QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#817240#9812. Binary SearchCoffinsWA 49ms39888kbC++141.0kb2024-12-16 21:03:502024-12-16 21:03:59

Judging History

This is the latest submission verdict.

  • [2024-12-16 21:03:59]
  • Judged
  • Verdict: WA
  • Time: 49ms
  • Memory: 39888kb
  • [2024-12-16 21:03:50]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;
const int N=3e5+5;
const int inf=1e9+7;
int n,m,a[N],f[N],dg[N];
vector<int> edge[N<<1];
void lk(int x,int y)
{edge[x].push_back(y),dg[y]++;}

int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin>>n>>m;for(int i=1;i<=n;i++)cin>>a[i];
    for(int i=1;i<=m;i++)
    {
        int x,y;cin>>x>>y;
        if(a[x]==a[y])lk(x+n,y),lk(y+n,x);
        else lk(x,y+n),lk(y,x+n);
    }fill(f+1,f+n*2+1,inf);queue<int> q;
    for(int i=1;i<=2*n;i++)
    if(!dg[i])f[i]=1,q.push(i);
    while(!q.empty())
    {
        int u=q.front();q.pop();
        for(int v:edge[u])
        {
            dg[v]--;
            if(f[v]==inf)f[v]=f[u]+1;
            f[v]=max(f[v],f[u]+1);
            if(!dg[v])q.push(v);
        }
    }int x=0,y=0,z=0,w=0;
    for(int i=1;i<=n;i++)
    if(a[i])x=max(x,f[i]),y=max(y,f[i+n]);
    else z=max(z,f[i]),w=max(w,f[i+n]);
    int ans=min({x,y,z,w})+1;
    if(ans>=inf)cout<<"infinity\n";
    else cout<<ans<<'\n';
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 20912kb

input:

4 4
0 0 1 1
1 2
1 3
2 3
3 4

output:

4

result:

ok single line: '4'

Test #2:

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

input:

6 7
0 0 1 1 0 1
1 2
3 1
1 4
2 3
4 2
3 4
5 6

output:

infinity

result:

ok single line: 'infinity'

Test #3:

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

input:

1 0
0

output:

1

result:

ok single line: '1'

Test #4:

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

input:

1 0
1

output:

1

result:

ok single line: '1'

Test #5:

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

input:

2 0
1 1

output:

1

result:

ok single line: '1'

Test #6:

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

input:

2 0
1 0

output:

2

result:

ok single line: '2'

Test #7:

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

input:

2 1
0 0
1 2

output:

1

result:

ok single line: '1'

Test #8:

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

input:

2 1
0 1
2 1

output:

2

result:

ok single line: '2'

Test #9:

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

input:

3 2
0 1 1
1 2
2 3

output:

2

result:

ok single line: '2'

Test #10:

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

input:

3 2
0 0 0
1 2
2 3

output:

1

result:

ok single line: '1'

Test #11:

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

input:

3 3
0 0 0
1 2
2 3
3 1

output:

1

result:

ok single line: '1'

Test #12:

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

input:

3 3
0 0 1
1 2
2 3
3 1

output:

2

result:

ok single line: '2'

Test #13:

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

input:

4 3
0 0 1 1
1 2
2 3
3 4

output:

4

result:

ok single line: '4'

Test #14:

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

input:

4 4
0 1 1 0
1 2
2 3
3 4
4 1

output:

infinity

result:

ok single line: 'infinity'

Test #15:

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

input:

4 4
0 1 0 1
1 2
2 3
3 4
4 1

output:

2

result:

ok single line: '2'

Test #16:

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

input:

3 1
0 0 1
1 2

output:

2

result:

ok single line: '2'

Test #17:

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

input:

3 1
1 0 1
1 3

output:

2

result:

ok single line: '2'

Test #18:

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

input:

3 1
0 1 1
1 2

output:

2

result:

ok single line: '2'

Test #19:

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

input:

4 2
0 0 1 1
1 2
3 4

output:

2

result:

ok single line: '2'

Test #20:

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

input:

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

output:

3

result:

ok single line: '3'

Test #21:

score: 0
Accepted
time: 3ms
memory: 20884kb

input:

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

output:

4

result:

ok single line: '4'

Test #22:

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

input:

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

output:

2

result:

ok single line: '2'

Test #23:

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

input:

3 2
1 0 0
1 2
3 2

output:

2

result:

