QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#397198#8584. 바이러스thangthang#0 2ms4816kbC++207.1kb2024-04-23 19:31:032024-07-04 03:36:58

Judging History

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

  • [2024-07-04 03:36:58]
  • 评测
  • 测评结果:0
  • 用时:2ms
  • 内存:4816kb
  • [2024-04-23 19:31:03]
  • 提交

answer

// author : HuuHung
// 25.3.2024


#include <bits/stdc++.h>
#define ii pair <int, int>
#define F first
#define S second
#define ll long long
#define lli pair <ll, int>
#define lb long double
#define pb push_back
#define vi vector <int>
#define vll vector <ll>
#define Bit(x, i) ((x) >> (i) & 1)
#define Mask(i) (1ll << (i))
#define All(v) (v).begin(), (v).end()

using namespace std;

void maxzi(auto &a, auto b){
    a = max(a, b);
}

void minzi(auto &a, auto b){
    a = min(a, b);
}

const int N = 1e5 + 5;
const int mod = 1e9 + 7;
const int LG = 20;

void add(auto &a, auto b){
    a += b;
    if (a >= mod) a -= mod;
    if (a < 0) a += mod;
}

auto Pow(auto a, auto b){
    if (b == 0) return 1;
    if (b % 2) return 1ll * a * Pow(a, b - 1) % mod;
    auto c = Pow(a, b / 2);
    return 1ll * c * c % mod;
}

// * end

struct LCA{
    vi st, ed, _lg, high;
    vector <vi> euler, adj;
    int cnt;

    void dfs(int u, int pa){
        ++ cnt;
        st[u] = cnt;
        euler[cnt].pb(u);
        for (int v : adj[u]){
            if (v == pa) continue;
            high[v] = high[u] + 1;
            dfs(v, u);
            euler[++ cnt].pb(u);
        }
        ed[u] = cnt;
    }

    int check(int u, int v) {
        return st[u] <= st[v] && ed[v] <= ed[u];
    }

    int min_by_time(int u, int v) {
        return (st[u] < st[v] ? u : v);
    }

    void add(int u, int v){
        adj[u].pb(v);
        adj[v].pb(u);
    }

    void resize(int n){
        st.resize(n + 3, 0);
        ed.resize(n + 3, 0);
        euler.resize(2 * n + 5);
        adj.resize(n + 3);
        _lg.resize(2 * n + 5);
        high.resize(n + 3, 1);
        for (int i = 0; i <= 2 * n; ++ i) _lg[i] = log2(i);
    }

    void init(int r){
        cnt = 0;
        dfs(r, 0);
        for (int lg = 1; lg < 20; ++lg) {
            for (int i = 1; i + (1 << lg) - 1 <= cnt; ++i)
                euler[i].pb(min_by_time(euler[i][lg - 1], euler[i + (1 << lg - 1)][lg - 1]));
        }
    }

    int get(int u, int v) {
        int L = min(st[u], st[v]);
        int R = max(ed[u], ed[v]);
        int lg = _lg[R - L + 1];
        return min_by_time(euler[L][lg], euler[R - (1 << lg) + 1][lg]);
    }

    int dist(int u, int v){
        int lc = get(u, v);
        return high[u] + high[v] - 2 * high[lc];
    }
} tree;

struct centroid{
    vi sz, used, par, maxdist;
    vector <vi> adj, cur, dhs;

    void resize(int n){
        sz.resize(n + 3, 0);
        used.resize(n + 3, 0);
        adj.resize(n + 3);
        cur.resize(n + 3);
        par.resize(n + 3, -1);
        maxdist.resize(n + 3, 0);
        dhs.resize(n + 3);
    }

    void add(int u, int v){
        adj[u].pb(v);
        adj[v].pb(u);
    }

    int dfs(int u, int p = -1){
        sz[u] = 1;
        for (int v : adj[u]){
            if (v == p || used[v]) continue;
            sz[u] += dfs(v, u);
        }

        return sz[u];
    }

    int get_cen(int m, int u, int p = -1){
        for (int v : adj[u]){
            if (v != p && !used[v] && 2 * sz[v] > m)
                return get_cen(m, v, u);
        }

        return u;
    }

    int ro = -1;

