QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#504877#6757. 深搜hirayuu_qoj36 19ms4344kbC++172.0kb2024-08-04 16:53:462024-08-04 16:53:46

Judging History

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

  • [2024-08-04 16:53:46]
  • 评测
  • 测评结果:36
  • 用时:19ms
  • 内存:4344kb
  • [2024-08-04 16:53:46]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rng(i,l,r) for(int i=(l); i<(r); i++)
#define all(x) x.begin(),x.end()
using ll=long long;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    const ll MOD=1000000007;
    int c;
    cin>>c;
    if(c<=9) {
        int n,m,k;
        cin>>n>>m>>k;
        vector<vector<ll>> tree(n,vector<ll>(n,n));
        rep(i,n) {
            tree[i][i]=0;
        }
        rep(i,n-1) {
            int u,v;
            cin>>u>>v;
            u--;v--;
            tree[u][v]=1;
            tree[v][u]=1;
        }
        rep(k,n) {
            rep(i,n) {
                rep(j,n) {
                    tree[i][j]=min(tree[i][j],tree[i][k]+tree[k][j]);
                }
            }
        }
        vector<pair<int,int>> nt;
        rep(i,m) {
            int a,b;
            cin>>a>>b;
            a--;b--;
            nt.emplace_back(a,b);
        }
        vector<int> s(k);
        rep(i,k) {
            cin>>s[i];
            s[i]--;
        }
        vector<vector<int>> ok(k,vector<int>(m,0));
        rep(i,k) {
            rep(j,m) {
                int a,b;
                tie(a,b)=nt[j];
                if(abs(tree[s[i]][a]-tree[s[i]][b])==tree[a][b]) {
                    ok[i][j]=1;
                }
            }
        }
        vector<ll> pow={1};
        rep(i,m)pow.emplace_back((pow.back()*2)%MOD);
        ll ans=0;
        rng(i,1,1<<k) {
            vector<int> nok(m,1);
            ll sign=-1;
            rep(j,k) {
                if((i>>j)&1) {
                    sign*=-1;
                    rep(p,m) {
                        if(ok[j][p]==0)nok[p]=0;
                    }
                }
            }
            int sum=0;
            rep(j,m)sum+=nok[j];
            ans+=sign*pow[sum];
            ans%=MOD;
        }
        ans+=MOD;
        ans%=MOD;
        cout<<ans<<"\n";
    }
}

详细


Pretests


Final Tests

Test #1:

score: 4
Accepted
time: 0ms
memory: 3544kb

input:

1
6 6 5
5 1
2 5
6 5
3 2
6 4
1 4
1 6
4 3
4 2
6 3
2 6
5 2 6 1 3

output:

22

result:

ok 1 number(s): "22"

Test #2:

score: 4
Accepted
time: 0ms
memory: 3528kb

input:

2
6 6 6
3 1
5 3
3 2
5 4
2 6
4 6
4 2
1 4
6 1
1 2
3 4
3 4 6 2 1 5

output:

46

result:

ok 1 number(s): "46"

Test #3:

score: 4
Accepted
time: 0ms
memory: 3612kb

input:

3
6 6 6
1 2
4 1
4 6
4 5
3 5
3 6
6 2
2 3
6 5
2 5
4 2
4 6 3 2 5 1

output:

46

result:

ok 1 number(s): "46"

Test #4:

score: 4
Accepted
time: 0ms
memory: 3528kb

input:

4
15 15 6
6 1
7 1
6 11
14 7
8 11
4 8
8 10
10 12
5 10
2 12
3 8
9 11
15 5
13 2
9 4
3 14
11 12
4 14
11 4
3 5
4 5
14 5
11 5
3 10
10 4
14 10
10 6
8 15
15 10
7 4 14 10 5 8

output:

1384

result:

ok 1 number(s): "1384"

Test #5:

score: 4
Accepted
time: 0ms
memory: 3488kb

input:

