Submission #1221797
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;
#define ALL(a) begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
if(x > y) x = y;
}
const double EPS = 1e-10;
const double PI = acos(-1.0);
const LL MOD = 1e9+7;
void dfs(int u, vector<bool>& used, VI& path, VVI& G){
used[u] = true;
for(int to: G[u]){
if(used[to]) continue;
path.PB(to);
dfs(to, used, path, G);
return;
}
}
int main(){
cin.tie(0);
ios_base::sync_with_stdio(false);
int N, M; cin >> N >> M;
VVI G(N+1);
REP(i,M){
int u, v; cin >> u >> v;
G[u].PB(v);
G[v].PB(u);
}
vector<bool> used(N+1, false);
VI p1, p2;
used[1] = true;
dfs(1, used, p1, G);
dfs(1, used, p2, G);
reverse(ALL(p2));
p2.PB(1);
cout << (SZ(p1) + SZ(p2)) << endl;
bool sp = false;
for(auto i: p2){
cout << (sp?" ":"") << i;
sp = true;
}
for(auto i: p1){
cout << (sp?" ":"") << i;
sp = true;
}
cout << endl;
return 0;
}
Submission Info
Submission Time |
|
Task |
B - Hamiltonish Path |
User |
okaduki |
Language |
C++14 (GCC 5.4.1) |
Score |
500 |
Code Size |
1875 Byte |
Status |
AC |
Exec Time |
49 ms |
Memory |
12536 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 |
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 |
29 ms |
3968 KB |
subtask_1_02.txt |
AC |
8 ms |
1024 KB |
subtask_1_03.txt |
AC |
26 ms |
4096 KB |
subtask_1_04.txt |
AC |
30 ms |
3584 KB |
subtask_1_05.txt |
AC |
30 ms |
3584 KB |
subtask_1_06.txt |
AC |
31 ms |
3712 KB |
subtask_1_07.txt |
AC |
33 ms |
5888 KB |
subtask_1_08.txt |
AC |
34 ms |
5760 KB |
subtask_1_09.txt |
AC |
49 ms |
12536 KB |
subtask_1_10.txt |
AC |
9 ms |
1024 KB |
subtask_1_11.txt |
AC |
10 ms |
1024 KB |
subtask_1_12.txt |
AC |
1 ms |
256 KB |
subtask_1_13.txt |
AC |
1 ms |
256 KB |