    int cen(int u){
        u = get_cen(dfs(u), u);
        if (ro < 0) ro = u;
        used[u] = 1;
        for (int v : adj[u]){
            if (!used[v]) cur[u].pb(cen(v));
        }
        return u;
    }

    map <ii, int> mp;
    int tot = 0;
    vi ask;
    vector <ii> status;
    const int inf = 2e9;

    void build(int u, vi &C){
        dhs[u].pb(u);
        for (int v : cur[u]){
            if (v == par[u]) continue;
            //cerr << u << ' ' << v << endl;
            par[v] = u;
            build(v, C);
            for (int k : dhs[v]){
                dhs[u].pb(k);
                maxzi(maxdist[u], tree.dist(u, k));
            }
        }
        for (int i = 0; i <= maxdist[u]; ++ i){
            mp[ii(u, i)] = tot;
            ++ tot;
            status.pb(ii(u, i));
            if (i > 0) ask.pb(1);
            else ask.pb(0);
        }
    }
} ce;

struct Dij{
    vector <vector <ii>> adj;
    vll dist;
    const ll inf = 1e18;
    int n;

    Dij(int _n){
        n = _n;
        adj.resize(n + 3);
        dist.resize(n + 3, inf);
    }

    void add(int u, int v, int w){
        adj[u].pb(ii(v, w));
//        //if (u < v) swap(u, v);
//        if (u >= ce.tot) cout << u - ce.tot << ' ' << -1 << ' ';
//        else cout << ce.status[u].F << ' ' << ce.status[u].S << ' ';
//        if (v >= ce.tot) cout << v - ce.tot << ' ' << -1 << ' ';
//        else cout << ce.status[v].F << ' ' << ce.status[v].S << ' ';
//        cout << w << endl;
//        //adj[v].pb(ii(u, w));
    }

    priority_queue <lli> qu;

    void process(){
        while (!qu.empty()){
            auto [du, u] = qu.top();
            du = -du;
            qu.pop();
            if (du != dist[u]) continue;
            for (auto [v, dv] : adj[u]){
                if (dist[v] > du + dv){
                    dist[v] = du + dv;
                    qu.push(lli(-dist[v], v));
                }
            }
        }
    }

    void build(vi &P, vi &D, vi &C){
        //cout << ce.tot << ' ' << endl;
        for (int i = 0; i < ce.tot; ++ i){
            if (ce.ask[i]) {
                add(i, i - 1, 0);
                add(i - 1 + ce.tot, i + ce.tot, 0);
            }
        }
        for (int u = 0; u < C.size(); ++ u){
            for (int k : ce.dhs[u]){
                int dep = tree.dist(u, k);
                int d = ce.mp[ii(u, dep)];
                add(d, k + 2 * ce.tot, 0);
                add(k + 2 * ce.tot, d + ce.tot, C[k]);
            }
        }
        for (int i = 0; i < P.size(); ++ i){
            int u = P[i];
            while (u > -1){
                int re = min(ce.maxdist[u], D[i] - tree.dist(u, P[i]));
                if (re >= 0){
                    int d = ce.mp[ii(u, re)];
                    add(i + 2 * ce.tot + C.size(), d, 0);
                    add(d + ce.tot, i + 2 * ce.tot + C.size(), 0);
                }
                u = ce.par[u];
            }
        }

        dist[2 * ce.tot + C.size()] = 0;
        qu.push(lli(0, 2 * ce.tot + C.size()));
        process();
    }
};

vll find_spread(int N, int M, vi A, vi B, vi P, vi D, vi C){
    tree.resize(N);
    ce.resize(N);
    for (int i = 0; i < N - 1; ++ i){
        tree.add(A[i], B[i]);
        ce.add(A[i], B[i]);
    }
    tree.init(0);
    ce.cen(0);
    ce.build(ce.ro, C);
    Dij ac(2 * ce.tot + M + N);
    ac.build(P, D, C);
    vll ans;
    for (int i = 0; i < M; ++ i) ans.pb(0);
    for (int i = 0; i < M; ++ i) ans[i] = ac.dist[2 * ce.tot + i + N];
    return ans;
}

