求如何看到自己程序占的空间(即有没有mle
  • 板块学术版
  • 楼主harvey2019
  • 当前回复0
  • 已保存回复0
  • 发布时间2024/10/26 09:02
  • 上次更新2024/10/26 09:02:58
查看原帖
求如何看到自己程序占的空间(即有没有mle
283541
harvey2019楼主2024/10/26 09:02

rt 顺便问这个为什会mle?(link

#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;
}
2024/10/26 09:02
加载中...