Submission #594204

# Submission time Handle Problem Language Result Execution time Memory
594204 2022-07-12T08:22:15 Z 박상훈(#8431) Unique Cities (JOI19_ho_t5) C++17
4 / 100
2000 ms 17856 KB
#include <bits/stdc++.h>

typedef long long ll;
using namespace std;
vector<int> adj[200200], D[200200];
int n, m, c[200200];

void dfs(int s, int pa = -1, int dep = 0){
    D[dep].push_back(c[s]);
    for (auto &v:adj[s]) if (v!=pa){
        dfs(v, s, dep+1);
    }
}

void naive(int R){
    for (int i=0;i<=n;i++) D[i].clear();
    dfs(R);
    vector<int> ans;
    for (int i=1;i<=n;i++) if (D[i].size()==1){
        ans.push_back(D[i][0]);
    }
    sort(ans.begin(), ans.end());
    ans.erase(unique(ans.begin(), ans.end()), ans.end());

    printf("%d\n", (int)ans.size());
}

int main(){
    scanf("%d %d", &n, &m);
    for (int i=1;i<=n-1;i++){
        int x, y;
        scanf("%d %d", &x, &y);
        adj[x].push_back(y);
        adj[y].push_back(x);
    }

    for (int i=1;i<=n;i++) scanf("%d", c+i);
    for (int i=1;i<=n;i++) naive(i);
    return 0;
}

Compilation message

joi2019_ho_t5.cpp: In function 'int main()':
joi2019_ho_t5.cpp:29:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |     scanf("%d %d", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~~
joi2019_ho_t5.cpp:32:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   32 |         scanf("%d %d", &x, &y);
      |         ~~~~~^~~~~~~~~~~~~~~~~
joi2019_ho_t5.cpp:37:33: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |     for (int i=1;i<=n;i++) scanf("%d", c+i);
      |                            ~~~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 61 ms 9804 KB Output is correct
3 Correct 45 ms 9832 KB Output is correct
4 Correct 73 ms 9984 KB Output is correct
5 Correct 79 ms 9852 KB Output is correct
6 Correct 137 ms 9940 KB Output is correct
7 Correct 84 ms 9940 KB Output is correct
8 Correct 67 ms 9836 KB Output is correct
9 Correct 78 ms 9812 KB Output is correct
10 Correct 67 ms 9940 KB Output is correct
11 Correct 103 ms 9940 KB Output is correct
12 Correct 43 ms 9812 KB Output is correct
13 Correct 123 ms 9896 KB Output is correct
14 Correct 72 ms 10708 KB Output is correct
15 Correct 75 ms 10564 KB Output is correct
16 Correct 40 ms 9824 KB Output is correct
17 Correct 97 ms 12496 KB Output is correct
18 Correct 76 ms 10872 KB Output is correct
19 Correct 65 ms 9828 KB Output is correct
20 Correct 175 ms 9848 KB Output is correct
21 Correct 82 ms 10004 KB Output is correct
22 Correct 62 ms 9812 KB Output is correct
23 Correct 78 ms 9880 KB Output is correct
24 Correct 66 ms 9896 KB Output is correct
25 Correct 74 ms 9856 KB Output is correct
26 Correct 47 ms 9852 KB Output is correct
27 Correct 132 ms 10064 KB Output is correct
28 Correct 117 ms 12388 KB Output is correct
29 Correct 97 ms 10664 KB Output is correct
30 Correct 49 ms 9748 KB Output is correct
31 Correct 112 ms 12484 KB Output is correct
32 Correct 84 ms 10828 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 2085 ms 15880 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2079 ms 17856 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 61 ms 9804 KB Output is correct
3 Correct 45 ms 9832 KB Output is correct
4 Correct 73 ms 9984 KB Output is correct
5 Correct 79 ms 9852 KB Output is correct
6 Correct 137 ms 9940 KB Output is correct
7 Correct 84 ms 9940 KB Output is correct
8 Correct 67 ms 9836 KB Output is correct
9 Correct 78 ms 9812 KB Output is correct
10 Correct 67 ms 9940 KB Output is correct
11 Correct 103 ms 9940 KB Output is correct
12 Correct 43 ms 9812 KB Output is correct
13 Correct 123 ms 9896 KB Output is correct
14 Correct 72 ms 10708 KB Output is correct
15 Correct 75 ms 10564 KB Output is correct
16 Correct 40 ms 9824 KB Output is correct
17 Correct 97 ms 12496 KB Output is correct
18 Correct 76 ms 10872 KB Output is correct
19 Correct 65 ms 9828 KB Output is correct
20 Correct 175 ms 9848 KB Output is correct
21 Correct 82 ms 10004 KB Output is correct
22 Correct 62 ms 9812 KB Output is correct
23 Correct 78 ms 9880 KB Output is correct
24 Correct 66 ms 9896 KB Output is correct
25 Correct 74 ms 9856 KB Output is correct
26 Correct 47 ms 9852 KB Output is correct
27 Correct 132 ms 10064 KB Output is correct
28 Correct 117 ms 12388 KB Output is correct
29 Correct 97 ms 10664 KB Output is correct
30 Correct 49 ms 9748 KB Output is correct
31 Correct 112 ms 12484 KB Output is correct
32 Correct 84 ms 10828 KB Output is correct
33 Execution timed out 2085 ms 15880 KB Time limit exceeded
34 Halted 0 ms 0 KB -