Submission #79560

#TimeUsernameProblemLanguageResultExecution timeMemory
79560FutymyCloneNetwork (BOI15_net)C++14
100 / 100
663 ms41528 KiB
#include <bits/stdc++.h>

using namespace std;

const int N = 5e5 + 5;

int n;
vector <int> vec, g[N];

void dfs (int u, int p) {
    bool leaf = true;
    for (auto v: g[u]) {
        if (v == p) continue;
        leaf = false;
        dfs(v, u);
    }

    if (leaf) vec.push_back(u);
}

int main(){
    scanf("%d", &n);
    for (int i = 1; i <= n - 1; i++) {
        int u, v; scanf("%d %d", &u, &v);
        g[u].push_back(v); g[v].push_back(u);
    }

    for (int i = 1; i <= n; i++) {
        if (g[i].size() > 1) {
            dfs(i, i);
            break;
        }
    }

    printf("%d\n", ((int)vec.size() + 1) / 2);
    for (int i = 0; i < ((int)vec.size() + 1) / 2; i++) printf("%d %d\n", vec[i], vec[i + vec.size() / 2]);
    return 0;
}

Compilation message (stderr)

net.cpp: In function 'int main()':
net.cpp:22:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
net.cpp:24:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         int u, v; scanf("%d %d", &u, &v);
                   ~~~~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...