# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
122121 | Gustav | Network (BOI15_net) | C++14 | 2 ms | 384 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 pair<int, int> pi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pi> vpi;
typedef vector<vi> vvi;
const int inf = 0x3f3f3f3f;
const ll linf = 123456789012345678;
const ll mod = 998244353;
#pragma GCC optimize("Ofast")
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " = " << x << endl
int n;
vvi conn;
int main(){
cin.sync_with_stdio(false);
cin.tie(0);
cin >> n;
conn = vvi(n);
for(int i = 0; i < n-1; i++){
int u, v;
cin >> u >> v;
u--, v--;
conn[u].push_back(v);
conn[v].push_back(u);
}
vi u;
for(int i = 0; i < n; i++) if(conn[i].size() == 1) u.push_back(i);
cout << (u.size()+1)/2 << "\n";
for(int i = 1; i < u.size(); i+=2) cout << u[i]+1 << " " << u[i-1]+1 << "\n";
if(u.size()%2 == 1){
int to = 0;
if(u[u.size()-1] == to) to++;
if(conn[u[u.size()-1]][0] == to) to++;
if(u[u.size()-1] == to) to++;
cout << u[u.size()-1]+1 << " " << to+1 << "\n";
}
}
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... |