# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
145448 | 2019-08-19T21:39:43 Z | luciocf | Uzastopni (COCI15_uzastopni) | C++14 | 244 ms | 19192 KB |
#include <bits/stdc++.h> using namespace std; const int maxn = 1e4+10; const int maxv = 110; int a[maxn]; bool tem[maxv][maxv]; vector<int> grafo[maxn]; bitset<maxv> bs[maxn][maxv]; void undo(void) { for (int i = 1; i < maxv; i++) for (int j = 1; j < maxv; j++) tem[i][j] = 0; } void dfs(int u, int p) { for (auto v: grafo[u]) if (v != p) dfs(v, u); undo(); for (auto v: grafo[u]) { if (v == p) continue; for (int i = 1; i < maxv; i++) { for (int j = i; j < maxv; j++) { if (i > a[u] && i <= a[v] && bs[v][i][j]) bs[u][i][j] = 1; if (i <= a[v] && bs[v][i][j]) tem[i][j] = 1; } } } bs[u][a[u]][a[u]] = tem[a[u]][a[u]] = 1; for (int l = maxv-1; l > a[u]; l--) for (int r = l; r < maxv-1; r++) if (tem[l][r]) bs[u][l] |= bs[u][r+1]; bs[u][a[u]] |= bs[u][a[u]+1]; for (int l = a[u]-1; l >= 1; l--) for (int r = l; r < a[u]; r++) if (tem[l][r]) bs[u][l] |= bs[u][r+1]; } int main(void) { int n; scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); for (int i = 1; i < n; i++) { int u, v; scanf("%d %d", &u, &v); grafo[u].push_back(v); grafo[v].push_back(u); } dfs(1, 0); int ans = 0; for (int i = 1; i <= a[1]; i++) ans += (int)bs[1][i].count(); printf("%d\n", ans); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 760 KB | Output is correct |
2 | Correct | 4 ms | 632 KB | Output is correct |
3 | Correct | 4 ms | 760 KB | Output is correct |
4 | Correct | 4 ms | 760 KB | Output is correct |
5 | Correct | 5 ms | 732 KB | Output is correct |
6 | Correct | 5 ms | 760 KB | Output is correct |
7 | Correct | 6 ms | 760 KB | Output is correct |
8 | Correct | 5 ms | 760 KB | Output is correct |
9 | Correct | 4 ms | 760 KB | Output is correct |
10 | Correct | 5 ms | 760 KB | Output is correct |
11 | Correct | 217 ms | 18424 KB | Output is correct |
12 | Correct | 222 ms | 18424 KB | Output is correct |
13 | Correct | 219 ms | 18268 KB | Output is correct |
14 | Correct | 238 ms | 19192 KB | Output is correct |
15 | Correct | 244 ms | 19176 KB | Output is correct |
16 | Correct | 237 ms | 19192 KB | Output is correct |
17 | Correct | 210 ms | 18364 KB | Output is correct |
18 | Correct | 208 ms | 18196 KB | Output is correct |
19 | Correct | 233 ms | 18296 KB | Output is correct |
20 | Correct | 230 ms | 18300 KB | Output is correct |