UOJ Logo

NOI.AC

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#202866#853. 加工零件one_zero_three_zero100390ms9300kbC++111.3kb2024-02-17 12:06:522024-02-17 12:06:54

answer

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

struct node{
    int idx,di,type;
    bool operator < (const node &a) const{
        return di > a.di;
    }
};

int n,m,q;
int u,v;
int dis[100005][2];
bool vis[100005][2];
vector<node> a[100005];

void Dijkstra(int st){
    dis[st][0] = 0;
    priority_queue<node> q;
    q.push({st,0,0});
    while(q.size()){
        node t = q.top();
        q.pop();
        if(vis[t.idx][t.type]) continue;
        vis[t.idx][t.type] = 1;
        for(auto && i : a[t.idx]){
            if(dis[t.idx][t.type] + i.di >= dis[i.idx][!t.type]) continue;
            dis[i.idx][!t.type] = dis[t.idx][t.type] + i.di;
            q.push({i.idx,dis[i.idx][!t.type],!t.type});
        }
    }
}

int main(){
#ifndef ONLINE_JUDGE
    freopen("../data.in","r",stdin);
    freopen("../data.out","w",stdout);
#endif
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);

    scanf("%d %d %d",&n,&m,&q);
    for(int i = 1;i <= n;i ++){
        dis[i][0] = dis[i][1] = 0x3f3f3f3f;
    }
    while(m --){
        scanf("%d %d",&u,&v);
        a[u].push_back({v,1,0});
        a[v].push_back({u,1,0});
    }
    Dijkstra(1);
    while(q --){
        scanf("%d %d",&u,&v);
        if(dis[u][v & 1] <= v) printf("Yes\n");
        else printf("No\n");
    }

    return 0;
}

Details

小提示:点击横条可展开更详细的信息

Test #1:

score: 5
Accepted
time: 2ms
memory: 3684kb

input:

526 1000 3
216 450
326 226
160 58
216 98
499 456
490 405
278 112
94 25
175 17
73 278
186 359
298 495...

output:

No
Yes
No

result:

ok 3 lines

Test #2:

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

input:

298 1000 3
84 235
246 201
189 26
70 248
253 52
85 256
142 153
185 129
12 27
135 13
81 128
121 273
20...

output:

No
No
Yes

result:

ok 3 lines

Test #3:

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

input:

608 1000 3
137 136
533 432
281 503
18 508
83 331
168 209
40 256
227 467
451 323
381 449
181 9
242 56...

output:

Yes
No
No

result:

ok 3 lines

Test #4:

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

input:

419 1000 3
241 397
194 308
67 267
249 105
316 178
274 183
207 400
299 31
362 416
316 100
272 388
166...

output:

Yes
Yes
No

result:

ok 3 lines

Test #5:

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

input:

789 1000 3
731 59
80 138
573 162
498 296
758 308
198 125
362 51
280 552
215 699
653 537
83 516
249 6...

output:

Yes
No
No

result:

ok 3 lines

Test #6:

score: 5
Accepted
time: 3ms
memory: 3680kb

input:

128 1000 3
66 119
83 33
120 126
45 6
78 83
6 117
69 4
71 4
9 37
94 40
92 85
95 5
30 113
64 69
94 5
8...

output:

No
Yes
Yes

result:

ok 3 lines

Test #7:

score: 5
Accepted
time: 3ms
memory: 3680kb

input:

672 1000 3
628 31
204 144
182 31
426 540
525 398
35 178
586 322
546 395
14 331
87 633
361 246
9 272
...

output:

Yes
No
No

result:

ok 3 lines

Test #8:

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

input:

252 1000 3
149 191
171 194
147 5
234 2
249 20
222 34
153 250
35 20
155 12
192 181
204 243
145 126
93...

output:

No
Yes
Yes

result:

ok 3 lines

Test #9:

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

input:

917 1000 100
828 235
858 88
782 723
898 806
788 885
316 453
384 42
255 606
248 688
235 406
627 654
1...

output:

Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
...

result:

ok 100 lines

Test #10:

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

input:

992 1000 100
448 821
624 365
333 406
723 869
110 927
131 955
250 981
343 923
256 160
690 751
491 282...

output:

Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
...

result:

ok 100 lines

Test #11:

score: 5
Accepted
time: 2ms
memory: 3680kb

input:

997 1000 70
546 283
567 706
821 731
423 498
548 823
296 634
370 195
246 22
924 442
308 628
280 776
9...

output:

Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
...

result:

ok 70 lines

Test #12:

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

input:

970 1000 100
860 214
460 49
946 486
688 587
381 235
939 588
159 561
546 802
39 828
950 473
508 200
4...

output:

Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
...

result:

ok 100 lines

Test #13:

score: 5
Accepted
time: 17ms
memory: 3680kb

input:

743 1000 100000
188 384
583 529
310 629
618 529
183 16
562 153
456 492
334 515
165 540
380 57
325 38...

output:

Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
No
Yes
Yes
Yes
Yes
Yes
Yes
Yes
No
Yes
Yes
No
Yes
Yes
Yes
Yes
Yes...

result:

ok 100000 lines

Test #14:

score: 5
Accepted
time: 8ms
memory: 3684kb

input:

829 1000 100000
103 206
265 333
614 821
221 450
692 383
682 515
383 733
827 82
210 141
628 443
239 3...

output:

Yes
Yes
Yes
Yes
Yes
No
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
No
No
No
Yes
Yes
Yes
...

result:

ok 100000 lines

Test #15:

score: 5
Accepted
time: 19ms
memory: 3676kb

input:

994 1000 100000
295 618
424 470
5 771
762 287
745 388
381 428
388 81
365 920
118 686
725 688
53 342
...

output:

Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
No
Yes
No
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Ye...

result:

ok 100000 lines

Test #16:

score: 5
Accepted
time: 14ms
memory: 3680kb

input:

783 1000 100000
527 676
693 782
412 432
51 131
488 348
300 322
105 334
531 454
504 426
176 200
288 5...

output:

Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
...

result:

ok 100000 lines

Test #17:

score: 5
Accepted
time: 66ms
memory: 8772kb

input:

33715 100000 100000
9136 16043
12397 25373
31126 33499
31619 28991
32276 27126
23878 27032
864 31850...

output:

Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
No
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Y...

result:

ok 100000 lines

Test #18:

score: 5
Accepted
time: 94ms
memory: 9156kb

input:

72608 100000 100000
16345 33449
6057 38806
65294 25736
20237 19010
22997 6127
2919 70452
1387 39687
...

output:

Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
No
Yes
Yes
Y...

result:

ok 100000 lines

Test #19:

score: 5
Accepted
time: 69ms
memory: 8264kb

input:

19631 100000 100000
7976 13237
11778 656
1584 1812
3279 18800
228 13957
4754 11149
11189 19271
6027 ...

output:

Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
...

result:

ok 100000 lines

Test #20:

score: 5
Accepted
time: 93ms
memory: 9300kb

input:

85692 100000 100000
16618 77180
27941 33522
57503 7000
4 34196
34815 32527
11289 22552
17630 23083
5...

output:

No
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Y...

result:

ok 100000 lines