QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#334549#1368. Kth SubtreesteventanTL 501ms196748kbC++141.2kb2024-02-22 04:22:432024-02-22 04:22:44

Judging History

你现在查看的是最新测评结果

  • [2024-02-22 04:22:44]
  • 评测
  • 测评结果:TL
  • 用时:501ms
  • 内存:196748kb
  • [2024-02-22 04:22:43]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

const int MAXN = 5005;
vector<int> tree[MAXN];
int sizes[MAXN];
long long dp[MAXN][MAXN] = {{0}};

void dfs(int cur, int prev) {
    sizes[cur] = 1;
    dp[cur][1] = 1;
    for (int nei : tree[cur]) {
        if (nei != prev) {
            dfs(nei, cur);
            sizes[cur] += sizes[nei];
            for (int i = sizes[cur]; i >= 2; i--) {
                for (int j = 1; j < i; j++) {
                    dp[cur][i] += dp[cur][i - j] * dp[nei][j];
                }
            }
        }
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n;
    long long K;
    cin >> n >> K;
    for (int i = 0; i < n - 1; i++) {
        int u, v;
        cin >> u >> v;
        u--; v--;
        tree[u].push_back(v);
        tree[v].push_back(u);
    }

    dfs(0, -1);
    long long count[n + 1];
    long long psum = 0;
    int res = -1;
    for (int i = 1; i <= n; i++) {
        count[i] = 0;
        for (int j = 0; j < n; j++) {
            count[i] += dp[j][i];
        }
        psum += count[i];
        if (psum >= K) {
            res = i;
            break;
        }
    }
    cout << res << endl;
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 6012kb

input:

100 116588
43 57
39 96
22 83
42 93
45 34
43 78
38 40
3 73
63 100
57 13
96 41
64 6
19 91
98 81
91 45
100 38
12 50
19 82
43 56
63 93
75 34
62 76
60 46
18 79
11 55
16 7
59 69
38 4
23 60
45 54
11 3
43 87
85 69
83 16
16 53
85 32
45 52
57 88
2 63
53 92
51 27
29 37
41 62
73 90
62 100
43 90
13 50
56 23
91 5...

output:

11

result:

ok single line: '11'

Test #2:

score: 0
Accepted
time: 0ms
memory: 7976kb

input:

100 116589
43 57
39 96
22 83
42 93
45 34
43 78
38 40
3 73
63 100
57 13
96 41
64 6
19 91
98 81
91 45
100 38
12 50
19 82
43 56
63 93
75 34
62 76
60 46
18 79
11 55
16 7
59 69
38 4
23 60
45 54
11 3
43 87
85 69
83 16
16 53
85 32
45 52
57 88
2 63
53 92
51 27
29 37
41 62
73 90
62 100
43 90
13 50
56 23
91 5...

output:

12

result:

ok single line: '12'

Test #3:

score: 0
Accepted
time: 1ms
memory: 7976kb

input:

100 117057262442603580
43 57
39 96
22 83
42 93
45 34
43 78
38 40
3 73
63 100
57 13
96 41
64 6
19 91
98 81
91 45
100 38
12 50
19 82
43 56
63 93
75 34
62 76
60 46
18 79
11 55
16 7
59 69
38 4
23 60
45 54
11 3
43 87
85 69
83 16
16 53
85 32
45 52
57 88
2 63
53 92
51 27
29 37
41 62
73 90
62 100
43 90
13 5...

output:

97

result:

ok single line: '97'

Test #4:

score: 0
Accepted
time: 1ms
memory: 7964kb

input:

100 117057262442603581
43 57
39 96
22 83
42 93
45 34
43 78
38 40
3 73
63 100
57 13
96 41
64 6
19 91
98 81
91 45
100 38
12 50
19 82
43 56
63 93
75 34
62 76
60 46
18 79
11 55
16 7
59 69
38 4
23 60
45 54
11 3
43 87
85 69
83 16
16 53
85 32
45 52
57 88
2 63
53 92
51 27
29 37
41 62
73 90
62 100
43 90
13 5...

output:

98

result:

ok single line: '98'

Test #5:

score: 0
Accepted
time: 490ms
memory: 81804kb

input:

2000 88224773283133500
787 496
787 1699
787 1642
787 1695
787 768
787 1830
787 1570
787 1445
787 1477
787 1455
787 1483
787 1011
787 1240
787 149
787 508
787 744
787 859
787 371
787 126
787 916
787 1906
787 1208
787 953
787 117
787 1294
787 1071
787 812
787 1327
787 837
787 1949
787 438
787 139
787 ...

output:

7

result:

ok single line: '7'

Test #6:

score: 0
Accepted
time: 487ms
memory: 81688kb

input:

2000 88224773283133501
787 496
787 1699
787 1642
787 1695
787 768
787 1830
787 1570
787 1445
787 1477
787 1455
787 1483
787 1011
787 1240
787 149
787 508
787 744
787 859
787 371
787 126
787 916
787 1906
787 1208
787 953
787 117
787 1294
787 1071
787 812
787 1327
787 837
787 1949
787 438
787 139
787 ...

output:

8

result:

ok single line: '8'

Test #7:

score: 0
Accepted
time: 495ms
memory: 81812kb

input:

2000 1000000000000000000
787 496
787 1699
787 1642
787 1695
787 768
787 1830
787 1570
787 1445
787 1477
787 1455
787 1483
787 1011
787 1240
787 149
787 508
787 744
787 859
787 371
787 126
787 916
787 1906
787 1208
787 953
787 117
787 1294
787 1071
787 812
787 1327
787 837
787 1949
787 438
787 139
78...

output:

8

result:

ok single line: '8'

Test #8:

score: 0
Accepted
time: 496ms
memory: 82488kb

input:

2000 1020301
540 541
927 926
799 798
1517 1516
381 382
220 219
1038 1039
1106 1105
1681 1682
666 667
1221 1222
1530 1529
146 145
845 844
677 676
1381 1380
1126 1127
718 717
516 517
1018 1019
1120 1121
1332 1333
1280 1281
440 439
1261 1260
618 619
100 101
1371 1370
25 26
526 525
835 834
1495 1496
182...

output:

601

result:

ok single line: '601'

Test #9:

score: 0
Accepted
time: 495ms
memory: 82404kb

input:

2000 877413
642 641
1728 1727
1038 1037
1534 1535
1130 1131
1834 1835
1795 1796
1890 1891
656 657
1423 1422
1730 1731
433 434
169 170
8 7
307 306
1581 1582
1169 1170
1763 1762
1831 1832
1929 1928
248 247
941 942
1434 1435
846 845
1376 1377
166 167
426 425
1274 1273
285 284
1142 1141
792 793
1365 136...

output:

502

result:

ok single line: '502'

Test #10:

score: 0
Accepted
time: 501ms
memory: 82648kb

input:

2000 2001000
1774 1775
851 852
1263 1262
77 78
1122 1123
1511 1512
203 204
365 364
1826 1825
520 519
1891 1890
1851 1850
1561 1562
1479 1478
1589 1588
1571 1570
1803 1804
1323 1322
142 141
544 545
1002 1003
1590 1589
1152 1153
1664 1665
836 837
1754 1755
1869 1868
492 493
1069 1070
105 104
381 380
5...

output:

2000

result:

ok single line: '2000'

Test #11:

score: 0
Accepted
time: 500ms
memory: 82088kb

input:

2000 1991000
1750 1749
1705 1706
1022 1023
1096 1097
844 843
1897 1896
196 197
28 29
1757 1756
1271 1272
1590 1591
1119 1120
1158 1159
714 715
1773 1772
797 796
1846 1845
1486 1487
476 477
1059 1060
1777 1778
653 654
526 527
1960 1961
1866 1865
1680 1681
1890 1891
1930 1931
1585 1586
1670 1669
165 1...

output:

1860

result:

ok single line: '1860'

Test #12:

score: 0
Accepted
time: 282ms
memory: 196748kb

input:

5000 760029199216401830
252 3746
866 3746
4429 3746
904 866
1813 4429
3518 904
4170 252
4469 3746
2099 1813
1889 4170
3439 1813
2432 252
3090 1813
4965 3518
4135 866
516 3090
210 2099
1731 1889
1879 3746
2325 4170
221 866
527 3090
2493 516
1104 1889
2867 210
4299 4135
4923 4299
4358 210
1744 2432
20...

output:

21

result:

ok single line: '21'

Test #13:

score: -100
Time Limit Exceeded

input:

5000 355204
3709 366
366 1694
1694 1110
1110 3742
3742 4979
4979 3908
3908 3578
3578 454
454 2040
2040 208
208 4449
4449 950
950 1153
1153 1781
1781 32
32 3282
3282 1685
1685 2631
2631 798
798 3326
3326 1776
1776 197
197 2780
2780 945
945 1507
1507 831
831 2759
2759 2544
2544 4136
4136 2703
2703 383...

output:


result: