# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1278872 | hoa208 | Network (BOI15_net) | C++20 | 310 ms | 50572 KiB |
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; i++)
#define FORD(i, b, a) for (int i = (b), _a = (a); i >= _a; i--)
#define pa pair<ll, ll>
#define fi first
#define se second
#define bit(mask, j) ((mask >> j) & 1)
const ll mod = 1e9 + 7;
const ll INF = 1e18;
//--------------------------------------------------------------------
const ll N = 5e5 + 10;
vector<ll> g[N], vt;
void dfs(ll u, ll p) {
if(g[u].size() == 1) {
vt.push_back(u);
}
for(auto v : g[u]) {
if(v == p) continue;
dfs(v, u);
}
}
void hbmt() {
ll n;
cin >> n;
FOR(i, 1, n - 1) {
ll u, v;
cin >> u >> v;
g[u].push_back(v);
g[v].push_back(u);
}
dfs(1, 0);
ll k = (vt.size() + 1) / 2;
ll e = vt.size() / 2;
cout << k << '\n';
for(int i = 0; i < e; i++) {
cout << vt[i] << ' ' << vt[i + e] << '\n';
}
if(vt.size() % 2 == 1) {
cout << vt.back() << ' ' << vt[0] << '\n';
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
#define NAME "hbmt"
if(fopen(NAME".inp", "r")) {
freopen(NAME".inp", "r", stdin);
freopen(NAME".out", "w", stdout);
}
//int t;cin>>t;while(t--)
hbmt();
return 0;
}
컴파일 시 표준 에러 (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... |