社区讨论
mle10分,求助
P1111修复公路参与者 5已保存回复 17
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 17 条
- 当前快照
- 1 份
- 快照标识符
- @m2pg70qf
- 此快照首次捕获于
- 2024/10/26 08:53 去年
- 此快照最后确认于
- 2025/11/04 23:44 4 个月前
CPP
#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
回复
共 17 条回复,欢迎继续交流。
正在加载回复...