Submission #42315

#TimeUsernameProblemLanguageResultExecution timeMemory
42315IvanCSenior Postmen (BOI14_postmen)C++14
55 / 100
656 ms108048 KiB
#include <bits/stdc++.h> using namespace std; typedef vector<int> vi; const int MAXN = 5*1e5 + 10; int N,M,posicao[MAXN],marcado[MAXN]; set<int> cjt[MAXN]; vi pilha,temporario; vector<vi> resposta; void dfs(int v){ marcado[v] = 1; posicao[v] = pilha.size(); pilha.push_back(v); while(!cjt[v].empty() && posicao[v] != -1){ int u = *(cjt[v].begin()); cjt[v].erase(u); cjt[u].erase(v); if(marcado[u]){ for(int i = posicao[v];i>posicao[u];i--){ int k = pilha[i]; posicao[k] = -1; marcado[k] = 0; temporario.push_back(k); pilha.pop_back(); } temporario.push_back(u); resposta.push_back(temporario); temporario.clear(); return; } else{ dfs(u); } } if(posicao[v] == -1) return; } int main(){ scanf("%d %d",&N,&M); for(int i = 1;i<=N;i++) posicao[i] = -1; for(int i = 1;i<=M;i++){ int u,v; scanf("%d %d",&u,&v); cjt[u].insert(v); cjt[v].insert(u); } for(int i = 1;i<=N;i++){ if(!cjt[i].empty()) dfs(i); } for(int i = 0;i<resposta.size();i++){ for(int j : resposta[i]) printf("%d ",j); printf("\n"); } return 0; }

Compilation message (stderr)

postmen.cpp: In function 'int main()':
postmen.cpp:48:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0;i<resposta.size();i++){
                ~^~~~~~~~~~~~~~~~
postmen.cpp:37: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:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d",&u,&v);
   ~~~~~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...