QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#613699#8517. Interesting PathsTecy#TL 1347ms167276kbC++201.6kb2024-10-05 14:31:062024-10-05 14:31:08

Judging History

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

  • [2024-10-05 14:31:08]
  • 评测
  • 测评结果:TL
  • 用时:1347ms
  • 内存:167276kb
  • [2024-10-05 14:31:06]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define N 1000010
map<ll,ll>mp1,mp2;
vector<ll>g[N];
vector<ll>f[N];
void bfs1(ll x)
{
    queue<ll>q;
    q.push(x);
    while(!q.empty())
    {
        ll num=q.front();
        q.pop();
        for(auto b:g[num])
        {
            if(mp1[b])continue;
            else 
            {
                mp1[b]++;
                q.push(b);
            }
        }
    }
}
void bfs2(ll x)
{
    queue<ll>q;
    q.push(x);
    while(!q.empty())
    {
        ll num=q.front();
        q.pop();
        for(auto b:f[num])
        {
            if(mp2[b])continue;
            else 
            {
                mp2[b]++;
                q.push(b);
            }
        }
    }
}

struct node
{
    ll l,r;
}p[N];

void solve() {
    ll n,m;
    cin>>n>>m;
    for(int i=1;i<=m;i++)
    {
        ll u,v;
        cin>>u>>v;
        g[u].push_back(v);
        f[v].push_back(u);
        p[i].l=u;p[i].r=v;
    }
    bfs1(1);
    bfs2(n);
    mp1[1]=1;mp2[1]=1;
    mp1[n]=1;mp2[n]=1;
    ll ans=0;
    for(int i=1;i<=m;i++)
    {
        if(mp1[p[i].l]&&mp1[p[i].r]&&mp2[p[i].l]&&mp2[p[i].r])
        {
            //cerr<<p[i].l<<" "<<p[i].r<<"\n";
            ans++;
        }
    }
    //cerr<<ans<<"\n";
    for(int i=2;i<n;i++)
    {
        if(mp1[i]&&mp2[i])ans--;
    }
    cout<<ans;
}

