Submission #1470108
Source Code Expand
// This amazing code is by Eric Sunli Chen. #include <algorithm> #include <bitset> #include <cmath> #include <cstring> #include <cstdio> #include <cstdlib> #include <ctime> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <string> #include <utility> #include <vector> using namespace std; template<typename T> void get_int(T &x) { char t=getchar(); bool neg=false; x=0; for(; (t>'9'||t<'0')&&t!='-'; t=getchar()); if(t=='-')neg=true,t=getchar(); for(; t<='9'&&t>='0'; t=getchar())x=x*10+t-'0'; if(neg)x=-x; } template<typename T> void print_int(T x) { if(x<0)putchar('-'),x=-x; short a[20]= {},sz=0; while(x>0)a[sz++]=x%10,x/=10; if(sz==0)putchar('0'); for(int i=sz-1; i>=0; i--)putchar('0'+a[i]); } #define ff first #define ss second #define pb push_back #define mp make_pair #define get1(a) get_int(a) #define get2(a,b) get1(a),get1(b) #define get3(a,b,c) get1(a),get2(b,c) #define printendl(a) print_int(a),puts("") typedef long long LL; typedef unsigned long long uLL; typedef pair<int,int> pii; const int inf=0x3f3f3f3f; const LL Linf=1ll<<61; const double pi=acos(-1.0); vector<int> g[100111]; deque<int> ans; int n,m; bool use[100111]; int main() { get2(n,m); for(int i=1,u,v;i<=m;i++) { get2(u,v); g[u].pb(v); g[v].pb(u); } ans.pb(1);use[1]=1; while(true) { int x=ans.back(); bool ok=0; for(int i=0;i<(int)g[x].size();i++) if(!use[g[x][i]]) { ans.pb(g[x][i]); use[g[x][i]]=1; ok=1; break; } if(!ok)break; } while(true) { int x=ans.front(); bool ok=0; for(int i=0;i<(int)g[x].size();i++) if(!use[g[x][i]]) { ans.push_front(g[x][i]); use[g[x][i]]=1; ok=1; break; } if(!ok)break; } printf("%d\n",(int)ans.size()); for(int i=0;i<(int)ans.size();i++)printf("%d ",ans[i]); return 0; }
Submission Info
Submission Time | |
---|---|
Task | B - Hamiltonish Path |
User | OhWeOnFire |
Language | C++14 (GCC 5.4.1) |
Score | 500 |
Code Size | 1926 Byte |
Status | AC |
Exec Time | 40 ms |
Memory | 6784 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 500 / 500 | ||||
Status |
|
|
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 | 24 ms | 4864 KB |
subtask_1_02.txt | AC | 7 ms | 3072 KB |
subtask_1_03.txt | AC | 22 ms | 4864 KB |
subtask_1_04.txt | AC | 25 ms | 4736 KB |
subtask_1_05.txt | AC | 25 ms | 4736 KB |
subtask_1_06.txt | AC | 25 ms | 4736 KB |
subtask_1_07.txt | AC | 27 ms | 5888 KB |
subtask_1_08.txt | AC | 27 ms | 5760 KB |
subtask_1_09.txt | AC | 40 ms | 6784 KB |
subtask_1_10.txt | AC | 6 ms | 3328 KB |
subtask_1_11.txt | AC | 7 ms | 3328 KB |
subtask_1_12.txt | AC | 2 ms | 2560 KB |
subtask_1_13.txt | AC | 2 ms | 2560 KB |