제출 #79597

#제출 시각아이디문제언어결과실행 시간메모리
79597EntityITNetwork (BOI15_net)C++14
0 / 100
14 ms12396 KiB
#include<bits/stdc++.h> using namespace std; #define pb push_back #define fi first #define se second typedef pair<int, int> ii; const int N = 5e5 + 5; int n, child[N], nLeaf; vector<int> gr[N], vec; void prep (int u, int p) { for (int v : gr[u]) if (v != p) { prep(v, u); child[u] += child[v]; } child[u] += (gr[u].size() == 1); } int findCentroid (int u, int p) { for (int v : gr[u]) if (v != p) { if (child[v] > (nLeaf + 1) / 2 ) return findCentroid(v, u); } return u; } void dfs (int u, int p) { for (int v : gr[u]) if (v != p) dfs(v, u); if (gr[u].size() == 1) vec.pb(u); } int main () { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; for (int _ = 1; _ < n; ++_) { int u, v; cin >> u >> v; gr[u].pb(v); gr[v].pb(u); } for (int u = 1; u <= n; ++u) nLeaf += (gr[u].size() == 1); cout << (nLeaf + 1) / 2 << '\n'; prep(1, 1); int cen = findCentroid(1, 1); for (int u : gr[cen]) dfs(u, cen); for (int i = 0; i < vec.size() - (nLeaf + 1) / 2; ++i) { cout << vec[i] << ' ' << vec[ i + (nLeaf + 1) / 2 ] << '\n'; } if (nLeaf % 2) cout << vec[0] << ' ' << vec[nLeaf / 2]; return 0; }

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

net.cpp: In function 'int main()':
net.cpp:49:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < vec.size() - (nLeaf + 1) / 2; ++i) {
                     ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...