# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
113779 | 2019-05-28T08:23:49 Z | Mercenary | Network (BOI15_net) | C++14 | 13 ms | 12160 KB |
#include<bits/stdc++.h> using namespace std; #define taskname "A" #define pb push_back #define mp make_pair #ifndef LOCAL #define cerr if(0)cout #endif typedef long double ld; typedef long long ll; typedef pair<int,int> ii; const int maxn = 5e5 + 6; int n , m; vector<int> leaf , adj[maxn]; void dfs(int u , int v){ if(adj[u].size() == 1){ leaf.pb(u); } for(int c : adj[u]){ if(c != v)dfs(c , u); } } void enter(){ cin >> n; for(int i = 1 ; i < n ; ++i){ int u , v;cin >> u >> v; adj[u].pb(v); adj[v].pb(u); } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); if(fopen(taskname".INP","r")){ freopen(taskname".INP", "r",stdin); freopen(taskname".OUT", "w",stdout); } enter(); int root = 0; for(int i = 1 ; i <= n ; ++i){ if(adj[i].size() > 1){ dfs(i , 0); root = i; break; } } if(leaf.size() % 2){ leaf.pb(root); } cout << leaf.size() / 2 << '\n'; for(int i = 0 ; i < leaf.size() / 2 ; ++i){ cout << leaf[i] << " " << leaf[leaf.size() - i - 1] << '\n'; } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 13 ms | 12032 KB | Output is correct |
2 | Incorrect | 13 ms | 12160 KB | Breaking single line is causing network to disconnect. |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 13 ms | 12032 KB | Output is correct |
2 | Incorrect | 13 ms | 12160 KB | Breaking single line is causing network to disconnect. |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 13 ms | 12032 KB | Output is correct |
2 | Incorrect | 13 ms | 12160 KB | Breaking single line is causing network to disconnect. |
3 | Halted | 0 ms | 0 KB | - |