5
15 15 6
11 1
9 11
1 15
7 11
15 2
6 2
4 2
8 4
4 5
14 8
1 10
7 12
6 3
10 13
14 10
5 7
5 13
3 9
13 6
6 5
4 9
4 10
15 7
15 13
12 1
11 8
10 11
11 5
6 11
13 5 3 1 4 11

output:

744

result:

ok 1 number(s): "744"

Test #6:

score: 4
Accepted
time: 0ms
memory: 3528kb

input:

6
15 15 6
9 1
7 9
6 1
7 3
6 8
8 12
4 12
12 5
10 5
10 15
14 1
3 2
11 7
13 2
10 14
14 13
5 2
15 4
8 14
4 13
12 2
6 14
6 13
3 14
10 3
4 3
3 8
9 3
11 14
10 13 4 6 3 11

output:

1873

result:

ok 1 number(s): "1873"

Test #7:

score: 4
Accepted
time: 19ms
memory: 4344kb

input:

7
300 168 6
1 184
1 41
10 41
184 18
18 215
184 271
215 267
194 184
165 18
223 18
223 83
123 165
6 165
90 83
41 2
123 40
232 194
177 232
262 123
140 271
40 211
11 271
21 18
15 11
158 177
197 1
41 35
194 110
217 177
215 121
297 123
223 38
15 72
297 46
35 212
228 140
1 89
130 11
158 296
279 35
90 287
1...

output:

144500972

result:

ok 1 number(s): "144500972"

Test #8:

score: 4
Accepted
time: 19ms
memory: 4276kb

input:

8
300 161 6
1 67
67 273
273 213
67 232
213 32
213 111
215 232
137 32
11 232
16 137
20 137
285 273
1 284
110 11
46 285
156 67
46 263
213 250
146 213
263 78
39 110
270 67
175 110
175 170
216 1
111 281
175 209
118 110
112 39
115 285
250 205
237 111
124 284
46 197
187 281
156 60
236 111
1 103
211 156
26...

output:

484515026

result:

ok 1 number(s): "484515026"

Test #9:

score: 4
Accepted
time: 19ms
memory: 4252kb

input:

9
300 157 6
56 1
1 36
56 280
285 1
285 265
166 280
56 213
87 1
191 213
87 232
166 31
280 112
43 213
43 24
293 166
232 91
31 89
259 213
232 68
134 24
168 91
280 257
172 280
87 226
229 36
56 209
239 232
43 72
72 132
265 235
283 72
300 112
1 252
112 174
241 285
24 44
8 235
193 43
256 280
168 287
257 61...

output:

644455703

result:

ok 1 number(s): "644455703"

Test #10:

score: 0
Wrong Answer
time: 0ms
memory: 3824kb

input:

10
300 299 120
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 11
11 12
12 13
13 14
14 15
15 16
16 17
17 18
18 19
19 20
20 21
21 22
22 23
23 24
24 25
25 26
26 27
27 28
28 29
29 30
30 31
31 32
32 33
33 34
34 35
35 36
36 37
37 38
38 39
39 40
40 41
41 42
42 43
43 44
44 45
45 46
46 47
47 48
48 49
49 50
50 51
51...

output:


result:

wrong answer Answer contains longer sequence [length = 1], but output contains 0 elements

Test #11:

score: 0
Wrong Answer
time: 0ms
memory: 3756kb

input:

11
300 300 116
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 11
11 12
12 13
13 14
14 15
15 16
16 17
17 18
18 19
19 20
20 21
21 22
22 23
23 24
24 25
25 26
26 27
27 28
28 29
29 30
30 31
31 32
32 33
33 34
34 35
35 36
36 37
37 38
38 39
39 40
40 41
41 42
42 43
43 44
44 45
45 46
46 47
47 48
48 49
49 50
50 51
51...

output:


result:

wrong answer Answer contains longer sequence [length = 1], but output contains 0 elements

Test #12:

score: 0
Wrong Answer
time: 0ms
memory: 3560kb

input:

