Submission #3026961


Source Code Expand

#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<math.h>
#include<numeric>
#include<cassert>
#include<random>
#include<deque>
#include<chrono>
#include<unordered_map>
#include<list>
#include<fstream>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
const ll E=1e18+7;
#define F first
#define S second
#define MK make_pair
const ll MOD=1000000007;

vector<vector<ll>> e;
vector<bool> used;

vector<ll> dfs(ll w,vector<ll> path){
    used[w]=true;
    path.push_back(w+1);
    for(int i=0;i<e[w].size();i++){
        if(!used[e[w][i]]){return dfs(e[w][i],path);}
    }
    return path;
}


int main(){
    vector<vector<ll>> e;
    vector<bool> used;
    ll n,m;
    cin>>n>>m;
    e.resize(n);
    used.resize(n);
    for(int i=0;i<m;i++){
        ll a,b;
        cin>>a>>b;
        a--; b--;
        e[a].push_back(b);
        e[b].push_back(a);
    }
    deque<ll> A;
    ll w=0;
    while(1){
        bool cont=false;
        used[w]=true;
        A.push_back(w+1);
        for(int i=0;i<e[w].size();i++){
            if(!used[e[w][i]]){w=e[w][i]; cont=true; break;}
        }
        if(!cont){break;}
    }
    w=0;
    while(1){
        bool cont=false;
        used[w]=true;
        if(w!=0){
            A.push_front(w+1);
        }
        for(int i=0;i<e[w].size();i++){
            if(!used[e[w][i]]){w=e[w][i]; cont=true; break;}
        }
        if(!cont){break;}
    }
    cout<<A.size()<<endl;
    for(int i=0;i<A.size();i++){
        cout<<A[i];
        if(i!=A.size()-1){cout<<" ";}
        else{cout<<endl;}
    }
    
    
    return 0;
}

Submission Info

Submission Time
Task B - Hamiltonish Path
User tubuann
Language C++14 (GCC 5.4.1)
Score 500
Code Size 1946 Byte
Status AC
Exec Time 86 ms
Memory 7168 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 1 ms 256 KB
sample_02.txt AC 1 ms 256 KB
sample_03.txt AC 1 ms 256 KB
subtask_1_01.txt AC 67 ms 4864 KB
subtask_1_02.txt AC 17 ms 1152 KB
subtask_1_03.txt AC 60 ms 4608 KB
subtask_1_04.txt AC 71 ms 4608 KB
subtask_1_05.txt AC 71 ms 4608 KB
subtask_1_06.txt AC 71 ms 4608 KB
subtask_1_07.txt AC 73 ms 6400 KB
subtask_1_08.txt AC 75 ms 6272 KB
subtask_1_09.txt AC 86 ms 7168 KB
subtask_1_10.txt AC 21 ms 1664 KB
subtask_1_11.txt AC 26 ms 1792 KB
subtask_1_12.txt AC 1 ms 256 KB
subtask_1_13.txt AC 1 ms 256 KB