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>
using namespace std;
const int mx = 5e5 + 5;
int n, m, pth[mx]; bool vis[mx], useEdg[mx]; vector<pair<int, int>> adj[mx];
void dfs(int cur){
if (vis[cur]){
int cyc = cur;
while (vis[cyc]){
cout<<cyc<<" ";
vis[cyc] = 0; cyc = pth[cyc];
}
cout<<"\n";
}
while (adj[cur].size()){
int nxt, ind;
tie(nxt, ind) = adj[cur].back(); adj[cur].pop_back();
if (!useEdg[ind]){
useEdg[ind] = vis[cur] = 1;
pth[cur] = nxt;
dfs(nxt);
}
}
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> n >> m;
for (int i = 1; i <= m; i++){
int a, b; cin >> a >> b;
adj[a].push_back({b, i}); adj[b].push_back({a, i});
}
dfs(1);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |