제출 #93779

#제출 시각아이디문제언어결과실행 시간메모리
93779kjain_1810Network (BOI15_net)C++11
63 / 100
7 ms5240 KiB
#include <bits/stdc++.h> #define pb push_back #define f first #define s second #define ind(a) scanf("%d", &a) #define inlld(a) scanf("%lld", &a) #define ind2(a, b) scanf("%d%d", &a, &b) #define inlld2(a, b) scanf("%lld%lld", &a, &b) #define ind3(a, b, c) scanf("%d%d%d", &a, &b, &c) #define inlld3(a, b, c) scanf("%lld%lld%lld", &a, &b, &c) using namespace std; const int N=1e5+5; const int MOD=1e9+7; typedef long long ll; typedef long double ld; ll n; vector<ll>adj[N], leaf, nonleaf; void dfs(ll u, ll p) { if(adj[u].size()==1) leaf.pb(u); else nonleaf.pb(u); for(auto v:adj[u]) if(v!=p) dfs(v, u); } int main() { inlld(n); for(ll a=1; a<n; a++) { ll u, v; inlld2(u, v); adj[u].pb(v); adj[v].pb(u); } for(ll a=1; a<=n; a++) if(adj[a].size()>1) { dfs(a, 0); break; } ll ans=((int)leaf.size()+1)/2; printf("%lld\n", ans); for(ll a=0; a*2+1<leaf.size(); a++) printf("%lld %lld\n", leaf[a], leaf[a+(leaf.size()+1)/2]); if(leaf.size()%2==1) printf("%lld %lld\n", leaf[leaf.size()/2], leaf[0]); return 0; }

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

net.cpp: In function 'int main()':
net.cpp:52:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(ll a=0; a*2+1<leaf.size(); a++)
                 ~~~~~^~~~~~~~~~~~
net.cpp:6:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
 #define inlld(a) scanf("%lld", &a)
                  ~~~~~^~~~~~~~~~~~
net.cpp:36:5: note: in expansion of macro 'inlld'
     inlld(n);
     ^~~~~
net.cpp:8:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
 #define inlld2(a, b) scanf("%lld%lld", &a, &b)
                      ~~~~~^~~~~~~~~~~~~~~~~~~~
net.cpp:40:9: note: in expansion of macro 'inlld2'
         inlld2(u, v);
         ^~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...