제출 #1184836

#제출 시각아이디문제언어결과실행 시간메모리
1184836qrnNetwork (BOI15_net)C++20
0 / 100
0 ms324 KiB
#include <bits/stdc++.h> // #include <ext/pb_ds/assoc_container.hpp> using namespace std; // using namespace __gnu_pbds; #define SPEED \ ios_base::sync_with_stdio(0); \ cin.tie(NULL); \ cout.tie(NULL); #define pb push_back #define ins insert #define fi first #define se second #define endl "\n" #define ALL(x) x.begin(), x.end() #define sz(x) x.size() #define intt long long const intt mod = 1e9 + 7; const intt base = 31; const intt inf = 1e9; const intt mxN = 2e5 + 5; const intt L = 21; vector<vector<intt>> graph; vector<intt> v; void dfs(intt node, intt parent) { if(graph[node].size() == 1) { v.pb(node); } for(auto u : graph[node]) { if(u != parent){ dfs(u, node); } } } void solve() { intt N; cin >> N; graph.assign(N + 1, vector<intt> {}); for(intt i = 0; i < N - 1; i++) { intt a, b; cin >> a >> b; graph[a].pb(b); graph[b].pb(a); } dfs(1, 1); cout << (v.size()) / 2 + (v.size() % 2 != 0) << endl; for(intt i = 0; i < v.size() - 1; i+=2) { cout << v[i] << " " << v[i+1] << endl; } if(v.size() % 2 != 0) { cout << v[0] << " " << v.back() << endl; } } signed main() { SPEED; intt tst = 1; // cin >> tst; while (tst--) { solve(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...