| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 | 
|---|---|---|---|---|---|---|---|
| 1263564 | dzhoz0 | Network (BOI15_net) | C++20 | 0 ms | 328 KiB | 
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define INF 1e18
#define f first
#define s second
#define pii pair<int, int>
#define vi vector<int>
const int MOD = 1'000'000'000 + 7;
void setIO(string name = "")
{
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
#ifdef LOCAL
    freopen("inp.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#else
    if (!name.empty())
    {
        freopen((name + ".INP").c_str(), "r", stdin);
        freopen((name + ".OUT").c_str(), "w", stdout);
    }
#endif
}
const int MAXN = 5e5;
int n;
int deg[MAXN + 5];
void solve()
{
    cin >> n;
    for(int i = 1; i < n; i++) {
        int u, v; cin >> u >> v;
        deg[u]++;
        deg[v]++;
    }
    vi leaves;
    for(int i = 1; i <= n; i++) {
        if(deg[i] == 1) leaves.push_back(i);
    }
    cout << ((int)leaves.size() + 1) / 2 << '\n';
    for(int i = 0; i < (int)leaves.size() / 2; i++) {
        cout << leaves[i] << ' ' << leaves[(int)leaves.size() / 2 + i] << '\n';
    }
    if((int)leaves.size() & 1) cout << leaves.back() << ' ' << leaves[0] << '\n';
}
signed main()
{
    setIO();
    int t = 1;
    // cin >> t;
    while (t--)
        solve();
}
컴파일 시 표준 에러 (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... | ||||
