Submission #197813

#TimeUsernameProblemLanguageResultExecution timeMemory
197813dndhkSenior Postmen (BOI14_postmen)C++14
55 / 100
542 ms34252 KiB
#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; int nxt = gp[x].back().first; gp[x].pop_back(); if(vst[nxt]){ while(v.back()!=nxt){ 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(nxt); } else solve(nxt); } 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{ int n = idx; while(1){ vst[n] = true; v.pb(n); while(!gp[n].empty() && chk[gp[n].back().second]) gp[n].pop_back(); chk[gp[n].back().second] = true; int nxt = gp[n].back().first; gp[n].pop_back(); if(vst[nxt]){ while(v.back()!=nxt){ vst[v.back()] = false; printf("%d ", v.back()); v.pop_back(); } vst[v.back()] = false; printf("%d\n", v.back()); v.pop_back(); if(v.empty()) break; else n = nxt; }else{ n = nxt; } } } } return 0; }

Compilation message (stderr)

postmen.cpp: In function 'int main()':
postmen.cpp:41:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &N, &M);
  ~~~~~^~~~~~~~~~~~~~~~
postmen.cpp:43:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   int a, b; scanf("%d%d", &a, &b);
             ~~~~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...