QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#749124 | #5659. Watching Cowflix | _8_8_ | 20.833333 | 287ms | 6200kb | C++23 | 1.0kb | 2024-11-14 22:46:10 | 2024-11-14 22:46:10 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = (int)2e5 + 12, MOD = (int)1e9 + 7;
int n, dp[N][2];
bool ok[N];
vector<int> g[N];
void dfs(int v, int pr, int k) {
dp[v][1] = 1 + k;
dp[v][0] = 0;
for(int to:g[v]) {
if(to == pr) continue;
dfs(to, v, k);
dp[v][0] += min(dp[to][0], dp[to][1]);
dp[v][1] += min(dp[to][0], dp[to][1] - k);
}
if(ok[v]) {
dp[v][0] = (int)1e9;
}
}
void test() {
cin >> n;
for(int i = 1; i <= n; i++) {
char x;cin >> x;
if(x == '1') {
ok[i] = 1;
}
}
for(int i = 1; i <= n - 1; i++) {
int u, v;
cin >> u >> v;
g[u].push_back(v);
g[v].push_back(u);
}
for(int i = 1; i <= n; i++) {
dfs(1, 1, i);
cout << min(dp[1][0], dp[1][1]) << '\n';
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int t = 1;
// cin >> t;
while(t--)
test();
}
详细
Pretests
Final Tests
Test #1:
score: 4.16667
Accepted
time: 1ms
memory: 3648kb
input:
5 10001 1 2 2 3 3 4 4 5
output:
4 6 8 9 10
result:
ok 5 number(s): "4 6 8 9 10"
Test #2:
score: 4.16667
Accepted
time: 2ms
memory: 5688kb
input:
7 0001010 7 4 5 6 7 2 5 1 6 3 2 5
output:
4 6 8 9 10 11 12
result:
ok 7 numbers
Test #3:
score: 4.16667
Accepted
time: 264ms
memory: 6200kb
input:
5000 0100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000010000000...
output:
711 837 944 1040 1121 1192 1249 1303 1352 1398 1439 1479 1518 1557 1596 1634 1671 1707 1742 1775 1807 1839 1871 1902 1932 1961 1990 2018 2046 2073 2099 2125 2150 2174 2197 2220 2242 2264 2286 2308 2329 2349 2368 2386 2404 2422 2439 2456 2472 2487 2502 2516 2529 2541 2552 2563 2573 2583 2593 2603 261...
result:
ok 5000 numbers
Test #4:
score: 4.16667
Accepted
time: 287ms
memory: 6132kb
input:
5000 0100000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000...
output:
890 1226 1433 1547 1619 1676 1727 1775 1821 1865 1908 1950 1989 2027 2064 2100 2136 2171 2206 2240 2273 2305 2336 2366 2395 2424 2452 2479 2506 2532 2557 2581 2604 2626 2648 2670 2691 2711 2730 2749 2768 2786 2804 2821 2837 2853 2869 2884 2898 2911 2923 2934 2944 2953 2962 2971 2980 2988 2995 3001 3...
result:
ok 5000 numbers
Test #5:
score: 4.16667
Accepted
time: 275ms
memory: 6036kb
input:
5000 0100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000001000000000000000001000000000000000000000000000000000000000000000000...
output:
794 1025 1178 1284 1364 1422 1473 1517 1559 1600 1640 1679 1717 1754 1790 1826 1861 1895 1928 1960 1992 2024 2056 2088 2119 2150 2181 2211 2241 2270 2298 2325 2351 2376 2401 2425 2448 2471 2493 2515 2536 2556 2575 2594 2612 2629 2645 2660 2674 2688 2701 2713 2724 2734 2743 2751 2759 2766 2772 2777 2...
result:
ok 5000 numbers
Test #6:
score: 0
Time Limit Exceeded
input:
200000 01000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
output:
result:
Test #7:
score: 0
Time Limit Exceeded
input:
200000 01000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
output:
result:
Test #8:
score: 0
Time Limit Exceeded
input:
200000 01000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
output:
result:
Test #9:
score: 0
Time Limit Exceeded
input:
100000 01000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
output:
12231 13861 15163 16221 17072 17762 18344 18845 19259 19625 19946 20243 20518 20777 21022 21258 21485 21703 21913 22120 22319 22516 22709 22900 23088 23273 23455 23635 23814 23991 24166 24340 24513 24684 24855 25026 25196 25366 25535 25703 25871 26038 26204 26370 26535 26700 26865 27029 27192 27355 ...
result:
Test #10:
score: 0
Time Limit Exceeded
input:
100000 01000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
output:
result:
Test #11:
score: 0
Time Limit Exceeded
input:
100000 01000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
output:
result:
Test #12:
score: 0
Time Limit Exceeded
input:
100000 01000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
output:
12198 13815 15093 16151 17026 17738 18331 18839 19271 19665 20028 20361 20662 20950 21223 21483 21737 21983 22223 22456 22688 22915 23140 23363 23583 23800 24014 24227 24437 24645 24852 25059 25263 25467 25670 25872 26073 26273 26472 26671 26870 27069 27268 27466 27663 27860 28056 28251 28445 28639 ...
result:
Test #13:
score: 0
Time Limit Exceeded
input:
100000 01000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
output:
result:
Test #14:
score: 0
Time Limit Exceeded
input:
100000 01000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
output:
result:
Test #15:
score: 0
Time Limit Exceeded
input:
100000 01000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
output:
12121 13753 15063 16111 16951 17644 18220 18708 19131 19507 19849 20159 20449 20713 20959 21195 21425 21646 21862 22074 22282 22486 22685 22881 23075 23263 23448 23631 23814 23995 24174 24352 24529 24705 24881 25057 25232 25406 25579 25751 25922 26092 26262 26432 26601 26769 26937 27104 27271 27437 ...
result:
Test #16:
score: 0
Time Limit Exceeded
input:
100000 01000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
output:
result:
Test #17:
score: 0
Time Limit Exceeded
input:
100000 01000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
output:
result:
Test #18:
score: 0
Time Limit Exceeded
input:
100000 01000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
output:
12282 13869 15142 16212 17062 17756 18336 18825 19253 19627 19967 20273 20555 20813 21059 21296 21518 21730 21938 22145 22349 22548 22745 22938 23130 23318 23505 23690 23872 24053 24231 24407 24582 24757 24930 25102 25273 25443 25613 25783 25953 26122 26290 26457 26623 26788 26952 27116 27279 27441 ...
result:
Test #19:
score: 0
Time Limit Exceeded
input:
100000 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
output:
result:
Test #20:
score: 0
Time Limit Exceeded
input:
200000 01000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
output:
result:
Test #21:
score: 0
Time Limit Exceeded
input:
200000 01000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
output:
result:
Test #22:
score: 0
Time Limit Exceeded
input:
200000 01000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
output:
result:
Test #23:
score: 0
Time Limit Exceeded
input:
200000 01000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
output:
result:
Test #24:
score: 0
Time Limit Exceeded
input:
200000 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...