# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
419629 | VladM | Senior Postmen (BOI14_postmen) | C++14 | 554 ms | 124912 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>
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
using namespace std;
#define DIM 500007
int u, v, n, m, par[DIM], vis[DIM];
set<int> vec[DIM];
void dfs(int v, int p)
{
vis[v]=1;
par[v]=p;
for(auto to : vec[v])
{
if(to==p) continue;
if(vis[to]==1)
{
vec[v].erase(to);
vec[to].erase(v);
while(v!=to)
{
p=par[v];
printf("%d ", v);
vec[v].erase(p);
vec[p].erase(v);
vis[v]=0;
par[v]=0;
v=p;
}
printf("%d\n", v);
if(!vec[v].empty()) dfs(v, par[v]);
}
else dfs(to, v);
break;
}
return;
}
int main()
{
scanf("%d%d", &n, &m);
for(int i=1; i<=m; i++)
{
scanf("%d%d", &u, &v);
if(vec[v].find(u)!=vec[v].end())
{
printf("%d %d\n", u, v);
vec[u].erase(v);
vec[v].erase(u);
}
else
{
vec[u].insert(v);
vec[v].insert(u);
}
}
for(int i=1; i<=n; i++)
{
if(vec[i].size()!=0)
{
dfs(i, -1);
}
}
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... |