mle10分,求助
查看原帖
mle10分,求助
283541
harvey2019楼主2024/10/26 08:53
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

inline ll read()
{
	ll ans = 0;
	ll f = 1;
	char c = getchar();
	
	while( c < '0' || c > '9' )
	{
		if( c == '-' )
		{
			f = -1;
		}
		
		c = getchar();
	}
	
	while( c >= '0' && c <= '9' )
	{
		ans = ( ans << 3 ) + ( ans << 1 ) + ( c - 48 );
		c = getchar();
	}
	
	return ans * f;
}

inline void write( ll x )
{
	if( x < 0 )
	{
		putchar( '-' );
		x = -x;
	}
	
	if( x > 9 )
	{
		write( x / 10 );
	}
	
	putchar( x % 10 + '0' );
}

int f[100001];

struct node
{
	short x,y;
	int t;
}a[100001];

int find( int k )
{
	if( f[k] == k )
	{
		return k;
	}
	
	return f[k] = find( f[k] );
}

bool cmp( node x , node y )
{
	return x.t < y.t;
}

int main()
{
	int n = read(),m = read();
	
	for( int i = 1 ; i <= n ; i++ )
	{
		f[i] = i;
	}
	
	for( int i = 1 ; i <= m ; i++ )
	{
		cin >> a[i].x >> a[i].y >> a[i].t;
	}
	
	sort( a + 1 , a + m + 1 , cmp );
	
	for( int i = 1 ; i <= m ; i++ )
	{
		if( find( a[i].x ) != find( a[i].y ) )
		{
			n--;
		}
		
		f[find( a[i].x )] = a[i].y;
		
		if( n == 1 )
		{
			cout << a[i].t << endl;
			
			return 0;
		}
	}
	
	cout << -1 << endl;
	
	return 0;
}

mle的莫名其妙,第一个点ac后面的mle了,不改short都mle

2024/10/26 08:53
加载中...