12
300 300 200
198 1
1 169
139 169
139 289
13 139
198 265
1 45
61 13
139 58
265 130
289 210
109 265
169 114
250 139
250 140
89 130
77 169
250 74
136 13
224 45
45 164
61 217
58 148
249 77
248 289
118 210
89 262
136 146
65 45
13 242
293 61
295 224
230 265
115 230
136 98
78 130
164 184
240 109
89 212
2...

output:


result:

wrong answer Answer contains longer sequence [length = 1], but output contains 0 elements

Test #13:

score: 0
Wrong Answer
time: 0ms
memory: 3536kb

input:

13
300 300 200
1 296
1 284
1 160
296 154
109 160
160 134
175 1
134 95
184 154
198 175
184 172
10 109
248 284
51 154
10 33
134 73
181 172
172 55
33 121
218 121
225 248
205 248
91 181
282 248
154 38
218 83
188 284
243 248
225 69
221 160
65 121
154 233
269 243
287 38
154 18
175 100
147 154
23 65
154 24...

output:


result:

wrong answer Answer contains longer sequence [length = 1], but output contains 0 elements

Test #14:

score: 0
Wrong Answer
time: 0ms
memory: 3536kb

input:

14
300 295 200
1 155
1 160
24 155
1 59
160 290
5 155
24 258
59 33
1 264
152 264
160 190
159 190
5 139
1 69
24 68
33 161
81 290
84 33
5 227
45 84
191 1
288 45
6 69
155 114
24 4
159 181
151 227
1 8
151 165
4 221
101 190
74 290
23 221
128 221
246 24
123 290
23 80
25 152
73 80
73 26
133 159
288 7
44 26
...

output:


result:

wrong answer Answer contains longer sequence [length = 1], but output contains 0 elements

Test #15:

score: 0
Wrong Answer
time: 0ms
memory: 3536kb

input:

15
300 299 200
1 272
1 205
238 272
170 205
272 32
32 192
243 170
59 192
170 97
205 169
86 59
252 32
4 32
40 252
50 86
289 169
59 122
289 128
3 1
32 258
289 229
289 145
3 48
97 84
41 40
35 258
238 127
48 179
129 127
9 145
50 295
243 27
177 127
292 295
170 95
295 43
218 170
55 169
278 35
81 50
155 128...

output:


result:

wrong answer Answer contains longer sequence [length = 1], but output contains 0 elements

Test #16:

score: 0
Wrong Answer
time: 0ms
memory: 3612kb

input:

16
300 293 200
1 176
1 230
122 176
3 230
3 110
64 1
110 69
219 176
64 279
152 122
69 170
3 269
152 155
132 122
76 155
246 155
235 230
5 269
123 69
42 3
147 155
267 269
148 122
116 219
148 59
85 69
176 194
24 42
220 64
235 238
54 64
97 76
116 25
122 75
116 297
176 272
258 76
10 1
231 3
262 170
76 251...

output:


result:

wrong answer Answer contains longer sequence [length = 1], but output contains 0 elements

Test #17:

score: 0
Wrong Answer
time: 0ms
memory: 3596kb

input:

17
200000 199883 97179
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 11
11 12
12 13
13 14
14 15
15 16
16 17
17 18
18 19
19 20
20 21
21 22
22 23
23 24
24 25
25 26
26 27
27 28
28 29
29 30
30 31
31 32
32 33
33 34
34 35
35 36
36 37
37 38
38 39
39 40
40 41
41 42
42 43
43 44
44 45
45 46
46 47
47 48
48 49
49 50
...

output:


result:

wrong answer Answer contains longer sequence [length = 1], but output contains 0 elements

Test #18:

score: 0
Wrong Answer
time: 0ms
memory: 3524kb

input:

18
200000 199876 97287
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
10 11
11 12
12 13
13 14
14 15
15 16
16 17
17 18
18 19
19 20
20 21
21 22
22 23
23 24
24 25
25 26
26 27
27 28
28 29
29 30
30 31
31 32
32 33
33 34
34 35
35 36
36 37
37 38
38 39
39 40
40 41
41 42
42 43
43 44
44 45
45 46
46 47
47 48
48 49
49 50
...

