제출 #137107

#제출 시각아이디문제언어결과실행 시간메모리
137107silxikysNetwork (BOI15_net)C++14
63 / 100
2068 ms57680 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; const int maxn = 5e5+5; int n; vector<int> adj[maxn]; int deg[maxn]; int tin[maxn]; int pt = 0; void dfs(int i, int p) { tin[i] = pt++; for (int j: adj[i]) { if (j == p) continue; dfs(j,i); } } int main() { scanf("%d",&n); for (int i = 0; i < n - 1; i++) { int a, b; scanf("%d %d",&a,&b); ++deg[a]; ++deg[b]; adj[a].push_back(b); adj[b].push_back(a); } vector<int> leafs; leafs.reserve(n); int start = 1; for (int i = 1; i <= n; i++) { if (deg[i] == 1) leafs.push_back(i); if (deg[i] > 1) { start = i; } } for (int j: adj[start]) { dfs(j,j); } sort(leafs.begin(),leafs.end(),[&](auto a, auto b) { return tin[a] < tin[b]; }); int k = leafs.size(); int m = k/2; printf("%d\n",(k+1)/2); for (int i = 0; i < (k+1)/2; i++) { printf("%d %d\n",leafs[i],leafs[(i+m)%k]); } }

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

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