# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
479876 | SamAnd | Senior Postmen (BOI14_postmen) | C++17 | 0 ms | 0 KiB |
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];
vector<int> a[N];
vector<int> b[N];
int vn;
int v[N];
void dfs(int x)
{
while (s[x] != -1)
{
int h = a[x][s[x]];
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();
a[x].push_back(y);
a[y].push_back(x);
++z;
b[x].push_back(z);
b[y].push_back(z);
}
for (int i = 1; i <= n; ++i)
s[i] = a[i].size() - 1;
dfs(1);
memset(c, false, sizeof c);
vecotr<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;
}