QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#190151#6861. Counter StrikemasterhuangAC ✓686ms58872kbC++202.2kb2023-09-28 13:46:442023-09-28 13:46:46

Judging History

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

  • [2023-09-28 13:46:46]
  • 评测
  • 测评结果:AC
  • 用时:686ms
  • 内存:58872kb
  • [2023-09-28 13:46:44]
  • 提交

answer

#include<bits/stdc++.h>
#define LL long long
#define P pair<int,int>
#define fi first
#define se second
#define fr(x) freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);
using namespace std;
const int N=4e5+5;
int T,n,m,K,tot,cnt,num,all,head[N],id[N],low[N],bl[N],I[N],siz[N],a[N],t;
struct node{int to,nex;}e[N<<1];
bool v[N],V[N],ok[N<<1],OK;
P EE[N];
basic_string<int>E[N];
vector<int>bc[N];
inline void add(int u,int v)
{
	e[++tot]={v,head[u]};head[u]=tot;
	e[++tot]={u,head[v]};head[v]=tot;
}
void dfs(int x,int fa)
{
	id[x]=low[x]=++tot;a[++t]=x;int son=0;
	for(int i=head[x];i;i=e[i].nex)
	{
		int to=e[i].to;
		if(!id[to])
		{
			(x==fa)&&(son++),dfs(to,fa),low[x]=min(low[x],low[to]);
			if(low[to]>=id[x]){cnt++;while(a[t+1]!=to) bc[cnt].push_back(a[t]),t--;bc[cnt].push_back(x);}
		}
		else low[x]=min(low[x],id[to]);
	}
	if(x==fa&&son==0) bc[++cnt].push_back(x);
}
void dfs2(int x,int fa)
{
	v[x]=1;siz[x]=V[x];
	for(int i:E[x]) if(i^fa) dfs2(i,x),siz[x]+=siz[i];
}
void dfs3(int x,int fa)
{
	bool ooo=1;
	for(int i:E[x]) if(i^fa) (siz[i]>1)&&(ooo=0),dfs3(i,x);
	if(all-siz[x]>1) ooo=0;
	if(ooo&&x<=n) OK=1;
}
inline bool chk(int x)
{
	for(int i=1;i<=2*n;i++) id[i]=low[i]=v[i]=V[i]=head[i]=siz[i]=a[i]=0,E[i].clear(),bc[i].clear();
	for(int i=1;i<=2*m+1;i++) ok[i]=0;cnt=num=t=tot=0;
	for(int i=1;i<=m;i++)
	{
		int u=EE[i].fi,v=EE[i].se;
		if(I[u]<=x||I[v]<=x) continue;
		add(u,v);
	}tot=0;
	for(int i=1;i<=n;i++) if(!id[i]&&I[i]>x) dfs(i,i);
	for(int i=1;i<=cnt;i++) for(int j:bc[i]) E[j]+=(i+n),E[i+n]+=(j);
	for(int i=1;i<=n;i++) if(I[i]>x&&(I[i]!=1e9)) V[i]=1;
	for(int i=1;i<=n+cnt;i++) v[i]=0;int CC=0;
	for(int i=1;i<=n+cnt;i++) if(!v[i])
	{
		OK=0;dfs2(i,0),all=siz[i],dfs3(i,0);
		if(!OK) return 0;if(siz[i]>1){if(CC) return 0;CC++;}
	}return 1;
}
int main()
{
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);cin>>T;
	while(T--)
	{
		cin>>n>>m>>K;
		for(int i=1;i<=n;i++) I[i]=1e9;
		for(int i=1,u,v;i<=m;i++) cin>>u>>v,EE[i]={u,v};
		for(int i=1,x;i<=K;i++) cin>>x,I[x]=i;
		int l=1,r=K,mid,ans=-1;
		while(l<=r) mid=(l+r)>>1,(chk(mid-1)?ans=r=mid-1:l=mid+1);
		cout<<ans<<"\n";
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 686ms
memory: 58872kb

input:

4446
21 23 21
21 20
19 10
6 11
9 21
18 9
14 1
18 11
14 2
19 15
17 11
6 2
19 17
3 16
1 7
5 11
17 4
10 20
13 16
13 3
13 8
9 11
12 13
12 18
12 3 13 4 10 11 6 1 14 9 15 21 8 19 18 5 16 17 7 20 2
24 28 24
19 15
2 11
20 18
19 17
8 6
3 10
21 18
22 6
21 10
14 6
14 7
5 19
2 23
5 10
1 11
12 20
13 16
24 3
10 9...

output:

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

result:

ok 4446 lines