Submission #31535

#TimeUsernameProblemLanguageResultExecution timeMemory
31535ngkan146Senior Postmen (BOI14_postmen)C++98
55 / 100
646 ms51808 KiB
#include <bits/stdc++.h> using namespace std; struct edge{ int v=0, id=0; edge(int v=0,int id=0):id(id),v(v){} }; int ctrl[1000005]; vector <edge> G[1000005]; bool visited[1000005]; int n,m; int euler[1000005], eulersize; int q[1000005], qsize; void dfs(){ q[qsize++] = 1; while(qsize){ int u = q[qsize-1]; bool mjk = 0; for(;ctrl[u]<G[u].size();++ctrl[u]){ int v = G[u][ctrl[u]].v; int id = G[u][ctrl[u]].id; if (visited[id]) continue; mjk = 1; visited[id] = 1; q[qsize++] = v; break; } if(mjk) continue; euler[eulersize++] = u; --qsize; } } int st[1000005], stsize; bool used[1000005]; int main(){ scanf("%d %d",&n,&m); for(int i=1;i<=m;++i){ int x,y; scanf("%d %d",&x,&y); G[x].push_back(edge(y,i)); G[y].push_back(edge(x,i)); } dfs(); for(int i=0;i<eulersize;++i){ if (used[euler[i]]){ while(st[stsize-1] != euler[i]){ printf("%d ",st[stsize-1]); used[st[stsize-1]] = 0; --stsize; }; printf("%d\n",euler[i]); } else{ st[stsize++] = euler[i]; used[euler[i]] = 1; } } }

Compilation message (stderr)

postmen.cpp: In constructor 'edge::edge(int, int)':
postmen.cpp:4:17: warning: 'edge::id' will be initialized after [-Wreorder]
     int v=0, id=0;
                 ^
postmen.cpp:4:11: warning:   'int edge::v' [-Wreorder]
     int v=0, id=0;
           ^
postmen.cpp:5:5: warning:   when initialized here [-Wreorder]
     edge(int v=0,int id=0):id(id),v(v){}
     ^~~~
postmen.cpp: In function 'void dfs()':
postmen.cpp:19:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(;ctrl[u]<G[u].size();++ctrl[u]){
              ~~~~~~~^~~~~~~~~~~~
postmen.cpp: In function 'int main()':
postmen.cpp:38:10: 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:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d",&x,&y);
         ~~~~~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...