# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
849147 | sandry24 | Network (BOI15_net) | C++17 | 1 ms | 348 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define pb push_back
#define mp make_pair
#define f first
#define s second
void solve(){
int n;
cin >> n;
vector<vi> adj(n+5);
for(int i = 0; i < n-1; i++){
int a, b;
cin >> a >> b;
adj[a].pb(b);
adj[b].pb(a);
}
vi leaves;
for(int i = 1; i <= n; i++)
if(adj[i].size() == 1)
leaves.pb(i);
cout << ceil((double)leaves.size()/2) << '\n';
for(int i = 0; i < leaves.size()/2; i++)
cout << leaves[i] << ' ' << leaves[i + leaves.size()/2] << '\n';
if(leaves.size() & 1)
cout << leaves[0] << ' ' << leaves.back() << '\n';
}
int main(){
//freopen("flota.in", "r", stdin);
//freopen("flota.out", "w", stdout);
ios::sync_with_stdio(0); cin.tie(0);
int t = 1;
//cin >> t;
while(t--){
solve();
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |