Submission #1367617


Source Code Expand

#include <bits/stdc++.h>

using namespace std;

//#define FILE_IO

int N, M;
int f[100005];
vector <int> edg[100005];
vector <int> path;

void go(int nod)
{
    if(f[nod])  return;
    f[nod] = 1;
    path.push_back(nod);
    for(auto x: edg[nod])
        if(!f[x])
        {
            go(x);
            return;
        }
}

int main()
{
    #ifdef FILE_IO
    freopen("1.in", "r", stdin);
    freopen("1.out", "w", stdout);
    #endif

    scanf("%d%d", &N, &M);
    for(int i = 1; i <= M; i++)
    {
        int x, y;
        scanf("%d%d", &x, &y);
        edg[x].push_back(y);
        edg[y].push_back(x);
    }

    go(1);
    reverse(path.begin(), path.end()); path.pop_back(); f[1] = 0;
    go(1);

    printf("%d\n", path.size());
    for(auto x: path)
        printf("%d ", x);

    return 0;
}

Submission Info

Submission Time
Task B - Hamiltonish Path
User bogdan10bos
Language C++14 (GCC 5.4.1)
Score 500
Code Size 856 Byte
Status AC
Exec Time 50 ms
Memory 9976 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:45:31: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘std::vector<int>::size_type {aka long unsigned int}’ [-Wformat=]
     printf("%d\n", path.size());
                               ^
./Main.cpp:32:26: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &N, &M);
                          ^
./Main.cpp:36:30: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d", &x, &y);
                              ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 3
AC × 19
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt
All sample_01.txt, sample_02.txt, sample_03.txt, sample_01.txt, sample_02.txt, sample_03.txt, subtask_1_01.txt, subtask_1_02.txt, subtask_1_03.txt, subtask_1_04.txt, subtask_1_05.txt, subtask_1_06.txt, subtask_1_07.txt, subtask_1_08.txt, subtask_1_09.txt, subtask_1_10.txt, subtask_1_11.txt, subtask_1_12.txt, subtask_1_13.txt
Case Name Status Exec Time Memory
sample_01.txt AC 2 ms 2560 KB
sample_02.txt AC 2 ms 2560 KB
sample_03.txt AC 2 ms 2560 KB
subtask_1_01.txt AC 31 ms 4864 KB
subtask_1_02.txt AC 9 ms 3200 KB
subtask_1_03.txt AC 28 ms 4992 KB
subtask_1_04.txt AC 32 ms 4864 KB
subtask_1_05.txt AC 33 ms 4864 KB
subtask_1_06.txt AC 33 ms 4992 KB
subtask_1_07.txt AC 34 ms 5888 KB
subtask_1_08.txt AC 35 ms 5760 KB
subtask_1_09.txt AC 50 ms 9976 KB
subtask_1_10.txt AC 10 ms 3328 KB
subtask_1_11.txt AC 12 ms 3328 KB
subtask_1_12.txt AC 2 ms 2560 KB
subtask_1_13.txt AC 2 ms 2560 KB