# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
777588 | MasterTaster | Senior Postmen (BOI14_postmen) | C++14 | 682 ms | 77320 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>
#define ll long long
#define pii pair<int, int>
#define xx first
#define yy second
#define pb push_back
#define MAXN 500003
using namespace std;
int n, m; //deg[MAXN]
vector<int> put, tren;
set<int> g[MAXN];
bool bio[MAXN];
int main(){
cin>>n>>m;
for (int i=0; i<m; i++)
{
int u, v; cin>>u>>v;
g[u].insert(v);
g[v].insert(u);
//deg[u]++;
//deg[v]++;
}
//cout<<"ee"<<endl;
stack<int> st;
st.push(1);
while (!st.empty())
{
int u=st.top();
if (g[u].empty())
{
put.pb(u);
st.pop();
continue;
}
int v=(*g[u].begin());
g[u].erase(v);
g[v].erase(u);
//deg[u]--;
//deg[v]--;
st.push(v);
}
//for (auto x:put) cout<<x<<" ";
//cout<<endl;
for (int i=0; i<put.size(); i++)
{
int u=put[i];
st.push(u);
if (bio[u])
{
tren.clear();
int nes=0;
while (!nes || st.top()!=u)
{
nes++;
bio[st.top()]=false;
tren.pb(st.top());
st.pop();
}
for (auto x:tren) cout<<x<<" ";
cout<<endl;
}
bio[u]=true;
}
cout<<endl;
}
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... |