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;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
typedef vector<pld> vpd;
#define pb push_back
#define popb pop_back
#define all(v) (v).begin(),(v).end()
#define ff first
#define ss second
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
int nx[4] = {1,-1,0,0}, ny[4] = {0,0,1,-1};
const int MAX_N = 1e5 + 4;
int n, m;
set<int> adj[MAX_N];
vpi edges;
vector<vi> ans;
bool seen[MAX_N];
int paths = 0;
bool works(int u, int dest, int par)
{
seen[u] = 1;
for(auto e: adj[u])
{
if(e == par)
continue;
if(e == dest)
{
edges.pb({u,e});
seen[u] = 0;
return true;
}
if(seen[e])
continue;
if(works(e,dest,u))
{
edges.pb({u,e});
seen[u] = 0;
return true;
}
}
seen[u] = 0;
return false;
}
void solve()
{
cin >> n >> m;
for(int i= 1; i <=m; i ++)
{
int a, b;
cin >> a >> b;
adj[a].insert(b);
adj[b].insert(a);
}
ans.resize(n);
for(int i= 1;i <= n; i ++)
{
if(works(i,i,0))
{
reverse(all(edges));
for(auto e: edges)
{
//cout << i << " cbon "<< e.ff << endl;
ans[paths].pb(e.ff);
adj[e.ff].erase(e.ss);
adj[e.ss].erase(e.ff);
}
edges.clear();
paths ++;
}
}
for(auto vec: ans)
{
for(auto e: vec)
cout << e << ' ';
cout << '\n';
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
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... |