답안 #342405

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
342405 2021-01-02T05:48:21 Z mjhmjh1104 Spring cleaning (CEOI20_cleaning) C++14
9 / 100
53 ms 7908 KB
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

const int MAX = 100006;

int n, q, d, childs[MAX];
vector<int> adj[MAX];

int main() {
    scanf("%d%d", &n, &q);
    for (int i = 0; i < n - 1; i++) {
        int a, b;
        scanf("%d%d", &a, &b);
        a--, b--;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    scanf("%d", &d);
    for (int i = 0; i < d; i++) {
        int x;
        scanf("%d", &x); x--;
        childs[x]++;
    }
    int cnt = 0;
    for (int i = 1; i < n; i++) cnt += max(childs[i], 1);
    if (cnt % 2) return puts("-1"), 0;
    long long res = 0;
    for (int i = 1; i < n; i++) if (childs[i] > 2) res += (childs[i] - 1) / 2 * 2, childs[i] -= (childs[i] - 1) / 2 * 2;
    for (int i = 1; i < n; i++) if (childs[i]) res += childs[i] * 2; else res++;
    printf("%lld", res);
}

Compilation message

cleaning.cpp: In function 'int main()':
cleaning.cpp:12:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   12 |     scanf("%d%d", &n, &q);
      |     ~~~~~^~~~~~~~~~~~~~~~
cleaning.cpp:15:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   15 |         scanf("%d%d", &a, &b);
      |         ~~~~~^~~~~~~~~~~~~~~~
cleaning.cpp:20:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   20 |     scanf("%d", &d);
      |     ~~~~~^~~~~~~~~~
cleaning.cpp:23:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   23 |         scanf("%d", &x); x--;
      |         ~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 2816 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 3180 KB Output is correct
2 Correct 12 ms 3180 KB Output is correct
3 Correct 36 ms 7396 KB Output is correct
4 Correct 35 ms 6520 KB Output is correct
5 Correct 45 ms 7908 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 14 ms 3308 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 14 ms 3692 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 29 ms 5612 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 53 ms 7276 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 2816 KB Output isn't correct
2 Halted 0 ms 0 KB -