//void solve(){
//    for (ll k : find_spread(8, 5, {0, 1, 2, 3, 4, 3, 3}, {1, 2, 3, 4, 5, 6, 7}, {2, 5, 7, 1, 4}, {2, 0, 0, 1, 1}, {40, 5, 5, 16, 32, 8, 1, 10}))
//        cout << k << ' ';
//}
//
//
//int main(){
//    ios_base::sync_with_stdio(0);
//    cin.tie(0);
//    cout.tie(0);
//    int t = 1;
//    while (t --) solve();
//
//    return 0;
//}






Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

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

input:

8 5
0 1
1 2
2 3
3 4
4 5
5 6
6 7
2 2
5 0
7 0
1 1
4 1
40 5 5 16 32 8 1 10

output:

0
24
1000000000000000000
5
16

result:

wrong answer 3rd lines differ - expected: '-1', found: '1000000000000000000'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 0
Wrong Answer

Test #34:

score: 5
Accepted
time: 0ms
memory: 3836kb

input:

8 5
0 1
1 2
2 3
3 4
4 5
3 6
3 7
2 2
5 0
7 0
1 1
4 1
40 5 5 16 32 8 1 10

output:

0
24
10
5
16

result:

ok 5 lines

Test #35:

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

input:

10 10
9 3
0 6
1 8
5 1
3 2
8 7
0 4
6 5
0 9
9 0
7 2
1 0
8 1
6 3
1 2
4 6
7 2
5 1
5 4
10 12 5 9 8 21 20 6 13 5

output:

0
11
17
11
5
11
5
11
17
5

result:

ok 10 lines

Test #36:

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

input:

20 20
16 11
13 10
17 6
13 18
13 16
13 0
2 5
14 7
5 17
15 1
18 19
7 15
6 4
13 2
1 8
0 14
13 12
13 9
9 3
10 9
5 16
8 18
0 19
17 16
7 11
2 7
15 13
18 18
19 11
2 18
16 7
11 17
16 19
14 15
5 15
13 19
5 8
7 15
17 15
201842345 959136634 799276472 790823713 190419998 931723392 553266463 967187391 208167145 ...

output:

0
134949910
134949910
134949910
134949910
134949910
134949910
134949910
134949910
134949910
134949910
134949910
134949910
134949910
134949910
134949910
134949910
134949910
134949910
134949910

result:

ok 20 lines

Test #37:

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

input:

20 20
11 17
13 8
6 4
18 13
15 12
5 15
16 7
8 10
3 18
16 3
16 19
16 1
2 9
1 11
14 2
0 14
10 5
16 0
17 6
0 1
17 5
1 14
16 6
1 5
4 3
4 4
18 4
12 8
7 8
0 12
3 12
4 13
11 5
2 0
10 9
18 1
18 17
15 19
11 4
392505795 598245226 676917494 520541066 400541959 961423871 653272803 503778194 808079532 53571674 86...

output:

0
392505795
392505795
392505795
392505795
793047754
793047754
392505795
395420842
392505795
392505795
392505795
392505795
392505795
1069423289
392505795
395420842
392505795
392505795
392505795

result:

ok 20 lines

Test #38:

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

input:

20 20
1 13
3 12
0 8
2 4
8 5
10 17
10 0
10 11
13 16
19 9
6 18
10 14
10 2
7 1
5 6
4 15
11 3
9 7
10 19
4 4
7 2
1 0
9 1
3 1
10 15
18 0
6 3
19 8
15 0
16 5
15 5
4 10
0 0
14 1
9 10
17 11
17 0
12 4
13 6
32588836 700122468 935315183 460144664 72259535 979008218 991710456 656707652 436761227 637241986 4232798...

output:

0
362671255
732711304
537602043
176293815
32588836
516986682
32588836
32588836
149603530
362671255
32588836
32588836
32588836
219213726
32588836
32588836
378798728
32588836
32588836

result:

ok 20 lines

Test #39:

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

input:

20 20
17 7
12 3
15 0
17 6
7 12
10 16
2 15
17 1
17 4
14 19
17 5
0 9
17 2
18 14
4 10
19 13
9 18
3 11
11 8
3 19
13 19
4 19
6 19
4 19
9 19
2 19
15 19
3 19
15 19
13 19
9 19
4 19
11 19
10 19
3 19
12 19
17 19
7 19
15 19
601569352 457345748 950690477 940932136 419713541 265386030 296609107 328433361 2843618...

