답안 #332897

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
332897 2020-12-04T00:30:28 Z ly20 Mergers (JOI19_mergers) C++17
10 / 100
34 ms 10216 KB
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 3123;
int marc[MAXN], tp[MAXN], sub[MAXN][MAXN];
int n, k;
vector <int> grafo[MAXN];
int vl[MAXN];
int resp = 0;
void dfs1(int v, int p) {
    for(int i = 0; i < grafo[v].size(); i++) {
        int viz = grafo[v][i];
        if(viz == p) continue;
        dfs1(viz, v);
        for(int j = 1; j <= k; j++) {
            sub[v][j] += sub[viz][j];
        }
        vl[v] += vl[viz];
    }
    bool ok = true;
    for(int i = 1; i <= k; i++) {
        if(sub[v][i] != marc[i] && sub[v][i] != 0) ok = false;
    }
    if(ok) vl[v]++;
    if(p == v) return;
    if(ok && vl[v] == 1) resp++;
}
int main() {
    scanf("%d %d", &n, &k);
    for(int i = 0; i < n - 1; i++) {
        int a, b;
        scanf("%d %d", &a, &b);
        grafo[a].push_back(b); grafo[b].push_back(a);
    }
    for(int i = 1 ; i<= n; i++) {
        int a;
        scanf("%d", &a);
        marc[a]++; tp[i] = a; sub[i][a]++;
    }
    if(n == 2) {
        if(tp[1] == tp[2]) printf("0\n");
        else printf("1\n");
        return 0;
    }
    int prox = 1;
    for(int i = 1; i <= n; i++) if(grafo[i].size() > 0) prox = i;
    dfs1(prox, prox);
    printf("%d\n", (resp + 1) / 2);
    return 0;
}

Compilation message

mergers.cpp: In function 'void dfs1(int, int)':
mergers.cpp:10:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   10 |     for(int i = 0; i < grafo[v].size(); i++) {
      |                    ~~^~~~~~~~~~~~~~~~~
mergers.cpp: In function 'int main()':
mergers.cpp:28:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   28 |     scanf("%d %d", &n, &k);
      |     ~~~~~^~~~~~~~~~~~~~~~~
mergers.cpp:31:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   31 |         scanf("%d %d", &a, &b);
      |         ~~~~~^~~~~~~~~~~~~~~~~
mergers.cpp:36:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   36 |         scanf("%d", &a);
      |         ~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 748 KB Output is correct
3 Correct 1 ms 768 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 896 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 876 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 876 KB Output is correct
12 Correct 11 ms 876 KB Output is correct
13 Correct 1 ms 492 KB Output is correct
14 Correct 1 ms 748 KB Output is correct
15 Correct 1 ms 748 KB Output is correct
16 Correct 1 ms 492 KB Output is correct
17 Correct 1 ms 492 KB Output is correct
18 Correct 1 ms 876 KB Output is correct
19 Correct 1 ms 492 KB Output is correct
20 Correct 1 ms 492 KB Output is correct
21 Correct 1 ms 876 KB Output is correct
22 Correct 1 ms 876 KB Output is correct
23 Correct 1 ms 492 KB Output is correct
24 Correct 1 ms 492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 748 KB Output is correct
3 Correct 1 ms 768 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 896 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 876 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 876 KB Output is correct
12 Correct 11 ms 876 KB Output is correct
13 Correct 1 ms 492 KB Output is correct
14 Correct 1 ms 748 KB Output is correct
15 Correct 1 ms 748 KB Output is correct
16 Correct 1 ms 492 KB Output is correct
17 Correct 1 ms 492 KB Output is correct
18 Correct 1 ms 876 KB Output is correct
19 Correct 1 ms 492 KB Output is correct
20 Correct 1 ms 492 KB Output is correct
21 Correct 1 ms 876 KB Output is correct
22 Correct 1 ms 876 KB Output is correct
23 Correct 1 ms 492 KB Output is correct
24 Correct 1 ms 492 KB Output is correct
25 Incorrect 1 ms 620 KB Output isn't correct
26 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 748 KB Output is correct
3 Correct 1 ms 768 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 896 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 876 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 876 KB Output is correct
12 Correct 11 ms 876 KB Output is correct
13 Correct 1 ms 492 KB Output is correct
14 Correct 1 ms 748 KB Output is correct
15 Correct 1 ms 748 KB Output is correct
16 Correct 1 ms 492 KB Output is correct
17 Correct 1 ms 492 KB Output is correct
18 Correct 1 ms 876 KB Output is correct
19 Correct 1 ms 492 KB Output is correct
20 Correct 1 ms 492 KB Output is correct
21 Correct 1 ms 876 KB Output is correct
22 Correct 1 ms 876 KB Output is correct
23 Correct 1 ms 492 KB Output is correct
24 Correct 1 ms 492 KB Output is correct
25 Incorrect 1 ms 620 KB Output isn't correct
26 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 34 ms 10216 KB Execution killed with signal 6 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 748 KB Output is correct
3 Correct 1 ms 768 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 896 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 876 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 876 KB Output is correct
12 Correct 11 ms 876 KB Output is correct
13 Correct 1 ms 492 KB Output is correct
14 Correct 1 ms 748 KB Output is correct
15 Correct 1 ms 748 KB Output is correct
16 Correct 1 ms 492 KB Output is correct
17 Correct 1 ms 492 KB Output is correct
18 Correct 1 ms 876 KB Output is correct
19 Correct 1 ms 492 KB Output is correct
20 Correct 1 ms 492 KB Output is correct
21 Correct 1 ms 876 KB Output is correct
22 Correct 1 ms 876 KB Output is correct
23 Correct 1 ms 492 KB Output is correct
24 Correct 1 ms 492 KB Output is correct
25 Incorrect 1 ms 620 KB Output isn't correct
26 Halted 0 ms 0 KB -