ok single line: '2'

Test #24:

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

input:

7 10
1 0 1 1 0 0 0
2 4
4 5
5 6
7 2
5 3
3 2
1 3
6 2
7 5
3 7

output:

4

result:

ok single line: '4'

Test #25:

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

input:

4 6
0 1 1 1
2 3
3 4
1 4
2 4
3 1
1 2

output:

2

result:

ok single line: '2'

Test #26:

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

input:

3 1
0 1 1
1 3

output:

2

result:

ok single line: '2'

Test #27:

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

input:

7 18
0 0 0 0 1 1 0
4 2
7 1
2 3
7 2
6 5
4 1
5 7
6 3
6 1
6 7
4 7
5 1
5 3
4 5
3 7
4 6
2 1
2 5

output:

infinity

result:

ok single line: 'infinity'

Test #28:

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

input:

7 17
1 0 1 0 0 0 0
6 3
5 1
6 4
7 6
7 2
3 1
6 1
2 4
1 2
4 7
7 1
3 2
5 2
4 5
5 7
3 7
3 4

output:

infinity

result:

ok single line: 'infinity'

Test #29:

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

input:

5 9
1 1 0 0 0
2 3
5 3
3 4
4 2
1 2
5 1
5 4
1 4
5 2

output:

infinity

result:

ok single line: 'infinity'

Test #30:

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

input:

8 14
1 0 0 0 1 1 1 0
2 4
8 4
2 1
5 6
8 1
3 7
7 5
7 4
3 4
1 5
2 3
8 3
5 3
7 2

output:

infinity

result:

ok single line: 'infinity'

Test #31:

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

input:

10 17
1 0 1 1 0 0 1 1 1 1
4 9
7 5
9 3
1 5
3 6
1 9
10 2
3 5
8 4
6 10
6 8
9 8
9 6
2 7
5 10
3 4
1 3

output:

2

result:

ok single line: '2'

Test #32:

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

input:

8 17
0 0 1 0 1 0 0 1
1 4
7 8
8 5
1 7
1 2
8 4
6 1
5 6
8 2
6 4
5 3
5 4
6 7
1 5
2 3
6 8
7 2

output:

infinity

result:

ok single line: 'infinity'

Test #33:

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

input:

4 3
0 0 1 0
1 4
3 4
2 1

output:

2

result:

ok single line: '2'

Test #34:

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

input:

2 1
1 0
1 2

output:

2

result:

ok single line: '2'

Test #35:

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

input:

4 5
1 1 0 0
4 3
1 2
4 2
1 4
2 3

output:

infinity

result:

ok single line: 'infinity'

Test #36:

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

input:

7 20
0 1 0 1 1 1 0
7 5
2 7
2 1
1 4
5 3
2 3
4 5
1 7
6 4
4 3
6 7
2 6
3 1
7 3
4 2
7 4
3 6
1 6
5 6
5 1

output:

infinity

result:

ok single line: 'infinity'

Test #37:

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

input:

2 1
1 0
2 1

output:

2

result:

ok single line: '2'

Test #38:

score: 0
Accepted
time: 3ms
memory: 20208kb

input:

7 7
1 1 1 1 0 1 1
1 6
7 5
2 4
3 6
4 5
6 4
1 4

output:

2

result:

ok single line: '2'

Test #39:

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

input:

2 1
0 0
2 1

output:

1

result:

ok single line: '1'

Test #40:

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

input:

9 14
0 1 1 1 0 1 0 0 0
6 4
6 2
9 4
8 7
5 9
3 9
3 7
7 9
1 4
3 2
1 6
3 1
3 4
2 8

output:

infinity

result:

ok single line: 'infinity'

Test #41:

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

input:

9 3
0 1 1 1 1 1 1 1 0
1 7
1 8
9 8

output:

2

result:

ok single line: '2'

Test #42:

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

input:

5 9
1 1 1 1 1
3 4
1 5
3 2
2 5
3 5
2 4
1 3
1 2
4 1

output:

1

result:

ok single line: '1'

Test #43:

score: 0
Accepted
time: 8ms
memory: 22084kb

input:

95705 24453
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

output:

2

result:

ok single line: '2'

Test #44:

score: -100
Wrong Answer
time: 49ms
memory: 39888kb

input:

300000 299999
0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 ...

output:

infinity

result:

wrong answer 1st lines differ - expected: '300000', found: 'infinity'