# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
486548 | Killer2501 | Network (BOI15_net) | C++14 | 1 ms | 716 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>
#define pll pair<ll, ll>
#define fi first
#define se second
#define pb push_back
#define task "test"
#define pii pair<ll, pll>
using namespace std;
using ll = long long ;
const int N = 1e2+5;
const ll mod = 1e9+7;
const ll base = 350;
const ll inf = 1e15;
ll m, n, t, k, a[N][N], b[N][N], ans, tong, d[N];
pll trave[N];
vector<ll> kq;
vector<ll> adj[N];
bool ok[N];
string s;
map<ll, ll> mp[N];
void add(ll& x, ll y, ll md)
{
x += y;
if(x >= md)x -= md;
}
ll pw(ll k, ll n, ll md)
{
ll total = 1;
for(; n; n >>= 1)
{
if(n&1)total = total * k % md;
k = k * k % md;
}
return total;
}
void dfs(ll u, ll p)
{
for(ll v: adj[u])
{
if(v == p)continue;
dfs(v, u);
}
if(adj[u].size() == 1)kq.pb(u);
}
void sol()
{
cin >> n;
for(int i = 1; i < n; i ++)
{
ll x, y;
cin >> x >> y;
adj[x].pb(y);
adj[y].pb(x);
}
dfs(1, 0);
m = kq.size();
cout << (m+1)/2 << '\n';
for(int i = 0; i < m/2; i ++)cout << kq[i] <<" "<<kq[i+m/2] << '\n';
if(m&1)cout << kq[m/2] <<" "<<kq.back();
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
if(fopen(task".inp", "r"))
{
freopen(task".inp", "r", stdin);
freopen(task".out", "w", stdout);
}
int ntest = 1;
//cin >> ntest;
while(ntest -- > 0)
sol();
}
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... |