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 ll long long
#define fr(i, d, c) for(ll i = d; i <= c; i++)
#define fl(i, d, c) for(ll i = d; i >= c; i--)
const int N = 5e5 + 9;
using namespace std;
ll n, m;
map<ll, ll> dd;
set<ll> adj[N];
stack<ll> st;
void run(ll u, ll bd) {
dd[u] = true;
st.push(u);
ll v = *adj[u].rbegin();
adj[u].erase(v);
adj[v].erase(u);
if(dd[v] == true) {
while(true) {
ll t = st.top();
st.pop();
cout<<t<<" ";
dd[t] = false;
if(t == v) break;
}
cout<<'\n';
}
if(v != bd) run(v, bd);
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> m;
fr(i, 1, m) {
ll x, y;
cin>> x >> y;
adj[x].insert(y);
adj[y].insert(x);
}
fr(i, 1, n) {
while(adj[i].size()) {
dd.clear();
run(i, 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... |