并查集WA了
查看原帖
并查集WA了
118630
Lube楼主2020/7/3 22:17
#include<bits/stdc++.h>
using namespace std;
struct s{
	int x,y,quan;
}g[200005];
int tot,n,m;
int rec1,rec2;
bool cmp(s a,s b){return a.quan>b.quan;}
pair<int,int> jh[20005];
pair<int,int> find(int mark)
{
	if(jh[mark].first==mark)
	{
		pair<int,int> xx;xx=jh[mark];if(xx.second)xx.second^=1;return xx;
	}
	return jh[mark]=find(jh[mark].first);
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)
	{
		int g1,g2,g3;scanf("%d%d%d",&g1,&g2,&g3);
		g[++tot].x=g1;g[tot].y=g2;g[tot].quan=g3;
	}
	sort(g+1,g+1+tot,cmp);
	for(int i=1;i<=n;i++)jh[i].first=i;
	for(int i=1;i<=tot;i++)
	{
	    jh[g[i].x]=find(g[i].x);
	    jh[g[i].y]=find(g[i].y);
	    if(jh[g[i].x].first==jh[g[i].y].first&&jh[g[i].x].second==jh[g[i].y].second){printf("%d",g[i].quan);return 0;}
	    if(!jh[g[i].x].second)jh[g[i].x].second=2;
	    pair<int,int> xx;xx=jh[g[i].x];xx.second=jh[g[i].x].second^1;
	    jh[g[i].y]=xx;
	}
	printf("0");
}
2020/7/3 22:17
加载中...