제출 #79540

#제출 시각아이디문제언어결과실행 시간메모리
79540FutymyCloneNetwork (BOI15_net)C++14
0 / 100
2 ms568 KiB
#include <bits/stdc++.h>

using namespace std;

const int N = 5e5 + 5;

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

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

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

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

컴파일 시 표준 에러 (stderr) 메시지

net.cpp: In function 'int main()':
net.cpp:20:53: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if ((int)vec.size() % 2 == 0) for (int i = 0; i < vec.size(); i += 2) printf("%d %d\n", vec[i], vec[i + 1]);
                                                   ~~^~~~~~~~~~~~
net.cpp:22:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int i = 0; i < vec.size() - 1; i += 2) printf("%d %d\n", vec[i], vec[i + 1]);
                         ~~^~~~~~~~~~~~~~~~
net.cpp:11:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
net.cpp:13: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...