# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
733344 | Trunkty | Senior Postmen (BOI14_postmen) | C++14 | 660 ms | 223468 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<int> roads[500005];
int poi[500005];
unordered_map<int,bool> mp[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]];
poi[x]++;
if(mp[x][p]){
continue;
}
mp[p][x] = 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);
roads[b].push_back(a);
}
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... |