This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define N 500005
using namespace std;
int vis[N], p[N];
int n, m, pre;
set<int> adj[N];
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
for(int i = 1; i <= m; i++){
int a, b;
cin >> a >> b;
adj[a].insert(b);
adj[b].insert(a);
}
for(int i = 1; i <= n; i++){
while(adj[i].size()){
stack<int> s;
s.push(i);
while(s.size()){
int now = s.top();
// cout << now << ' ';
if(vis[now] == 1){
// cout << 1 << '\n';
cout << now << ' ';
s.pop();
while(s.top() != now){
vis[s.top()] = 0;
cout << s.top() << ' ';
s.pop();
}
vis[now] = 0;
cout << '\n';
}
else{
if(adj[now].size() == 0){
vis[now] = 2;
s.pop();
// cout << 2 << '\n';
}
else{
// cout << 3 << '\n';
vis[now] = 1;
int k = *adj[now].begin();
adj[now].erase(k);
adj[k].erase(now);
s.push(k);
}
}
}
}
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |