10pts 除#1全部TLE 玄关
查看原帖
10pts 除#1全部TLE 玄关
1249176
Bao0714楼主2024/12/20 16:24
#include<bits/stdc++.h>
using namespace std;
const int N=2e4+10;
const int M=2e5+10;
int head[N],nxt[M],to[M],w[M],tot;
int mid;
int col[N];
bool F=true;
void dfs(int k)
{
	for(int i=head[k];i;i=nxt[i])
	{
		if(w[i]>mid)
		{
		if(!col[to[i]])
		{
			col[to[i]]=3-col[k];
			dfs(to[i]);
		}
		else
		if(col[k]+col[to[i]]!=3)
				F=false;
		}
	}
}
int main()
{
	int n,m,a,b,c;
	cin>>n>>m;
	for(int i=1;i<=n;i++)
	{
		cin>>a>>b>>c;
		to[++tot]=b,nxt[tot]=head[a],head[a]=tot,w[tot]=c;
		to[++tot]=a,nxt[tot]=head[b],head[b]=tot,w[tot]=c;
	}
	int l=0,r=1e9;
	while(l!=r)
	{
		mid=(l+r)>>1;
		F=true;
		memset(col,0,sizeof(col));
		for(int i=1;i<=n;i++)
		if(!col[i])
		col[i]=1,dfs(i);
		if(F)
			r=mid;
		else
			l=mid-1;
	}
	cout<<l;
	return 0;
}
2024/12/20 16:24
加载中...