# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1119671 | sasde | Senior Postmen (BOI14_postmen) | C++17 | 496 ms | 69496 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 str string
#define task "strdel"
#define ii pair<int,int>
#define iii pair<int,ii>
#define iv pair<ii,ii>
#define se second
#define fi first
#define ffi fi.fi
#define sfi se.fi
#define sse se.se
#define fse fi.se
#define lt(i, c, d) for(int i = c; i <= d; ++i)
#define fl(i, c, d) for(int i = d; i >= c; --i)
#define pb push_back
#define emb emplace_back
#define em emplace
using namespace std;
const int N=1e6+5,lg=20,mod=998244353;
mt19937 rd(chrono::steady_clock::now().time_since_epoch().count());
int Rand(int u,int v){
return u+rd()%(v-u+1);
}
int n,m;
vector<ii>a[N];
bool k[N],k1[N];
list<int> eul(int u){
list<int> ans={u};
while(!a[u].empty()){
k1[u]=true;
int v=a[u].back().fi;
int i=a[u].back().se;
a[u].pop_back();
if(k[i])continue;
k[i]=true;
u=v;
ans.emb(u);
}
for(auto it=++ans.begin();it!=ans.end();++it){
auto t=eul(*it);
t.pop_back();
// cout <<*it<<" "<<t.size()<<'\n';
ans.splice(it,t);
// ans.insert(it,t.begin(), t.end());
}
return ans;
}
bool h[N];
void solve(){
cin >> n >> m;
for(int i=1;i<=m;++i){
int u,v;
cin >> u >> v;
a[u].emb(v,i);
a[v].emb(u,i);
}
// for(int i:res)cout<<i<<" ";cout<<'\n';
for(int i=1;i<=n;++i)
if(!k1[i]){
list<int>res=eul(i);
stack<int>s;
for(int i:res){
if(h[i]){
while(!s.empty()&&h[i]){
h[s.top()]=false;
cout <<s.top()<<" ";
s.pop();
}
cout<<'\n';
}
h[i]=true;
s.push(i);
}
}
// cout <<1;
}
main()
{
srand(time(0));
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
if(fopen(task".inp","r")){
freopen(task".inp","r",stdin);
freopen(task".out","w",stdout);
}
int t=1;
// cin >> t;
while(t--){
solve();
// 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... |