#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);
reverse(ep.begin(), ep.end());
int g = 0;
vector<int> occourence(ep.size(), -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 << '\n';
}
occourence[value] = i;
}
int i = 0;
return 0;
}
Compilation message
postmen.cpp: In function 'int main()':
postmen.cpp:48:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
48 | for (int i = 0; i < ep.size(); i++)
| ~~^~~~~~~~~~~
postmen.cpp:43:6: warning: unused variable 'g' [-Wunused-variable]
43 | int g = 0;
| ^
postmen.cpp:69:6: warning: unused variable 'i' [-Wunused-variable]
69 | int i = 0;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
2 ms |
2396 KB |
Output is correct |
5 |
Incorrect |
1 ms |
604 KB |
Edge does not exist or used 20, 37 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
3 ms |
2396 KB |
Output is correct |
5 |
Incorrect |
1 ms |
600 KB |
Edge does not exist or used 20, 37 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
3 ms |
2396 KB |
Output is correct |
5 |
Incorrect |
1 ms |
604 KB |
Edge does not exist or used 20, 37 |
6 |
Halted |
0 ms |
0 KB |
- |