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 = 100001;
vector<pair<int, int>> adj[maxn];
vector<bool> seen;
vector<pair<int, int>> path;
void dfs(int s, int i){
while(!adj[s].empty()){
auto [u, id] = adj[s].back();
adj[s].pop_back();
if(seen[id]) continue;
seen[id] = true;
dfs(u, id);
}
path.pb({s, i});
}
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, 0);
reverse(all(path));
int v[n+1] = {};
vector<pair<int, int>> w;
for(auto [s, i]: path){
if(v[s]){
cout << i << ' ';
while(w.back().first != s){
auto [t, j] = w.back();
w.pop_back();
v[t] = 0;
cout << j << ' ';
}
cout << "\n";
}
else{
v[s] = 1;
w.pb({s, i});
}
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |