제출 #106883

#제출 시각아이디문제언어결과실행 시간메모리
106883PajarajaNetwork (BOI15_net)C++17
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; int cnt,nes; vector<int> g[500007],d[500007]; vector<bool> v[500007]; int k[500007]; void dfs(int s,int f) { if(g[s].size()==1) { k[cnt++]=s; return; } for(int i=0;i<g[s].size();i++) if(g[s][i]!=f) dfs(g[s][i],s); } int main() { int n,v1,v2,l=0; nes=0; fill(k,k+200007,0); scanf("%d",&n); for(int i=0;i<n-1;i++) { scanf("%d%d",&v1,&v2); g[v1].push_back(v2); g[v2].push_back(v1); } for(int i=1;i<=n;i++) if(g[i].size()==1) l++; printf("%d\n",(l+1)/2); for(int i=1;i<=n;i++) if(g[i].size()>1) { dfs(i,0); for(int i=0;i<l/2;i++) printf("%d %d\n",k[i],k[i+l/2]); if(l%2==0) printf("%d %d",s,k[l-1]); return 0; } }

컴파일 시 표준 에러 (stderr) 메시지

net.cpp: In function 'void dfs(int, int)':
net.cpp:14:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<g[s].size();i++) if(g[s][i]!=f) dfs(g[s][i],s);
                 ~^~~~~~~~~~~~
net.cpp: In function 'int main()':
net.cpp:34:34: error: 's' was not declared in this scope
        if(l%2==0) printf("%d %d",s,k[l-1]);
                                  ^
net.cpp:21:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&n);
     ~~~~~^~~~~~~~~
net.cpp:24:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d",&v1,&v2);
         ~~~~~^~~~~~~~~~~~~~~~