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 N = 5e5 + 5;
int n, m, x[N], y[N];
vector < int > g[N];
bool used[N];
vector < int > q;
void dfs(int v){
for(auto num : g[v]){
if(used[num]){
continue;
}
used[num] = true;
int to = (x[num] ^ v ^ y[num]);
dfs(to);
}
q.push_back(v);
}
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin >> n >> m;
for(int i = 1; i <= m; i++){
cin >> x[i] >> y[i];
g[x[i]].push_back(i);
g[y[i]].push_back(i);
}
dfs(1);
memset(used, 0, sizeof(used));
vector < int > s;
for(auto it : q){
if(!used[it]){
used[it] = true;
s.push_back(it);
}
else{
while(s.back() != it){
cout << s.back() << " ";
used[s.back()] = false;
s.pop_back();
}
cout << it << "\n";
}
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |