Submission #42314

#TimeUsernameProblemLanguageResultExecution timeMemory
42314IvanCSenior Postmen (BOI14_postmen)C++14
55 / 100
667 ms76280 KiB
#include <bits/stdc++.h> using namespace std; typedef vector<int> vi; const int MAXN = 5*1e5 + 10; int N,M,e1[MAXN],e2[MAXN],e3[MAXN],marcado[MAXN],ptr[MAXN]; vi grafo[MAXN],pilha; vector<vi> resposta; int dfs(int v){ //printf("DFS %d\n",v); marcado[v] = 1; for(;ptr[v] < grafo[v].size();ptr[v]++){ int idx = grafo[v][ptr[v]]; if(e3[idx] == 1) continue; e3[idx] = 1; int u = (e1[idx] != v) ? (e1[idx]) : (e2[idx]); if(marcado[u]){ marcado[v] = 0; pilha.push_back(v); return u; } int ret = dfs(u); if(ret == v){ pilha.push_back(v); resposta.push_back(pilha); pilha.clear(); } else{ marcado[v] = 0; pilha.push_back(v); return ret; } } marcado[v] = 0; pilha.clear(); return -1; } int main(){ scanf("%d %d",&N,&M); for(int i = 1;i<=M;i++){ scanf("%d %d",&e1[i],&e2[i]); grafo[e1[i]].push_back(i); grafo[e2[i]].push_back(i); } for(int i = 1;i<=N;i++){ 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 dfs(int)':
postmen.cpp:11:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(;ptr[v] < grafo[v].size();ptr[v]++){
       ~~~~~~~^~~~~~~~~~~~~~~~~
postmen.cpp: In function 'int main()':
postmen.cpp:47:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0;i<resposta.size();i++){
                ~^~~~~~~~~~~~~~~~
postmen.cpp:38: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:40:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d",&e1[i],&e2[i]);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...