QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#816915#9812. Binary SearchYMH_fourteenWA 48ms25304kbC++141.4kb2024-12-16 19:09:292024-12-16 19:09:31

Judging History

This is the latest submission verdict.

  • [2024-12-16 19:09:31]
  • Judged
  • Verdict: WA
  • Time: 48ms
  • Memory: 25304kb
  • [2024-12-16 19:09:29]
  • Submitted

answer

// Author: YE Minghan
#include<bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#include "templates/debug.h"
#define __int128 ll
#else
#define dbg(...) (void)0
#define msg(...) (void)0
#endif
#define ll long long
#define endl '\n'
#define PB emplace_back
#define PPB pop_back
#define MP make_pair
#define ALL(Name) Name.begin(),Name.end()
#define PII pair<int,int>
#define VI vector<int>
#define GI greater<int>
#define fi first
#define se second

const int N=300005;
int n,m;
bool a[N];
int f[2][N],d[2][N]; // 0:diff 1:same
bool vis[N];
VI g[N];

int main()
{
	ios::sync_with_stdio(false),cin.tie(nullptr);
//	int _;cin>>_;while(_--)

	cin>>n>>m;
	for(int i=1;i<=n;i++)cin>>a[i];
	for(int i=1,u,v;i<=m;i++)
	{
		cin>>u>>v,g[u].PB(v),g[v].PB(u);
		d[a[v]][u]++,d[a[u]][v]++;
	}
	queue<pair<bool,int>>q;
	memset(f,0xc0,sizeof(f));
	for(int i=1;i<=n;i++)
		for(int j=0;j<=1;j++)
			if(!d[j][i])
			{
				f[j][i]=1;
				if(!vis[i])q.emplace(j,i),vis[i]=1;
			}
	while(!q.empty())
	{
		auto [p,x]=q.front();q.pop();
		for(int y:g[x])
		{
			f[a[x]][y]=max(f[a[x]][y],f[p][x]+1);
			if(vis[y])continue;
			if(!--d[a[x]][y])q.emplace(a[x],y),vis[y]=1;
		}
	}
	for(int i=1;i<=n;i++)if(!vis[i])return puts("infinity"),0;
	int ans=2e9;
	for(int i=0;i<4;i++)
	{
		int mx=1;
		for(int j=1;j<=n;j++)
			if((i>>1)^a[j])mx=max(mx,f[i&1][j]+1);
		ans=min(ans,mx);
	}
	cout<<ans;

	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 4ms
memory: 16016kb

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: 4ms
memory: 15564kb

input:

1 0
0

output:

1

result:

ok single line: '1'

Test #4:

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

input:

1 0
1

output:

1

result:

ok single line: '1'

Test #5:

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

input:

2 0
1 1

output:

1

result:

ok single line: '1'

Test #6:

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

input:

2 0
1 0

output:

2

result:

ok single line: '2'

Test #7:

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

input:

2 1
0 0
1 2

output:

1

result:

ok single line: '1'

Test #8:

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

input:

2 1
0 1
2 1

output:

2

result:

ok single line: '2'

Test #9:

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

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: 15560kb

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: 13576kb

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: 4ms
memory: 15664kb

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: 0ms
memory: 15616kb

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: 15632kb

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: 15564kb

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: 3ms
memory: 15624kb

input:

3 1
0 0 1
1 2

output:

2

result:

ok single line: '2'

Test #17:

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

input:

3 1
1 0 1
1 3

output:

2

result:

ok single line: '2'

Test #18:

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

input:

3 1
0 1 1
1 2

output:

2

result:

ok single line: '2'

Test #19:

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

input:

4 2
0 0 1 1
1 2
3 4

output:

2

result:

ok single line: '2'

Test #20:

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

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: 0ms
memory: 15636kb

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: 15560kb

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: 4ms
memory: 15580kb

input:

3 2
1 0 0
1 2
3 2

output:

2

result:

ok single line: '2'

Test #24:

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

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: 0ms
memory: 15888kb

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: 15564kb

input:

3 1
0 1 1
1 3

output:

2

result:

ok single line: '2'

Test #27:

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

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: 15648kb

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: 15632kb

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: 0ms
memory: 15628kb

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: 0ms
memory: 15820kb

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: 4ms
memory: 15632kb

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: 4ms
memory: 15856kb

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: 15668kb

input:

2 1
1 0
1 2

output:

2

result:

ok single line: '2'

Test #35:

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

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: 3ms
memory: 15576kb

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: 15512kb

input:

2 1
1 0
2 1

output:

2

result:

ok single line: '2'

Test #38:

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

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: 15600kb

input:

2 1
0 0
2 1

output:

1

result:

ok single line: '1'

Test #40:

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

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: 15660kb

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: 4ms
memory: 15624kb

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: 11ms
memory: 16848kb

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: 48ms
memory: 25304kb

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:

150002

result:

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