QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#816908 | #9812. Binary Search | YMH_fourteen | WA | 4ms | 15776kb | C++14 | 1.4kb | 2024-12-16 19:06:52 | 2024-12-16 19:06:53 |
Judging History
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]&&!vis[i])f[j][i]=1,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),dbg(i&1,j,f[i&1][j]);
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: 4ms
memory: 15644kb
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: 0ms
memory: 15580kb
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: 2ms
memory: 15572kb
input:
1 0 0
output:
1
result:
ok single line: '1'
Test #4:
score: 0
Accepted
time: 0ms
memory: 15776kb
input:
1 0 1
output:
1
result:
ok single line: '1'
Test #5:
score: 0
Accepted
time: 0ms
memory: 13472kb
input:
2 0 1 1
output:
1
result:
ok single line: '1'
Test #6:
score: -100
Wrong Answer
time: 0ms
memory: 15612kb
input:
2 0 1 0
output:
1
result:
wrong answer 1st lines differ - expected: '2', found: '1'