# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
103585 | luciocf | Senior Postmen (BOI14_postmen) | C++14 | 1089 ms | 36372 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;
const int maxn = 5e5+10;
typedef pair<int, int> pii;
int qtd;
bool markEdge[maxn], mark[maxn];
vector<pii> grafo[maxn];
vector<int> ans[maxn];
stack<int> stk;
void dfs(int u)
{
if (mark[u])
{
++qtd;
while (true)
{
int v = stk.top();
stk.pop();
mark[v] = 0;
ans[qtd].push_back(v);
if (v == u) break;
}
}
for (auto v: grafo[u])
{
if (!markEdge[v.second])
{
mark[u] = 1;
stk.push(u);
markEdge[v.second] = 1;
dfs(v.first);
}
}
}
int main(void)
{
int n, m;
scanf("%d %d", &n, &m);
for (int i = 1; i <= m; i++)
{
int u, v;
scanf("%d %d", &u, &v);
grafo[u].push_back({v, i});
grafo[v].push_back({u, i});
}
dfs(1);
for (int i = 1; i <= qtd; i++)
{
printf("%d", ans[i][0]);
for (int j = 1; j < ans[i].size(); j++)
printf(" %d", ans[i][j]);
printf("\n");
}
}
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... |