Submission #721006

# Submission time Handle Problem Language Result Execution time Memory
721006 2023-04-10T03:37:07 Z Pring Unique Cities (JOI19_ho_t5) C++14
4 / 100
787 ms 274432 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define endl '\n'
typedef pair<int, int> pii;

const int MXN = 2005;
int n, m, dis[MXN][MXN], color[MXN];
vector<int> edge[MXN];

void DFS(int root, int id, int parent, int depth) {
    dis[root][id] = depth;
    for (auto &i : edge[id]) {
        if (i == parent) continue;
        DFS(root, i, id, depth + 1);
    }
}

int solve(int id) {
    int ans = 0;
    bitset<MXN> b;
    vector<int> v(n, -1);
    for (int i = 0; i < n; i++) {
        if (i == id) continue;
        int &x = v[dis[id][i]];
        if (x == -2) continue;
        if (x == -1) x = i;
        else {
            x = -2;
        }
    }
    for (int i = 0; i < n; i++) {
        if (v[i] >= 0) {
            b[color[v[i]]] = true;
        }
    }
    return b.count();
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int x, y;
    cin >> n >> m;
    for (int i = 1; i < n; i++) {
        cin >> x >> y;
        edge[--x].push_back(--y);
        edge[y].push_back(x);
    }
    for (int i = 0; i < n; i++) {
        cin >> color[i];
        DFS(i, i, -1, 0);
    }
    for (int i = 0; i < n; i++) cout << solve(i) << endl;
    return 0;
}

Compilation message

joi2019_ho_t5.cpp: In function 'long long int solve(long long int)':
joi2019_ho_t5.cpp:21:9: warning: unused variable 'ans' [-Wunused-variable]
   21 |     int ans = 0;
      |         ^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 95 ms 29396 KB Output is correct
3 Correct 30 ms 11236 KB Output is correct
4 Correct 124 ms 28900 KB Output is correct
5 Correct 115 ms 31872 KB Output is correct
6 Correct 122 ms 31832 KB Output is correct
7 Correct 125 ms 31820 KB Output is correct
8 Correct 106 ms 31924 KB Output is correct
9 Correct 121 ms 31812 KB Output is correct
10 Correct 116 ms 31868 KB Output is correct
11 Correct 119 ms 31860 KB Output is correct
12 Correct 60 ms 31864 KB Output is correct
13 Correct 125 ms 31816 KB Output is correct
14 Correct 115 ms 31896 KB Output is correct
15 Correct 121 ms 31856 KB Output is correct
16 Correct 55 ms 31852 KB Output is correct
17 Correct 98 ms 31820 KB Output is correct
18 Correct 110 ms 31948 KB Output is correct
19 Correct 114 ms 31800 KB Output is correct
20 Correct 118 ms 31940 KB Output is correct
21 Correct 119 ms 31960 KB Output is correct
22 Correct 104 ms 31872 KB Output is correct
23 Correct 120 ms 31792 KB Output is correct
24 Correct 117 ms 31824 KB Output is correct
25 Correct 120 ms 31792 KB Output is correct
26 Correct 70 ms 31852 KB Output is correct
27 Correct 128 ms 31940 KB Output is correct
28 Correct 103 ms 31836 KB Output is correct
29 Correct 113 ms 31860 KB Output is correct
30 Correct 55 ms 31820 KB Output is correct
31 Correct 96 ms 31852 KB Output is correct
32 Correct 101 ms 31952 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 56 ms 15956 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 787 ms 274432 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 95 ms 29396 KB Output is correct
3 Correct 30 ms 11236 KB Output is correct
4 Correct 124 ms 28900 KB Output is correct
5 Correct 115 ms 31872 KB Output is correct
6 Correct 122 ms 31832 KB Output is correct
7 Correct 125 ms 31820 KB Output is correct
8 Correct 106 ms 31924 KB Output is correct
9 Correct 121 ms 31812 KB Output is correct
10 Correct 116 ms 31868 KB Output is correct
11 Correct 119 ms 31860 KB Output is correct
12 Correct 60 ms 31864 KB Output is correct
13 Correct 125 ms 31816 KB Output is correct
14 Correct 115 ms 31896 KB Output is correct
15 Correct 121 ms 31856 KB Output is correct
16 Correct 55 ms 31852 KB Output is correct
17 Correct 98 ms 31820 KB Output is correct
18 Correct 110 ms 31948 KB Output is correct
19 Correct 114 ms 31800 KB Output is correct
20 Correct 118 ms 31940 KB Output is correct
21 Correct 119 ms 31960 KB Output is correct
22 Correct 104 ms 31872 KB Output is correct
23 Correct 120 ms 31792 KB Output is correct
24 Correct 117 ms 31824 KB Output is correct
25 Correct 120 ms 31792 KB Output is correct
26 Correct 70 ms 31852 KB Output is correct
27 Correct 128 ms 31940 KB Output is correct
28 Correct 103 ms 31836 KB Output is correct
29 Correct 113 ms 31860 KB Output is correct
30 Correct 55 ms 31820 KB Output is correct
31 Correct 96 ms 31852 KB Output is correct
32 Correct 101 ms 31952 KB Output is correct
33 Runtime error 56 ms 15956 KB Execution killed with signal 11
34 Halted 0 ms 0 KB -