int main() {
    ios::sync_with_stdio(false);
    cout.tie(0);
    cin.tie(0);

    int T = 1;
    //cin >> T;
    for (int i = 1; i <= T; i++) {
        solve();
    }

    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 2ms
memory: 3548kb

input:

5 7
1 3
3 5
1 2
2 3
3 4
4 5
2 4

output:

4

result:

ok 1 number(s): "4"

Test #2:

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

input:

5 3
1 3
2 3
2 5

output:

0

result:

ok 1 number(s): "0"

Test #3:

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

input:

2 0

output:

0

result:

ok 1 number(s): "0"

Test #4:

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

input:

2 1
1 2

output:

1

result:

ok 1 number(s): "1"

Test #5:

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

input:

10 20
2 8
5 8
4 8
3 10
3 7
2 7
2 5
1 7
6 9
6 10
2 4
5 9
2 10
3 9
7 8
4 10
3 6
2 3
5 7
6 8

output:

0

result:

ok 1 number(s): "0"

Test #6:

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

input:

10 30
8 9
1 5
3 6
4 6
4 7
6 9
3 5
5 6
3 8
1 4
3 4
7 8
2 4
4 5
1 8
6 10
2 10
9 10
1 2
8 10
2 7
2 8
2 5
7 9
2 6
4 8
1 7
1 6
7 10
4 9

output:

19

result:

ok 1 number(s): "19"

Test #7:

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

input:

20 57
6 20
5 9
8 11
6 17
5 18
14 16
6 18
8 18
1 3
17 20
2 16
4 19
2 15
7 17
17 19
8 16
11 15
13 16
5 20
4 14
5 16
7 12
10 12
3 12
8 13
1 5
6 11
13 17
11 16
2 6
4 5
14 15
3 14
9 13
8 10
18 20
15 17
6 12
5 17
2 10
8 17
15 16
15 20
5 19
10 15
1 2
4 20
4 18
3 16
2 12
8 19
10 19
2 11
12 17
12 20
5 7
1 15

output:

21

result:

ok 1 number(s): "21"

Test #8:

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

input:

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

output:

5

result:

ok 1 number(s): "5"

Test #9:

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

input:

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

output:

79

result:

ok 1 number(s): "79"

Test #10:

score: 0
Accepted
time: 215ms
memory: 66044kb

input:

1000000 0

output:

0

result:

ok 1 number(s): "0"

Test #11:

score: 0
Accepted
time: 347ms
memory: 45428kb

input:

10000 1000000
3186 5896
193 9783
2762 3101
2793 5391
2587 9231
2991 6139
317 448
361 5290
7372 7580
279 2589
5476 7584
2829 3375
3785 8539
5898 7644
460 2025
2029 6959
1249 8686
1787 5348
840 7031
9515 9862
6122 9224
3911 5359
725 4062
985 5179
3337 4188
6961 8345
5325 6480
8308 9019
7827 9054
759 3...

output:

0

result:

ok 1 number(s): "0"

Test #12:

score: 0
Accepted
time: 986ms
memory: 167276kb

input:

1000000 1000000
227867 264986
543264 885751
368699 709020
126827 786083
15773 700372
582092 653193
597763 662903
24964 669822
118877 700066
650866 776787
264084 934355
104858 656657
393038 691935
254875 794624
349005 722140
77011 854592
264566 829978
395038 833643
180017 193646
28588 147277
71335 79...

output:

0

result:

ok 1 number(s): "0"

Test #13:

score: 0
Accepted
time: 849ms
memory: 126836kb

input:

1000000 1000000
277718 460482
147752 592243
672428 950124
290176 395254
169855 591213
23051 603108
683561 886805
369178 558263
15523 306646
851733 898093
16252 953612
195928 796663
298711 941197
807239 939884
477390 577792
177636 375148
199307 279986
171470 388424
864738 896318
520095 685892
281955 ...

output:

987489

result:

ok 1 number(s): "987489"

Test #14:

score: 0
Accepted
time: 538ms
memory: 122344kb

input:

1000000 500000
220011 331608
383898 452284
478455 598602
535465 835096
34781 509172
284635 653292
553793 686935
595558 905694
106231 182420
72160 205103
435467 474167
133438 709831
447900 993899
311233 441916
30052 897382
34200 490411
24306 365889
346868 769417
163206 392108
340962 818759
699298 730...

output:

442134

result:

ok 1 number(s): "442134"

Test #15:

score: 0
Accepted
time: 774ms
memory: 46884kb

input:

10000 1000000
769 5111
2621 5295
616 5384
603 9873
257 7962
4616 5977
4420 7963
1225 7007
5292 7230
6869 8661
5669 5714
7618 9925
2384 2393
1029 7575
3713 6965
1131 7793
6479 9949
5650 5880
6640 6735
4012 7870
6937 8667
3173 8439
1618 7794
1166 3266
4671 5333
3778 5189
1386 8839
1577 6482
764 7866
2...

output:

893098

result:

ok 1 number(s): "893098"

Test #16:

score: 0
Accepted
time: 1117ms
memory: 48184kb

input:

25000 1000000
3286 13917
7601 14129
18179 21682
12738 14859
2310 11787
13237 13313
1403 20530
2019 12776
7246 21258
109 4285
1250 5654
3281 16015
4357 7111
509 5915
8595 11893
15252 17559
5074 7653
5468 21483
4532 20843
9827 24533
5902 23960
2056 5538
11183 12864
1648 9275
19962 23304
12806 18024
41...

output:

687486

result:

ok 1 number(s): "687486"

Test #17:

score: 0
Accepted
time: 1347ms
memory: 156644kb

input:

1000000 1000000
145889 828965
101891 872944
306461 891194
479634 562124
460093 702806
434097 687914
868462 943584
522148 811696
202648 321281
413792 709955
9764 601279
257576 742047
310620 793868
444655 595009
47265 57177
277171 641024
281005 694629
508946 736418
264412 927342
33742 591190
274183 92...

output:

171017

result:

ok 1 number(s): "171017"

Test #18:

score: -100
Time Limit Exceeded

input:

1000000 1000000
987682 991819
630763 967194
682365 816105
15669 988580
649157 744816
777657 787054
515972 839941
428069 860906
127350 850842
91250 505765
522849 651379
194742 204624
71459 470879
181532 208277
330718 442774
486299 868372
186798 859668
474733 619379
997653 998142
758371 812576
407121 ...

output:

500000

result: