Submission #23239

# Submission time Handle Problem Language Result Execution time Memory
23239 2017-05-05T12:26:42 Z jjwdi0 Network (BOI15_net) C++11
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;

int N;
vector<int> v[500005], ans;
bool leaf[500005];

void dfs(int x, int p) {
    for(int it : v[x]) {
        if(it == p) continue;
        dfs(it, x);
        sz[x] += sz[it];
    }
    if(v[x].size() == 1) leaf[x] = 1;
}

int main() {
    scanf("%d", &N);
    for(int i=1, x, y; i<N; i++) {
        scanf("%d %d", &x, &y);
        v[x].push_back(y);
        v[y].push_back(x);
    }
    dfs(1, 0);
    for(int i=1; i<=N; i++) if(leaf[i]) ans.push_back(i);
    if((int)ans.size() % 2 == 1) ans.push_back(ans[0]);
    printf("%d\n", (int)ans.size() / 2);
    for(int i=0; i<ans.size(); i+=2) printf("%d %d\n", ans[i], ans[i+1]);
}

Compilation message

net.cpp: In function 'void dfs(int, int)':
net.cpp:12:9: error: 'sz' was not declared in this scope
         sz[x] += sz[it];
         ^
net.cpp: In function 'int main()':
net.cpp:28:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0; i<ans.size(); i+=2) printf("%d %d\n", ans[i], ans[i+1]);
                   ^
net.cpp:18:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &N);
                    ^
net.cpp:20:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d", &x, &y);
                               ^