1 solutions

  • 1
    @ 2022-4-11 22:48:14
    #include<iostream>
    #include<algorithm>
    using namespace std;
    const int N=200020;
    int p[N];
    struct mess{
    	int x,y;
    	int s;
    }a[N];
    bool cmp(mess x,mess y)
    {
    	return x.s>y.s;
    }
    int find(int x)
    {
    	if(p[x]!=x) p[x]=find(p[x]);
    	return p[x];
    }
    void merge(int x,int y)
    {
    	int xx=find(x);
    	int yy=find(y);
    	if(xx!=yy) p[xx]=yy;
    }
    int main(){
    	int n,m;
    	cin>>n>>m;
    	for(int i=1;i<=2*n;i++) p[i]=i;
    	for(int i=1;i<=m;i++) cin>>a[i].x>>a[i].y>>a[i].s;
    	sort(a+1,a+m+1,cmp);
    	for(int i=1;i<=m;i++)
    	{
    		if(find(a[i].x)==find(a[i].y))
    		{
    			cout<<a[i].s;
    			return 0;
    		}
    		merge(a[i].x+n,a[i].y);
    		merge(a[i].x,a[i].y+n);
    	}
    	cout<<"0";
    	return 0;
    } 
    /*
    首先先排序,两个怨气大的不能在同一个集合里面
    如果在了,那就是被看见的第一个,其实下面就可以不用判断了 
    
    
    */
    
    • 1

    Information

    ID
    274
    Time
    1000ms
    Memory
    256MiB
    Difficulty
    6
    Tags
    # Submissions
    22
    Accepted
    11
    Uploaded By