output:

0
71625849
71625849
71625849
71625849
71625849
71625849
71625849
71625849
71625849
71625849
71625849
71625849
71625849
71625849
71625849
71625849
71625849
71625849
71625849

result:

ok 20 lines

Test #40:

score: 0
Accepted
time: 2ms
memory: 4804kb

input:

500 500
61 206
219 174
496 451
386 483
285 100
385 54
98 441
455 305
40 443
496 139
88 374
462 27
426 92
259 245
155 262
205 223
29 190
496 33
54 120
93 182
167 350
23 211
147 429
463 41
372 354
31 465
461 258
117 433
149 21
27 322
240 387
498 202
261 279
233 315
485 68
389 390
256 82
91 405
350 370...

output:

0
770946
770946
770946
770946
770946
770946
770946
770946
770946
770946
770946
770946
770946
770946
770946
770946
770946
770946
770946
770946
770946
770946
770946
770946
770946
770946
770946
770946
770946
770946
770946
770946
770946
770946
770946
770946
770946
770946
770946
770946
770946
770946
7709...

result:

ok 500 lines

Test #41:

score: 0
Accepted
time: 2ms
memory: 4568kb

input:

500 500
411 418
150 393
315 115
204 312
270 177
232 356
167 235
314 443
125 65
169 456
102 483
269 55
317 62
124 132
173 271
150 22
257 198
331 71
26 361
171 476
182 289
149 11
460 208
287 134
116 43
135 376
148 408
324 167
295 118
300 50
150 368
422 185
400 475
375 409
428 390
377 294
290 218
256 1...

output:

0
6449391
6449391
6449391
6449391
6449391
6449391
6449391
6449391
6449391
6449391
6449391
6449391
6449391
6449391
6449391
6449391
6449391
6449391
6449391
6449391
6449391
6449391
6449391
6449391
6449391
6449391
6449391
6449391
6449391
6449391
6449391
6449391
6449391
6449391
6449391
6449391
6449391
64...

result:

ok 500 lines

Test #42:

score: 0
Accepted
time: 2ms
memory: 4596kb

input:

500 500
191 230
92 212
99 452
123 269
259 301
156 121
195 231
429 5
240 327
243 66
402 436
460 55
9 16
251 290
417 156
334 245
112 406
162 186
371 294
108 275
18 119
397 235
50 333
25 278
254 300
456 185
433 49
172 495
94 334
147 240
398 441
498 268
306 135
35 448
25 18
327 391
95 372
421 232
42 386...

output:

0
3197154
3197154
3197154
3197154
14362633
3197154
3197154
3197154
3197154
3197154
3197154
3197154
3197154
3197154
3197154
3197154
3197154
3197154
3197154
3197154
3197154
3197154
3197154
3197154
3197154
3197154
3197154
65618143
3197154
3197154
3197154
3197154
3197154
3197154
43588673
3197154
3197154...

result:

ok 500 lines

Test #43:

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

input:

500 500
372 50
64 368
71 283
194 472
261 189
129 131
87 243
332 46
191 163
136 458
36 220
161 313
6 490
331 359
391 214
48 422
337 144
397 40
475 425
416 333
51 437
343 318
66 56
49 5
241 402
231 252
83 486
53 411
347 388
468 241
353 124
275 168
486 377
137 108
278 137
28 286
181 416
443 48
366 371
...

output:

0
1401277
1401277
1401277
1401277
1401277
1401277
1401277
1401277
1401277
1401277
1401277
1401277
1401277
1401277
1401277
1401277
1401277
1401277
1401277
1401277
1401277
1401277
1401277
1401277
1401277
244238527
1401277
1401277
1401277
1401277
1401277
1401277
1401277
1401277
1401277
1401277
1401277
...

result:

ok 500 lines

Test #44:

score: 0
Accepted
time: 2ms
memory: 4532kb

input:

500 500
243 313
464 344
352 116
215 310
460 330
181 193
85 95
373 382
185 91
227 62
70 138
342 103
284 101
143 445
88 163
339 139
69 472
262 247
188 267
429 73
129 422
225 25
275 389
276 364
166 184
293 148
417 23
332 90
219 76
120 48
101 199
137 100
55 72
207 214
365 370
83 4
204 18
342 146
216 357...

