Submission #31532

#TimeUsernameProblemLanguageResultExecution timeMemory
31532ngkan146Senior Postmen (BOI14_postmen)C++11
55 / 100
560 ms53740 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[500005]; vector <edge> G[500005]; bool visited[500005]; int n,m; vector <int> euler; 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]++; break; } if(mjk) continue; euler.push_back(u); --qsize; } } void dfs(int u){ 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; visited[id] = 1; dfs(v); } euler.push_back(u); } int st[500005], stsize; bool used[500005]; 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(1); for(int i=0;i<euler.size();++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:20:17: warning: unused variable 'v' [-Wunused-variable]
             int v = G[u][ctrl[u]].v;
                 ^
postmen.cpp: In function 'void dfs(int)':
postmen.cpp:36:17: 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:58:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<euler.size();++i){
                 ~^~~~~~~~~~~~~
postmen.cpp:48: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:51: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...