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 <iostream>
#include <vector>
#include <list>
#include <algorithm>
typedef long long ll;
using namespace std;
const int maxn = 5e5 + 5;
struct edge { int v, i; };
bool vise[maxn], visvr[maxn];
int nxt[maxn];
vector<edge> g[maxn];
vector<int> e;
void dfs(int u)
{
if (visvr[u]) // cyklus
{
while (visvr[u])
{
cout << u + 1 << " ";
visvr[u] = false;
u = nxt[u];
}
cout << "\n";
}
while (!g[u].empty())
{
edge e = g[u].back();
g[u].pop_back();
if (!vise[e.i])
{
vise[e.i] = true;
visvr[u] = true;
nxt[u] = e.v;
dfs(e.v);
}
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
for (int i = 0, a, b; i < m; i++)
{
cin >> a >> b;
a--, b--;
g[a].push_back({ b, i });
g[b].push_back({ a, i });
}
dfs(0);
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... |