# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
594072 | 2022-07-12T04:48:16 Z | 반딧불(#8432) | Unique Cities (JOI19_ho_t5) | C++17 | 2000 ms | 27264 KB |
#include <bits/stdc++.h> using namespace std; typedef long long ll; int n, k; vector<int> link[200002]; int arr[200002]; int par[200002], depth[200002], LCADB[200002][20]; void dfs(int x, int p=-1){ for(auto y: link[x]){ if(y==p) continue; par[y] = LCADB[y][0] = x, depth[y] = depth[x]+1; dfs(y, x); } } int getLCA(int x, int y){ if(depth[x] > depth[y]) swap(x, y); for(int d=0; d<20; d++) if((depth[y]-depth[x])&(1<<d)) y=LCADB[y][d]; if(x==y) return x; for(int d=19; d>=0; d--) if(LCADB[x][d] != LCADB[y][d]) x = LCADB[x][d], y = LCADB[y][d]; return par[x]; } int dist(int x, int y){ return depth[x] + depth[y] - 2*depth[getLCA(x, y)]; } int main(){ scanf("%d %d", &n, &k); for(int i=1; i<n; i++){ int x, y; scanf("%d %d", &x, &y); link[x].push_back(y); link[y].push_back(x); } for(int i=1; i<=n; i++) scanf("%d", &arr[i]); dfs(1); for(int d=1; d<20; d++) for(int i=1; i<=n; i++) LCADB[i][d] = LCADB[LCADB[i][d-1]][d-1]; for(int i=1; i<=n; i++){ map<int, int> mp; for(int j=1; j<=n; j++){ if(i==j) continue; mp[dist(i, j)]++; } vector<bool> chk(k+1); for(int j=1; j<=n; j++){ if(mp[dist(i, j)] == 1) chk[arr[j]] = true; } printf("%d\n", count(chk.begin(), chk.end(), true)); } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 4948 KB | Output is correct |
2 | Correct | 967 ms | 5252 KB | Output is correct |
3 | Correct | 333 ms | 5208 KB | Output is correct |
4 | Correct | 1286 ms | 5312 KB | Output is correct |
5 | Correct | 1058 ms | 5288 KB | Output is correct |
6 | Correct | 1796 ms | 5416 KB | Output is correct |
7 | Correct | 1583 ms | 5356 KB | Output is correct |
8 | Correct | 763 ms | 5272 KB | Output is correct |
9 | Correct | 1345 ms | 5292 KB | Output is correct |
10 | Correct | 1159 ms | 5284 KB | Output is correct |
11 | Correct | 1152 ms | 5276 KB | Output is correct |
12 | Correct | 622 ms | 5276 KB | Output is correct |
13 | Correct | 1789 ms | 5416 KB | Output is correct |
14 | Correct | 1255 ms | 5332 KB | Output is correct |
15 | Correct | 1333 ms | 5332 KB | Output is correct |
16 | Correct | 567 ms | 5324 KB | Output is correct |
17 | Correct | 1221 ms | 5408 KB | Output is correct |
18 | Correct | 1367 ms | 5588 KB | Output is correct |
19 | Correct | 1038 ms | 5272 KB | Output is correct |
20 | Correct | 1776 ms | 5588 KB | Output is correct |
21 | Correct | 1638 ms | 5344 KB | Output is correct |
22 | Correct | 790 ms | 5272 KB | Output is correct |
23 | Correct | 1263 ms | 5292 KB | Output is correct |
24 | Correct | 1099 ms | 5288 KB | Output is correct |
25 | Correct | 1101 ms | 5284 KB | Output is correct |
26 | Correct | 572 ms | 5280 KB | Output is correct |
27 | Correct | 1680 ms | 5408 KB | Output is correct |
28 | Correct | 1307 ms | 5460 KB | Output is correct |
29 | Correct | 1401 ms | 5336 KB | Output is correct |
30 | Correct | 618 ms | 5284 KB | Output is correct |
31 | Correct | 1446 ms | 5380 KB | Output is correct |
32 | Correct | 1429 ms | 5352 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 2058 ms | 20672 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 2047 ms | 27264 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 4948 KB | Output is correct |
2 | Correct | 967 ms | 5252 KB | Output is correct |
3 | Correct | 333 ms | 5208 KB | Output is correct |
4 | Correct | 1286 ms | 5312 KB | Output is correct |
5 | Correct | 1058 ms | 5288 KB | Output is correct |
6 | Correct | 1796 ms | 5416 KB | Output is correct |
7 | Correct | 1583 ms | 5356 KB | Output is correct |
8 | Correct | 763 ms | 5272 KB | Output is correct |
9 | Correct | 1345 ms | 5292 KB | Output is correct |
10 | Correct | 1159 ms | 5284 KB | Output is correct |
11 | Correct | 1152 ms | 5276 KB | Output is correct |
12 | Correct | 622 ms | 5276 KB | Output is correct |
13 | Correct | 1789 ms | 5416 KB | Output is correct |
14 | Correct | 1255 ms | 5332 KB | Output is correct |
15 | Correct | 1333 ms | 5332 KB | Output is correct |
16 | Correct | 567 ms | 5324 KB | Output is correct |
17 | Correct | 1221 ms | 5408 KB | Output is correct |
18 | Correct | 1367 ms | 5588 KB | Output is correct |
19 | Correct | 1038 ms | 5272 KB | Output is correct |
20 | Correct | 1776 ms | 5588 KB | Output is correct |
21 | Correct | 1638 ms | 5344 KB | Output is correct |
22 | Correct | 790 ms | 5272 KB | Output is correct |
23 | Correct | 1263 ms | 5292 KB | Output is correct |
24 | Correct | 1099 ms | 5288 KB | Output is correct |
25 | Correct | 1101 ms | 5284 KB | Output is correct |
26 | Correct | 572 ms | 5280 KB | Output is correct |
27 | Correct | 1680 ms | 5408 KB | Output is correct |
28 | Correct | 1307 ms | 5460 KB | Output is correct |
29 | Correct | 1401 ms | 5336 KB | Output is correct |
30 | Correct | 618 ms | 5284 KB | Output is correct |
31 | Correct | 1446 ms | 5380 KB | Output is correct |
32 | Correct | 1429 ms | 5352 KB | Output is correct |
33 | Execution timed out | 2058 ms | 20672 KB | Time limit exceeded |
34 | Halted | 0 ms | 0 KB | - |