# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
755472 | irmuun | Senior Postmen (BOI14_postmen) | C++17 | 523 ms | 101660 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;
#define pb push_back
#define ll long long
#define ff first
#define ss second
#define all(s) s.begin(),s.end()
int main(){
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int n,m;
cin>>n>>m;
set<int>adj[n+1];
vector<int>used(n+1,0);
for(int i=1;i<=m;i++){
int u,v;
cin>>u>>v;
adj[u].insert(v);
adj[v].insert(u);
}
vector<int>ord;
function <void(int)> dfs=[&](int x){
ord.pb(x);
if(adj[x].size()==0){
return;
}
int y=*adj[x].begin();
adj[x].erase(y);
adj[y].erase(x);
dfs(y);
};
for(int i=1;i<=n;i++){
if(adj[i].size()>0){
dfs(i);
}
}
stack<int>v;
for(int i=0;i<ord.size();i++){
if(used[ord[i]]==0){
used[ord[i]]=1;
v.push(ord[i]);
}
else{
int x=ord[i];
cout<<x<<' ';
while(!v.empty()){
int y=v.top();
if(x!=y){
cout<<y<<' ';
v.pop();
used[y]=0;
}
else{
break;
}
}
cout<<"\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... |