# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
396096 | Nicholas_Patrick | Senior Postmen (BOI14_postmen) | C++17 | 619 ms | 42832 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 <cstdio>
#include <queue>
#include <unordered_set>
using namespace std;
int main(){
int n, m;
scanf("%d%d", &n, &m);
unordered_set<long long> deleted;
vector<vector<int>> adjLis(n);
for(int i=m; i--;){
int a, b;
scanf("%d%d", &a, &b), a--, b--;
adjLis[a].push_back(b);
adjLis[b].push_back(a);
}
vector<bool> visited(n, false);
for(int i=n; i--;){
int x=i;
vector<int> ans;
while(not adjLis[i].empty()){
ans.push_back(x);
visited[x]=true;
int y=-1;
for(;not adjLis[i].empty();){
y=adjLis[x].back();
adjLis[x].pop_back();
auto it=deleted.find((long long)x<<30|y);
if(it!=deleted.end()){
deleted.erase(it);
y=-1;
}else break;
}
if(y==-1)break;
deleted.insert((long long)y<<30|x);
if(visited[y]){
while(ans.back()!=y){
printf("%d ", ans.back()+1);
visited[ans.back()]=false;
ans.pop_back();
}
printf("%d\n", ans.back()+1);
visited[ans.back()]=false;
ans.pop_back();
x=y;
}else{
x=y;
}
}
}
}
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... |