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;
#define all(x) begin(x), end(x)
#define sz(x) (int)x.size()
#define pb push_back
const int maxn = 500001;
vector<pair<int, int>> adj[maxn];
vector<bool> seen;
vector<int> path;
void dfs(int s){
while(!adj[s].empty()){
auto [u, id] = adj[s].back();
adj[s].pop_back();
if(seen[id]) continue;
seen[id] = true;
dfs(u);
}
path.pb(s);
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
int n, m; cin >> n >> m;
seen.resize(m+1);
for(int i=1; i<=m; i++){
int a, b; cin >> a >> b;
adj[a].pb({b, i}); adj[b].pb({a, i});
}
dfs(1);
reverse(all(path));
int v[n+1] = {};
vector<int> w;
for(auto s: path){
if(v[s]){
cout << s << ' ';
while(w.back() != s){
auto t = w.back();
w.pop_back();
v[t] = 0;
cout << t << ' ';
}
cout << "\n";
}
else{
v[s] = 1;
w.pb(s);
}
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |