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;
const int MAXN = 5e5 + 5;
int n, m;
int ii[MAXN];
vector <pair <int, int> > Adj[MAXN];
vector <int> Ans[MAXN];
bool In[MAXN], Used[MAXN];
void Find(int node, int id)
{
while(ii[node] < (int)Adj[node].size() and Used[Adj[node][ii[node]].second])
{
ii[node]++;
}
if(ii[node] < (int)Adj[node].size())
{
Used[Adj[node][ii[node]].second] = true;
Find(Adj[node][ii[node]].first, id);
}
if(In[node])
{
cout << node << ' ';
while(Ans[id].back() != node)
{
cout << Ans[id].back() << ' ';
In[Ans[id].back()] = false;
Ans[id].pop_back();
}
cout << '\n';
}
else
{
In[node] = true;
Ans[id].push_back(node);
}
}
int main()
{
// freopen("test_input.txt", "r", stdin);
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
for(int i = 1; i <= m; i++)
{
int u, v;
cin >> u >> v;
Adj[u].emplace_back(v, i);
Adj[v].emplace_back(u, i);
}
for(int i = 1; i <= n; i++)
{
if((int)Adj[i].size())
{
Find(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... |