output:

0
2185120
2185120
97049678
16788183
705908158
2185120
2185120
42725473
2185120
2185120
2185120
97049678
108699201
2185120
2185120
2185120
362023472
2185120
2185120
2185120
2185120
2185120
11181490
32623158
2185120
2185120
2185120
2185120
21435748
2185120
2185120
2185120
7221891
2185120
21435748
2185...

result:

ok 500 lines

Test #45:

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

input:

500 500
350 403
403 289
88 400
310 62
150 122
454 111
244 358
76 307
124 285
10 266
184 75
126 421
439 127
265 409
400 70
79 86
232 367
138 345
404 207
249 313
140 188
228 333
492 203
490 452
186 461
246 492
173 28
364 23
497 154
204 316
269 429
329 198
319 306
281 430
71 448
123 14
334 155
385 123
...

output:

0
1623578
1623578
1623578
1623578
1623578
1623578
1623578
1623578
1623578
58121494
1623578
1623578
1623578
1623578
1623578
1623578
1623578
1623578
12712309
1623578
45586847
1623578
1623578
12712309
1623578
1623578
55828524
1623578
5437637
1623578
1623578
1623578
1623578
1623578
1623578
1623578
16235...

result:

ok 500 lines

Test #46:

score: 0
Accepted
time: 2ms
memory: 4544kb

input:

500 500
204 252
121 383
17 289
23 184
185 53
140 235
153 172
180 276
149 360
165 275
155 210
108 19
410 29
366 78
113 217
245 477
421 30
262 69
313 13
157 84
445 324
197 491
14 299
317 463
448 395
346 147
285 270
187 415
269 273
296 264
317 16
317 72
273 308
62 340
317 167
399 468
65 334
15 363
217 ...

output:

0
320391
320391
320391
320391
320391
320391
320391
320391
320391
320391
320391
320391
320391
320391
320391
320391
320391
320391
320391
320391
320391
320391
320391
320391
320391
320391
320391
320391
320391
320391
320391
320391
320391
320391
320391
320391
320391
320391
320391
320391
320391
320391
3203...

result:

ok 500 lines

Test #47:

score: 0
Accepted
time: 2ms
memory: 4608kb

input:

500 500
80 439
397 302
494 6
286 440
87 284
162 134
165 458
435 457
205 298
433 242
37 247
196 308
280 105
136 61
118 49
284 53
495 487
63 337
409 18
225 234
55 141
459 128
480 148
203 496
246 245
266 174
398 367
91 116
367 37
103 296
237 222
271 90
476 82
135 195
306 107
342 232
216 449
231 366
456...

output:

0
626982
626982
626982
626982
626982
626982
626982
626982
626982
626982
626982
626982
626982
626982
626982
626982
626982
626982
626982
626982
626982
626982
626982
626982
626982
626982
626982
626982
626982
626982
626982
626982
626982
626982
626982
626982
626982
626982
626982
626982
626982
626982
6269...

result:

ok 500 lines

Test #48:

score: -5
Wrong Answer
time: 2ms
memory: 4436kb

input:

500 500
151 54
116 9
420 190
389 13
463 185
492 41
153 275
58 401
348 418
308 236
286 264
273 279
405 439
434 409
310 455
227 443
65 472
136 22
314 226
425 463
436 177
122 304
53 183
97 386
123 235
288 193
379 14
154 435
168 58
186 442
67 87
270 464
278 436
264 239
459 194
330 107
238 36
391 295
327...

output:

0
1000000000000000000
1000000000000000000
1000000000000000000
1000000000000000000
1000000000000000000
1000000000000000000
1000000000000000000
1000000000000000000
1000000000000000000
1000000000000000000
1000000000000000000
1000000000000000000
1000000000000000000
1000000000000000000
100000000000000000...

result:

wrong answer 2nd lines differ - expected: '-1', found: '1000000000000000000'

Subtask #5:

score: 0
Skipped

Dependency #4:

0%

Subtask #6:

score: 0
Skipped

Dependency #1:

0%