Submission #1691498
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
#define fst first
#define snd second
#define pb push_back
#define REP(i, a, b) for(int i = (a), i##end = (b); i < i##end; ++i)
#define DREP(i, a, b) for(int i=(a-1), i##end = (b); i >=i##end; --i)
template <typename T> bool chkmax(T& a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T> bool chkmin(T& a, T b) { return a > b ? a = b, 1 : 0; }
const int N = 100000;
const int oo = 0x3f3f3f3f;
template<typename T> T read() {
T n(0), f(1);
char ch = getchar();
for(;!isdigit(ch); ch = getchar()) if(ch == '-') f = -1;
for(; isdigit(ch); ch = getchar()) n = n * 10 + ch - 48;
return n * f;
}
int n, m;
bool vis[N + 5];
vector<int> G[N + 5], Ans;
void dfs(int u) {
if(!vis[u]) Ans.pb(u);
vis[u] = true;
for(const auto&v : G[u]) if(!vis[v]) {
dfs(v);
break;
}
}
int main() {
#ifdef Wearry
freopen("data.txt", "r", stdin);
freopen("ans.txt", "w", stdout);
#endif
scanf("%d%d", &n, &m);
for(int i = 1; i <= m; ++i) {
static int a, b;
scanf("%d%d", &a, &b);
G[a].pb(b), G[b].pb(a);
}
dfs(1);
reverse(Ans.begin(), Ans.end());
dfs(1);
printf("%d\n", int(Ans.size()));
for(const auto&x : Ans) printf("%d ", x);
return 0;
}
Submission Info
Submission Time |
|
Task |
B - Hamiltonish Path |
User |
Wearry |
Language |
C++14 (GCC 5.4.1) |
Score |
500 |
Code Size |
1419 Byte |
Status |
AC |
Exec Time |
50 ms |
Memory |
9720 KB |
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:46: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:49:30: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &a, &b);
^
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 |
3 ms |
2560 KB |
sample_02.txt |
AC |
3 ms |
2560 KB |
sample_03.txt |
AC |
3 ms |
2560 KB |
subtask_1_01.txt |
AC |
31 ms |
4864 KB |
subtask_1_02.txt |
AC |
9 ms |
3072 KB |
subtask_1_03.txt |
AC |
29 ms |
4864 KB |
subtask_1_04.txt |
AC |
33 ms |
4736 KB |
subtask_1_05.txt |
AC |
33 ms |
4736 KB |
subtask_1_06.txt |
AC |
34 ms |
4864 KB |
subtask_1_07.txt |
AC |
35 ms |
5888 KB |
subtask_1_08.txt |
AC |
35 ms |
5760 KB |
subtask_1_09.txt |
AC |
50 ms |
9720 KB |
subtask_1_10.txt |
AC |
10 ms |
3328 KB |
subtask_1_11.txt |
AC |
12 ms |
3328 KB |
subtask_1_12.txt |
AC |
3 ms |
2560 KB |
subtask_1_13.txt |
AC |
3 ms |
2560 KB |