output:


result:

wrong answer Answer contains longer sequence [length = 1], but output contains 0 elements

Test #19:

score: 0
Wrong Answer
time: 0ms
memory: 3612kb

input:

19
200000 200000 133333
1 124760
44003 124760
37294 1
163294 1
124760 4221
1 118363
163294 130356
163294 26345
150233 124760
163294 71228
118363 185064
16012 4221
136324 4221
130356 159564
16012 82836
37294 117301
37294 113319
118985 118363
67201 130356
134497 44003
118985 184508
62789 4221
167242 1...

output:


result:

wrong answer Answer contains longer sequence [length = 1], but output contains 0 elements

Test #20:

score: 0
Wrong Answer
time: 0ms
memory: 3616kb

input:

20
200000 200000 133333
140575 1
1 186893
181732 140575
79385 140575
181732 9627
186089 181732
186893 149538
186893 55018
140575 13029
186089 97797
164282 149538
18033 181732
55018 137342
1 136416
140575 148531
97797 1750
9627 9882
181032 55018
34757 55018
72967 181032
137342 70468
85420 136416
1803...

output:


result:

wrong answer Answer contains longer sequence [length = 1], but output contains 0 elements

Test #21:

score: 0
Wrong Answer
time: 0ms
memory: 3556kb

input:

21
200000 200000 133333
1 101322
88622 101322
58269 101322
58269 180983
168242 101322
95381 1
193115 95381
190995 168242
101322 148011
62879 88622
101322 172145
120738 190995
15239 120738
80271 193115
168242 21478
125310 58269
193115 93056
172145 110789
13098 172145
148011 174687
173743 190995
85181...

output:


result:

wrong answer Answer contains longer sequence [length = 1], but output contains 0 elements

Test #22:

score: 0
Wrong Answer
time: 0ms
memory: 3536kb

input:

22
200000 199999 133333
150539 1
150539 74762
1 34140
1 195593
164815 1
32085 195593
156066 32085
21074 34140
162900 34140
70220 195593
6115 32085
155396 70220
73894 150539
22486 195593
195593 19530
6115 146034
21074 40513
61074 146034
146034 198896
120389 195593
34219 61074
113107 1
195593 86095
64...

output:


result:

wrong answer Answer contains longer sequence [length = 1], but output contains 0 elements

Test #23:

score: 0
Wrong Answer
time: 0ms
memory: 3532kb

input:

23
500000 499999 333333
1 199660
284063 1
156514 199660
346277 1
199660 147381
284063 314108
147381 497971
248228 1
207371 284063
314108 165529
156514 452115
218249 248228
140112 1
395841 452115
337568 156514
314108 125202
310327 218249
446894 140112
490601 1
165529 179615
323005 207371
179615 57231...

output:


result:

wrong answer Answer contains longer sequence [length = 1], but output contains 0 elements

Test #24:

score: 0
Wrong Answer
time: 0ms
memory: 3612kb

input:

24
500000 499998 333333
65074 1
65074 304288
1 335471
59340 335471
304288 81779
81779 254965
59340 491338
108358 81779
59340 313254
59340 490077
150085 108358
304288 231400
108450 491338
108358 58590
215265 254965
14203 108450
222338 81779
313254 347805
136496 215265
173386 1
490077 183586
108358 20...

output:


result:

wrong answer Answer contains longer sequence [length = 1], but output contains 0 elements

Test #25:

score: 0
Wrong Answer
time: 0ms
memory: 3532kb

input:

25
500000 499997 333333
1 359765
359765 132729
101821 132729
1 357109
101821 393660
393660 141211
204917 1
393660 160129
204917 59682
165524 160129
359765 184850
39288 1
97240 165524
77900 101821
39288 343784
402651 1
181637 77900
351195 393660
77900 303404
357109 478493
403484 101821
357109 458913
...

output:


result:

wrong answer Answer contains longer sequence [length = 1], but output contains 0 elements