#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;
bool yes = false;
for(auto e: adj[u])
{
if(e == par)
continue;
if(e == dest)
{
yes = true;
}
if(seen[e])
continue;
if(works(e,dest,u))
{
edges.pb({u,e});
seen[u] = 0;
return true;
}
}
seen[u] = 0;
if(yes)
{
edges.pb({u,dest});
seen[u] = 0;
return true;
}
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 << ' ';
if(vec.empty())
return ;
cout << '\n';
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4940 KB |
Output is correct |
2 |
Correct |
3 ms |
4940 KB |
Output is correct |
3 |
Correct |
2 ms |
4940 KB |
Output is correct |
4 |
Correct |
5 ms |
5392 KB |
Output is correct |
5 |
Correct |
3 ms |
5068 KB |
Output is correct |
6 |
Execution timed out |
1098 ms |
5488 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4940 KB |
Output is correct |
2 |
Correct |
2 ms |
4940 KB |
Output is correct |
3 |
Correct |
3 ms |
4940 KB |
Output is correct |
4 |
Correct |
4 ms |
5324 KB |
Output is correct |
5 |
Correct |
3 ms |
5068 KB |
Output is correct |
6 |
Execution timed out |
1082 ms |
5452 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4940 KB |
Output is correct |
2 |
Correct |
2 ms |
4940 KB |
Output is correct |
3 |
Correct |
2 ms |
4940 KB |
Output is correct |
4 |
Correct |
4 ms |
5324 KB |
Output is correct |
5 |
Correct |
6 ms |
5068 KB |
Output is correct |
6 |
Execution timed out |
1086 ms |
5452 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |