#include <bits/stdc++.h>
using namespace std;
const int mxN=5e5;
int n, m, eu[mxN], ev[mxN];
vector<int> adj[mxN], a1, a2;
bool a[mxN], b[mxN];
void dfs(int u) {
while(adj[u].size()) {
int e=adj[u].back();
adj[u].pop_back();
if(a[e])
continue;
a[e]=1;
a1.push_back(u);
dfs(eu[e]^ev[e]^u);
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m;
for(int i=0; i<m; ++i) {
cin >> eu[i] >> ev[i], --eu[i], --ev[i];
adj[eu[i]].push_back(i);
adj[ev[i]].push_back(i);
}
dfs(0);
a1.push_back(0);
// cout << "hi1" << endl;
for(int i=0; i<a1.size(); ++i) {
// cout << i << " " << a1[i] << endl;
if(b[a1[i]]) {
// cout << i << endl;
while(b[a1[i]]) {
// cout << a2.size() << " " << a2.back() << endl;
cout << a2.back()+1 << " ";
b[a2.back()]=0;
a2.pop_back();
}
cout << "\n";
}
a2.push_back(a1[i]);
b[a1[i]]=1;
}
}
Compilation message
postmen.cpp: In function 'int main()':
postmen.cpp:34:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0; i<a1.size(); ++i) {
~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
12136 KB |
Output is correct |
2 |
Correct |
12 ms |
12160 KB |
Output is correct |
3 |
Correct |
14 ms |
12160 KB |
Output is correct |
4 |
Correct |
12 ms |
12288 KB |
Output is correct |
5 |
Incorrect |
13 ms |
12160 KB |
Edge does not exist or used 8, 23 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
12160 KB |
Output is correct |
2 |
Correct |
11 ms |
12136 KB |
Output is correct |
3 |
Correct |
14 ms |
12032 KB |
Output is correct |
4 |
Correct |
24 ms |
12288 KB |
Output is correct |
5 |
Incorrect |
12 ms |
12160 KB |
Edge does not exist or used 8, 23 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
12160 KB |
Output is correct |
2 |
Correct |
12 ms |
12032 KB |
Output is correct |
3 |
Correct |
12 ms |
12160 KB |
Output is correct |
4 |
Correct |
13 ms |
12416 KB |
Output is correct |
5 |
Incorrect |
12 ms |
12160 KB |
Edge does not exist or used 8, 23 |
6 |
Halted |
0 ms |
0 KB |
- |