# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
966967 | 2024-04-20T18:09:54 Z | blackslex | Capital City (JOI20_capital_city) | C++17 | 3000 ms | 12568 KB |
#include<bits/stdc++.h> using namespace std; int n, k, x, y; int main() { scanf("%d %d", &n, &k); vector<int> c(n + 5), st(k + 5); vector<vector<int>> v(n + 5, vector<int>()); for (int i = 1; i < n; i++) scanf("%d %d", &x, &y), v[x].emplace_back(y), v[y].emplace_back(x); for (int i = 1; i <= n; i++) scanf("%d", &c[i]), st[--c[i]] = i; vector<bool> f(n + 5); function<void(int, int, int)> dfs = [&] (int cur, int par, int msk) { if (!(msk & (1 << c[cur]))) return; f[cur] = 1; for (auto &e: v[cur]) { if (par == e) continue; dfs(e, cur, msk); } }; int ans = 1e9; for (int i = 1; i < (1 << k); i++) { f.assign(n + 5, 0); int cst = 0; for (int j = 1; j <= n; j++) if (i & (1 << c[j])) cst = j; dfs(cst, 0, i); bool ok = 1; for (int j = 1; j <= n; j++) { if (i & (1 << c[j])) ok &= f[j]; } if (ok) ans = min(ans, __builtin_popcount(i) - 1); } printf("%d", ans); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 344 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 440 KB | Output is correct |
4 | Correct | 0 ms | 344 KB | Output is correct |
5 | Correct | 0 ms | 344 KB | Output is correct |
6 | Correct | 0 ms | 348 KB | Output is correct |
7 | Correct | 0 ms | 348 KB | Output is correct |
8 | Correct | 0 ms | 348 KB | Output is correct |
9 | Correct | 1 ms | 604 KB | Output is correct |
10 | Correct | 0 ms | 348 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 344 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 440 KB | Output is correct |
4 | Correct | 0 ms | 344 KB | Output is correct |
5 | Correct | 0 ms | 344 KB | Output is correct |
6 | Correct | 0 ms | 348 KB | Output is correct |
7 | Correct | 0 ms | 348 KB | Output is correct |
8 | Correct | 0 ms | 348 KB | Output is correct |
9 | Correct | 1 ms | 604 KB | Output is correct |
10 | Correct | 0 ms | 348 KB | Output is correct |
11 | Execution timed out | 3070 ms | 348 KB | Time limit exceeded |
12 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 72 ms | 12568 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 344 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 440 KB | Output is correct |
4 | Correct | 0 ms | 344 KB | Output is correct |
5 | Correct | 0 ms | 344 KB | Output is correct |
6 | Correct | 0 ms | 348 KB | Output is correct |
7 | Correct | 0 ms | 348 KB | Output is correct |
8 | Correct | 0 ms | 348 KB | Output is correct |
9 | Correct | 1 ms | 604 KB | Output is correct |
10 | Correct | 0 ms | 348 KB | Output is correct |
11 | Execution timed out | 3070 ms | 348 KB | Time limit exceeded |
12 | Halted | 0 ms | 0 KB | - |