# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
941017 | KaleemRazaSyed | Senior Postmen (BOI14_postmen) | C++17 | 6 ms | 12888 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<iostream>
#include<vector>
using namespace std;
const int N = 5e5+5;
struct edge
{
int u, v;
bool vis;
int other(int x)
{
return u + v - x;
}
};
vector<int> G[N];
vector<edge> e;
vector<int> p;
void dfs(int v)
{
p.push_back(v);
while(G[v].size())
{
int i = G[v].back();
G[v].pop_back();
if(e[i].vis)
continue;
e[i].vis = true;
dfs(e[i].other(v));
}
}
bool seen[N];
int main()
{
int n, m;
cin >> n >> m;
for(int i = 0; i < m; i ++)
{
int u, v;
cin >> u >> v;
G[u].push_back(i);
G[v].push_back(i);
e.push_back(edge{u, v, false});
}
dfs(1);
vector<int> ans;
for(int i = 0; i < p.size(); i++)
{
if(!seen[p[i]])
ans.push_back(p[i]);
else
{
cout << p[i];
while(ans.back() != p[i])
{
cout <<' ' << ans.back();
seen[ans.back()] = false;
ans.pop_back();
}
cout << '\n';
}
seen[p[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... |