# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
639709 |
2022-09-11T08:02:25 Z |
Wunka |
Network (BOI15_net) |
C++17 |
|
8 ms |
14048 KB |
#include<bits/stdc++.h>
using namespace std;
const int N = 5e5 + 5;
vector<vector<int>> graph(N);
vector<bool> visited(N);
vector<int> degree(N);
map<int, int> leaf;
int k = 0, mx, x;
void dfs(int v) {
visited[v] = true;
if(degree[v] == 1) {
leaf[k] = v;
k++;
}
for(int next : graph[v]) {
if(!visited[next]) {
dfs(next);
}
}
}
int main() {
int n;
cin >> n;
mx = 0;
for(int i = 0; i < n - 1; i++) {
int a, b;
cin >> a >> b;
a--, b--;
degree[a]++, degree[b]++;
graph[a].push_back(b);
graph[b].push_back(a);
if(degree[a] > mx) {
mx = degree[a];
x = a;
}
if(degree[b] > mx) {
mx = degree[b];
x = b;
}
}
dfs(x);
cout << (k + 1) / 2 << '\n';
/*
if(k % 2 == 1) {
cout << x + 1 << ' ' << leaf[k] + 1 << '\n';
k--;
}
*/
for(int i = 0; i < k - i - 1; i++) {
cout << leaf[i] + 1 << ' ' << leaf[k - i - 1] + 1 << '\n';
}
if(k % 2 == 1) {
cout << leaf[k / 2] + 1 << ' ' << x + 1 << '\n';
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
14048 KB |
Output is correct |
2 |
Incorrect |
7 ms |
14036 KB |
Breaking single line is causing network to disconnect. |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
14048 KB |
Output is correct |
2 |
Incorrect |
7 ms |
14036 KB |
Breaking single line is causing network to disconnect. |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
14048 KB |
Output is correct |
2 |
Incorrect |
7 ms |
14036 KB |
Breaking single line is causing network to disconnect. |
3 |
Halted |
0 ms |
0 KB |
- |