# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
905890 | 2024-01-13T06:39:29 Z | dsyz | Network (BOI15_net) | C++17 | 5 ms | 12380 KB |
#include <bits/stdc++.h> using namespace std; using ll = long long; #define MAXN (500005) ll N; vector<ll> v[MAXN]; bool leaf[MAXN]; void dfs(ll x,ll p){ ll children = 0; for(auto u : v[x]){ if(u != p){ dfs(u,x); children++; } } if(children == 0){ leaf[x] = 1; } } int main() { ios_base::sync_with_stdio(false);cin.tie(0); cin>>N; for(ll i = 0;i < N - 1;i++){ ll a,b; cin>>a>>b; a--, b--; v[a].push_back(b); v[b].push_back(a); } dfs(0,-1); vector<ll> ans; for(ll i = 0;i < N;i++){ if(leaf[i]){ ans.push_back(i + 1); } } cout<<ans.size() - 1<<'\n'; cout<<1<<" "<<ans.back()<<'\n'; for(ll i = 1;i < ans.size() - 1;i++){ cout<<ans[i - 1]<<" "<<ans[i]<<'\n'; } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 5 ms | 12380 KB | Breaking single line is causing network to disconnect. |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 5 ms | 12380 KB | Breaking single line is causing network to disconnect. |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 5 ms | 12380 KB | Breaking single line is causing network to disconnect. |
2 | Halted | 0 ms | 0 KB | - |