This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// In The Name Of Allah
#include <bits/stdc++.h>
#define ss second
#define ff first
#define use_fast ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define se(n) cout << setprecision(n) << fixed
#define pb push_back
//#define ll long long
#define ld long double
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC optimize("no-stack-protector,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
const int N = 5e5 + 100, OO = 1e9 + 7, K = 1e7 + 4, T = 22, M = 1e9 + 7, P = 6151, SQ = 1300, lg = 22;
typedef pair <int, int> pii;
bool mark[N];
int num[N], ET[N], l[N], r[N], nw[N], ht[N], nxt = 0, lst[N], pre[N][3];
inline void dfs(int x) {
while(nw[x] != -1) {
int p = nw[x];
nw[x] = pre[p][(x == r[p])];
if(mark[p])
continue;
mark[p] = true;
dfs(l[p] ^ r[p] ^ x);
ET[nxt++] = x;
}
}
int32_t main() {
int n, m;
cin >> n >> m;
for(int i = 1; i <= n; i++)
lst[i] = -1;
for(int j = 0; j < m; j++)
pre[j][0] = pre[j][1] = -1;
for(int i = 0; i < m; i++) {
cin >> l[i] >> r[i];
if(lst[l[i]] != -1)
pre[lst[l[i]]][(r[lst[l[i]]] == l[i])] = i;
if(lst[r[i]] != -1)
pre[lst[r[i]]][(r[lst[r[i]]] == r[i])] = i;
if(lst[l[i]] == -1)
nw[l[i]] = i;
if(lst[r[i]] == -1)
nw[r[i]] = i;
lst[l[i]] = lst[r[i]] = i;
}
dfs(1);
int sz = -1;
for(int i = 0; i < nxt; i++) {
int u = ET[i];
if(num[u]) {
cout << u;
while(ht[sz] != u)
cout << " " << ht[sz], num[ht[sz]]--, sz--;
cout << endl;
}
else
ht[++sz] = u, num[u]++;
}
for(int i = 0; i <= sz; i++)
cout << ht[i] << " ";
cout << endl;
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... |