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;
#define m_p make_pair
const int N = 500005;
int n, m;
int z;
bool c[N];
int s[N];
pair<int, int> a[N];
vector<int> b[N];
int vn;
int v[N];
void dfs(int x)
{
while (s[x] != -1)
{
int h = a[b[x][s[x]]].first;
if (h == x)
h = a[b[x][s[x]]].second;
if (c[b[x][s[x]]])
{
--s[x];
continue;
}
c[b[x][s[x]]] = true;
--s[x];
dfs(h);
}
v[vn++] = x;
}
int ka()
{
int x = 0;
while (1)
{
char t = getchar();
if (t == ' ' || t == '\n')
return x;
x *= 10;
x += (t - '0');
}
}
char t[10];
void tp(int x)
{
int tn = 0;
while (x)
{
t[tn++] = (x % 10) + '0';
x /= 10;
}
for (int i = tn - 1; i >= 0; --i)
putchar(t[i]);
putchar(' ');
}
int main()
{
n = ka();
m = ka();
for (int i = 0; i < m; ++i)
{
int x, y;
x = ka();
y = ka();
++z;
a[z] = m_p(x, y);
b[x].push_back(z);
b[y].push_back(z);
}
for (int i = 1; i <= n; ++i)
s[i] = b[i].size() - 1;
dfs(1);
memset(c, false, sizeof c);
vector<int> s;
for (int i = 0; i < vn; ++i)
{
if (c[v[i]])
{
tp(v[i]);
while (s.back() != v[i])
{
tp(s.back());
c[s.back()] = false;
s.pop_back();
}
putchar('\n');
}
else
{
s.push_back(v[i]);
c[v[i]] = true;
}
}
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... |