# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
197470 | dndhk | Senior Postmen (BOI14_postmen) | C++14 | 550 ms | 49892 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 pb push_back
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAX_N = 500000;
int N, M;
vector<pii> gp[MAX_N+1];
bool chk[MAX_N+1];
bool vst[MAX_N+1];
vector<int> v;
void solve(int x){
vst[x] = true;
v.pb(x);
while(!gp[x].empty() && chk[gp[x].back().second]) gp[x].pop_back();
chk[gp[x].back().second] = true;
if(vst[gp[x].back().first]){
while(v.back()!=gp[x].back().first){
printf("%d ", v.back());
vst[v.back()] = false;
v.pop_back();
}
vst[v.back()] = false;
printf("%d\n", v.back()); v.pop_back();
if(v.empty()) return;
else solve(gp[x].back().first);
}
else solve(gp[x].back().first);
}
int main(){
scanf("%d%d", &N, &M);
for(int i=1; i<=M; i++){
int a, b; scanf("%d%d", &a, &b);
gp[a].pb({b, i});
gp[b].pb({a, i});
}
int idx = 1;
while(idx<=N){
while(!gp[idx].empty() && chk[gp[idx].back().second]) gp[idx].pop_back();
if(gp[idx].empty()) idx++;
else{
solve(idx);
}
}
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... |