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;
using ll = long long;
const int mx=2e5+5;
vector<pair<int,int>> g[mx],edges;
bool used[mx];
int n,m;
vector<int> path;
void dfs(int u) {
while(!g[u].empty()) {
pair<int,int> cur = g[u].back();
g[u].pop_back();
if(used[cur.second]) continue;
used[cur.second] = true;
dfs(cur.first);
}
path.push_back(u);
}
int main(){
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin >> n >> m;
for(int i=1;i<=m;++i) {
int u,v; cin >> u >> v;
edges.push_back({u,v});
g[u].push_back({v,i});
g[v].push_back({u,i});
}
for(int i=0;i<m;++i) {
if(!used[i+1]) {
dfs(edges[i].first);
for(auto j:path) {
cout << j << " ";
}
path.clear();
cout << '\n';
}
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |