#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<queue<int>> adj;
vector<unordered_set<int>> c;
vector<int> ep;
void euler(int index, int last)
{
c[last].insert(index);
while (!adj[index].empty())
{
int node = adj[index].front();
adj[index].pop();
if (!c[node].count(index))
euler(node, index);
}
ep.push_back(index);
}
int main()
{
int N, M; cin >> N >> M;
adj.resize(N);
c.resize(N);
for (int i = 0; i < M; i++)
{
int a, b;
cin >> a >> b;
a--; b--;
adj[a].push(b);
adj[b].push(a);
}
euler(0, 0);
for (auto v : ep)
cerr << v+1 << ' ';
cerr<<'\n';
vector<int> occourence(N, -1);
vector<int> linkedList(ep.size(), -1);
iota(linkedList.begin(), linkedList.end(), 1);
for (int i = 0; i < ep.size(); i++)
{
int value = ep[i];
if (occourence[value] != -1)
{
int j = linkedList[occourence[value]];
linkedList[occourence[value]] = i + 1;
for (; j < i; j = linkedList[j])
{
cout << ep[j] + 1 << ' ';
occourence[ep[j]] = -1;
}
cout << ep[i] + 1 << '\n';
continue;
}
occourence[value] = i;
}
return 0;
}
/*
5 6
1 2
1 3
1 4
1 5
2 3
4 5
*/
Compilation message
postmen.cpp: In function 'int main()':
postmen.cpp:50:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
50 | for (int i = 0; i < ep.size(); i++)
| ~~^~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
9 ms |
2396 KB |
Output is correct |
5 |
Correct |
3 ms |
604 KB |
Output is correct |
6 |
Correct |
12 ms |
1116 KB |
Output is correct |
7 |
Correct |
41 ms |
2640 KB |
Output is correct |
8 |
Correct |
8 ms |
2140 KB |
Output is correct |
9 |
Correct |
313 ms |
14224 KB |
Output is correct |
10 |
Correct |
9 ms |
2140 KB |
Output is correct |
11 |
Correct |
8 ms |
2392 KB |
Output is correct |
12 |
Correct |
280 ms |
15528 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
9 ms |
2392 KB |
Output is correct |
5 |
Correct |
3 ms |
604 KB |
Output is correct |
6 |
Correct |
12 ms |
1116 KB |
Output is correct |
7 |
Correct |
43 ms |
2644 KB |
Output is correct |
8 |
Correct |
8 ms |
2396 KB |
Output is correct |
9 |
Correct |
274 ms |
14172 KB |
Output is correct |
10 |
Correct |
9 ms |
2140 KB |
Output is correct |
11 |
Correct |
8 ms |
2396 KB |
Output is correct |
12 |
Correct |
286 ms |
15824 KB |
Output is correct |
13 |
Correct |
369 ms |
97412 KB |
Output is correct |
14 |
Correct |
358 ms |
72296 KB |
Output is correct |
15 |
Correct |
347 ms |
69556 KB |
Output is correct |
16 |
Correct |
345 ms |
97484 KB |
Output is correct |
17 |
Correct |
370 ms |
62320 KB |
Output is correct |
18 |
Correct |
349 ms |
74244 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
9 ms |
2396 KB |
Output is correct |
5 |
Correct |
3 ms |
468 KB |
Output is correct |
6 |
Correct |
14 ms |
1116 KB |
Output is correct |
7 |
Correct |
42 ms |
2640 KB |
Output is correct |
8 |
Correct |
7 ms |
2140 KB |
Output is correct |
9 |
Correct |
282 ms |
14420 KB |
Output is correct |
10 |
Correct |
9 ms |
2140 KB |
Output is correct |
11 |
Correct |
11 ms |
2392 KB |
Output is correct |
12 |
Correct |
282 ms |
15560 KB |
Output is correct |
13 |
Correct |
354 ms |
97640 KB |
Output is correct |
14 |
Correct |
339 ms |
72396 KB |
Output is correct |
15 |
Correct |
346 ms |
69604 KB |
Output is correct |
16 |
Correct |
344 ms |
97484 KB |
Output is correct |
17 |
Correct |
347 ms |
62520 KB |
Output is correct |
18 |
Correct |
366 ms |
74440 KB |
Output is correct |
19 |
Runtime error |
95 ms |
262144 KB |
Execution killed with signal 9 |
20 |
Halted |
0 ms |
0 KB |
- |