Submission #197470

#TimeUsernameProblemLanguageResultExecution timeMemory
197470dndhkSenior Postmen (BOI14_postmen)C++14
55 / 100
550 ms49892 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; 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)

postmen.cpp: In function 'int main()':
postmen.cpp:39: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:41: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...