Submission #1369617


Source Code Expand

#include <bits/stdc++.h>

#define fi first
#define se second
#define sc scanf
#define pr printf
#define pb push_back
#define ll long long
#define fin(s) freopen( s, "r", stdin );
#define fout(s) freopen( s, "w", stdout );

const long long N = 100100;
const long long MX = sqrt(N);
const long long H = 17;
const long long MAGIC = 1000;
const long long mod = 1e9 + 7;

using namespace std;

int n;
int m;
int r[N];
bool used[N];
vector < int > v[N];

void solve()
{
        cin >> n >> m;
        for(int i = 1; i <= m; i++){
                int x, y;
                cin >> x >> y;
                v[x].pb(y);
                v[y].pb(x);
        }
        int s = 1, t = 1, bs = true, bt = true;
        used[1] = true;
        while(true){
                bool ch = false;
                if(bs){
                        bs = false;
                        for(int x: v[s]){
                                if(used[x] == false){
                                        ch = true;
                                        bs = true;
                                        r[x] = s;
                                        s = x;
                                        used[x] = true;
                                        break;
                                }
                        }
                }
                if(bt){
                        bt = false;
                        for(int x: v[t]){
                                if(used[x] == false){
                                        ch = true;
                                        bt = true;
                                        r[t] = x;
                                        t = x;
                                        used[x] = true;
                                        break;
                                }
                        }
                }
                if(!ch){
                        break;
                }
        }
        vector < int > ans;
        while(s){
                ans.pb(s);
                s = r[s];
        }
        cout << ans.size() << "\n";
        for(int x: ans){
                cout << x << " ";
        }
}

bool mtest = false; int main()
{
        //fin("input.txt");
        //fout("output.txt");
        //fin("landscape.in");
        //fout("landscape.out");
        ios_base::sync_with_stdio(0);
        int TE = 1;
        if(mtest)
                cin >> TE;
        while(TE--)
                solve();
        return 0;
}

Submission Info

Submission Time
Task B - Hamiltonish Path
User EliteWantsYou
Language C++14 (GCC 5.4.1)
Score 500
Code Size 2562 Byte
Status AC
Exec Time 47 ms
Memory 7288 KB

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 30 ms 4992 KB
subtask_1_02.txt AC 9 ms 3072 KB
subtask_1_03.txt AC 28 ms 5120 KB
subtask_1_04.txt AC 31 ms 4992 KB
subtask_1_05.txt AC 32 ms 4992 KB
subtask_1_06.txt AC 32 ms 4992 KB
subtask_1_07.txt AC 34 ms 5888 KB
subtask_1_08.txt AC 34 ms 5760 KB
subtask_1_09.txt AC 47 ms 7288 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