Submission #332900

# Submission time Handle Problem Language Result Execution time Memory
332900 2020-12-04T00:38:33 Z ly20 Mergers (JOI19_mergers) C++17
10 / 100
45 ms 37356 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() > 1) 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);
      |         ~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 748 KB Output is correct
3 Correct 1 ms 748 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 748 KB Output is correct
7 Correct 0 ms 364 KB Output is correct
8 Correct 1 ms 748 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 1 ms 748 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
# Verdict Execution time Memory Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 748 KB Output is correct
3 Correct 1 ms 748 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 748 KB Output is correct
7 Correct 0 ms 364 KB Output is correct
8 Correct 1 ms 748 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 1 ms 748 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 Correct 1 ms 620 KB Output is correct
26 Correct 27 ms 28140 KB Output is correct
27 Correct 10 ms 13164 KB Output is correct
28 Correct 37 ms 26860 KB Output is correct
29 Correct 31 ms 26732 KB Output is correct
30 Correct 11 ms 13804 KB Output is correct
31 Correct 1 ms 620 KB Output is correct
32 Correct 45 ms 37356 KB Output is correct
33 Correct 1 ms 620 KB Output is correct
34 Correct 9 ms 12652 KB Output is correct
35 Correct 31 ms 26732 KB Output is correct
36 Incorrect 10 ms 12908 KB Output isn't correct
37 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 748 KB Output is correct
3 Correct 1 ms 748 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 748 KB Output is correct
7 Correct 0 ms 364 KB Output is correct
8 Correct 1 ms 748 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 1 ms 748 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 Correct 1 ms 620 KB Output is correct
26 Runtime error 34 ms 10856 KB Execution killed with signal 6 (could be triggered by violating memory limits)
27 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 43 ms 10600 KB Execution killed with signal 6 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 748 KB Output is correct
3 Correct 1 ms 748 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 748 KB Output is correct
7 Correct 0 ms 364 KB Output is correct
8 Correct 1 ms 748 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 1 ms 748 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 Correct 1 ms 620 KB Output is correct
26 Correct 27 ms 28140 KB Output is correct
27 Correct 10 ms 13164 KB Output is correct
28 Correct 37 ms 26860 KB Output is correct
29 Correct 31 ms 26732 KB Output is correct
30 Correct 11 ms 13804 KB Output is correct
31 Correct 1 ms 620 KB Output is correct
32 Correct 45 ms 37356 KB Output is correct
33 Correct 1 ms 620 KB Output is correct
34 Correct 9 ms 12652 KB Output is correct
35 Correct 31 ms 26732 KB Output is correct
36 Incorrect 10 ms 12908 KB Output isn't correct
37 Halted 0 ms 0 KB -