제출 #320769

#제출 시각아이디문제언어결과실행 시간메모리
320769gustasonNetwork (BOI15_net)C++14
0 / 100
1 ms364 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector<int> ind(n+1, 0), conn(n+1); for(int i = 0; i < n-1; i++) { int a, b; cin >> a >> b; ind[a]++; ind[b]++; conn[a] = b; conn[b] = a; } vector<int> edges; for(int i = 0; i <= n; i++) { if (ind[i] == 1) { edges.push_back(i); } } int sz = edges.size(); cout << ceil((double) sz / 2) << "\n"; for(int i = 2; i < sz; i += 2) { cout << edges[i-1] << " " << edges[i-2] << "\n"; } if (sz % 2) { int last = edges[sz-1]; if (conn[last] == 1) { conn[last] = 2; } else { conn[last] = 1; } cout << last << " " << conn[last] << "\n"; } // for(int i ) // for(int i : edges) { // cout << i << " "; // } return 0; } //~ check for overflows
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...