# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
129754 | SamAnd | Senior Postmen (BOI14_postmen) | C++17 | 653 ms | 94176 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;
set<int> a[N];
vector<int> v;
void dfs(int x)
{
while (1)
{
if (a[x].empty())
break;
int h = *a[x].begin();
a[x].erase(h);
a[h].erase(x);
dfs(h);
}
v.push_back(x);
}
bool c[N];
int main()
{
scanf("%d%d", &n, &m);
for (int i = 0; i < m; ++i)
{
int x, y;
scanf("%d%d", &x, &y);
a[x].insert(y);
a[y].insert(x);
}
dfs(1);
stack<int> s;
for (int i = 0; i < v.size(); ++i)
{
if (c[v[i]])
{
printf("%d ", v[i]);
while (s.top() != v[i])
{
printf("%d ", s.top());
c[s.top()] = false;
s.pop();
}
printf("\n");
}
else
{
s.push(v[i]);
c[v[i]] = true;
}
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |