제출 #24944

#제출 시각아이디문제언어결과실행 시간메모리
24944RezwanArefin01Network (BOI15_net)C++14
100 / 100
623 ms42508 KiB
//Bismillahir Rahmanir Rahim #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> ii; const int maxn = 5e5; vector<int> adj[maxn], lef; void dfs(int u, int par){ for(int v : adj[u]) if(v - par) dfs(v, u); if(adj[u].size() == 1) lef.push_back(u); } int main(int argc, char const *argv[]) { #ifdef LOCAL_TESTING freopen("in", "r", stdin); #endif int n; scanf("%d", &n); for(int i=0; i<n-1; i++) { int u, v; scanf("%d %d", &u, &v); adj[u].push_back(v); adj[v].push_back(u); } for(int i=1; i<=n; i++) if(adj[i].size() > 1) { dfs(i, 0); break; } int sz = int((lef.size()+1)/2); printf("%d\n", sz); for(int i=0; i<sz; i++) { printf("%d %d\n", lef[i], lef[i + lef.size()/2]); } }

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

net.cpp: In function 'int main(int, const char**)':
net.cpp:16:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  int n; scanf("%d", &n);
                        ^
net.cpp:19:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &u, &v);
                         ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...