# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
733347 | Trunkty | Senior Postmen (BOI14_postmen) | C++14 | 650 ms | 157476 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;
typedef long long ll;
#define int ll
int n,m;
vector<vector<int>> roads[500005];
int poi[500005];
bool mark[500005];
bool vis[500005];
vector<int> curr;
vector<vector<int>> ans;
void euler(int x){
if(vis[x]){
curr = {x};
return;
}
vis[x] = true;
while(roads[x].size()!=poi[x]){
int p = roads[x][poi[x]][0], q = roads[x][poi[x]][1];
poi[x]++;
if(mark[q]){
continue;
}
mark[q] = true;
euler(p);
if(curr.size()>0 and curr[0]!=x){
curr.push_back(x);
vis[x] = false;
return;
}
else if(curr[0]==x){
ans.push_back(curr);
curr.clear();
}
}
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> m;
for(int i=1;i<=m;i++){
int a,b;
cin >> a >> b;
roads[a].push_back({b,i});
roads[b].push_back({a,i});
}
for(int i=1;i<=n;i++){
if(roads[i].size()>0){
euler(i);
}
}
for(vector<int> i:ans){
for(int j:i){
cout << j << " ";
}
cout << "\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... |