답안 #116762

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
116762 2019-06-13T17:54:20 Z roseanne_pcy Network (BOI15_net) C++14
컴파일 오류
0 ms 0 KB
//Power Of Ninja Go
#include <bits/stdc++.h>
//#ifdef atom #else #endif
using namespace std;
typedef long long ll; typedef pair<int, int> ii;
#define X first
#define Y second
#define vi vector<int>
#define vii vector< ii >
#define pb push_back
const int maxn = 5e5+5;
vi adj[maxn];
vi leaf;
void dfs(int u, int p)
{
    bool found = 0;
    for(auto v : adj[u])
    {
        if(v == p) continue;
        dfs(v, u);
        found = 1;
    }
    if(!found) leaf.pb(u);p
}
int main()
{
    //#ifndef atom freopen(".in", "r", stdin); freopen(".out", "w", stdout); #endif
    int n; scanf("%d", &n);
    for(int i = 0; i< n-1; i++)
    {
        int u, v; scanf("%d %d", &u, &v);
        adj[u].pb(v); adj[v].pb(u);
    }
    int s = 1;
    for(int i = 1; i<= n; i++) if(adj[i].size()> 1) s = i;
    dfs(s, 0);
    printf("%d\n", (leaf.size()+1)/2);
    int mid = (leaf.size()+1)/2;
    for(int i = 0; i< mid; i++)
    {
        printf("%d %d\n", leaf[i], leaf[min((int) leaf.size()-1, mid+i)]);
    }
}

Compilation message

net.cpp: In function 'void dfs(int, int)':
net.cpp:23:5: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
     if(!found) leaf.pb(u);p
     ^~
net.cpp:23:27: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
     if(!found) leaf.pb(u);p
                           ^
net.cpp:24:1: error: expected ';' before '}' token
 }
 ^
net.cpp:24:1: warning: statement has no effect [-Wunused-value]
net.cpp: In function 'int main()':
net.cpp:37:37: warning: format '%d' expects argument of type 'int', but argument 2 has type 'std::vector<int>::size_type {aka long unsigned int}' [-Wformat=]
     printf("%d\n", (leaf.size()+1)/2);
                    ~~~~~~~~~~~~~~~~~^
net.cpp:28:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     int n; scanf("%d", &n);
            ~~~~~^~~~~~~~~~
net.cpp:31: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);
                   ~~~~~^~~~~~~~~~~~~~~~~