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>
#define fr(i, n, m) for(int i = (n); i < (m); i ++)
#define pb push_back
#define st first
#define nd second
#define pq priority_queue
#define all(x) begin(x), end(x)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
const ll inf = 1e18;
const ll mod = 1000000007;
const ld eps = 1e-13;
const ld pi = 3.14159265359;
mt19937 _rand(time(NULL));
clock_t timer = clock();
const int mxn = 6*1e5;
int n, m;
vector<int> g[mxn];
bool used[mxn];
int l[mxn], r[mxn];
vector<int> cycle;
int nxt(int u, int edge){
return l[edge]^r[edge]^u;
}
void euler(int u){
fr(i, 0, (int)g[u].size()){
if(used[g[u][i]]){
swap(g[u][i], g[u].back());
g[u].pop_back();
--i;
continue;
}
used[g[u][i]] = true;
euler(nxt(u, g[u][i]));
}
cycle.pb(u);
}
vector<int> sol[mxn];
int R[mxn];
int _next[mxn];
int lst[mxn];
void restore(){
memset(lst, -1, sizeof(lst));
for(int i = cycle.size()-1; i >= 0; i --){
_next[i] = lst[cycle[i]];
lst[cycle[i]] = i;
}
sol[0].pb(0);
R[0] = _next[0];
stack<int> S;
S.push(0);
int id = 1;
fr(i, 1, (int)cycle.size()-1){
int u = cycle[i];
if(R[S.top()] == i) S.pop();
if(S.empty() || (_next[i] != -1 && _next[i] <= R[S.top()])){
S.push(id);
sol[id].pb(u);
R[id] = _next[i];
id++;
}
else{
sol[S.top()].pb(u);
}
}
fr(i, 0, id+1){
for(auto u : sol[i]) cout<<u+1<<' ';
cout<<endl;
}
}
void solve(){
cin >> n >> m;
fr(i, 0, m){
cin >> l[i] >> r[i];
--l[i], --r[i];
g[l[i]].pb(i);
g[r[i]].pb(i);
}
euler(0);
restore();
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
solve();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |