# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
987693 | anonymous321 | Senior Postmen (BOI14_postmen) | C++17 | 138 ms | 30804 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<cstdio>
#include<vector>
#include<stack>
#include<set>
using namespace std;
const int MNODES = 200010;
set<int> g[MNODES];
bool visited[MNODES];
stack<pair<int, int> > s;
void delete_edge(int u, int v)
{
g[u].erase(v);
g[v].erase(u);
}
void dfs(int v)
{
while(!g[v].empty())
{
int w = *g[v].begin();
delete_edge(v, w);
dfs(w);
s.push(make_pair(v, w));
}
}
int main()
{
int n, m;
scanf("%d %d", &n, &m);
for(int i = 0; i < m; ++i)
{
int u, v;
scanf("%d %d", &u, &v);
g[u].insert(v);
g[v].insert(u);
}
dfs(1);
stack<int> c;
vector<vector<int> > cycles;
while(!s.empty())
{
pair<int, int> e = s.top();
s.pop();
if(c.empty())
{
c.push(e.first);
visited[e.first] = true;
}
if(visited[e.second])
{
cycles.push_back(vector<int>());
cycles.back().push_back(e.second);
while(c.top() != e.second)
{
cycles.back().push_back(c.top());
visited[c.top()] = false;
c.pop();
}
c.pop();
}
c.push(e.second);
visited[e.second] = true;
}
for(int i = 0; i < (int)cycles.size(); ++i)
{
for(int j = 0; j < (int)cycles[i].size(); ++j) printf("%d ", cycles[i][j]);
printf("\n");
}
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... |