【悬关+叫爸爸】莫名其妙WA+RE
  • 板块P1396 营救
  • 楼主SCma
  • 当前回复74
  • 已保存回复75
  • 发布时间2024/4/6 15:34
  • 上次更新2024/11/6 21:32:32
查看原帖
【悬关+叫爸爸】莫名其妙WA+RE
794146
SCma楼主2024/4/6 15:34

思路没问题,将#1,#2样例下载下来本地测试也没有问题,就是莫名其妙挂了,求助

奖赏:悬关 + 磕头认爹

#include<bits/stdc++.h>
#define MIN(a,b,c) min(min(a,b),c)
#define MAX(a,b,c) max(max(a,b),c)
#define ri register int
#define int long long
#define fixedset(a) fixed << setprecision(a)
#define MAXN 9.2211e18
#define inf 2114514
#define mf 5011
#define sf 1011
using namespace std;
int n,m,s,t,father[inf/10];
struct route{
	int x,y,cost;
	friend bool operator <(route a,route b){a.cost < b.cost;} 
}edge[inf/10];
int findFather(int x){
	if(father[x]==x) return x;
	return father[x]=findFather(father[x]);
}
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	//freopen(".in","r",stdin);
   	//freopen(".out","w",stdout);

	cin >> n >> m >> s >> t;
	for(ri i=1;i<=m;i++) cin >> edge[i].x >> edge[i].y >> edge[i].cost; 
	for(ri i=1;i<=n;i++) father[i]=i;
	sort(edge+1,edge+1+m);
	
	for(ri i=1;i<=m;i++){
		int fx=findFather(edge[i].x),fy=findFather(edge[i].y);
		if(fx!=fy) father[fx]=fy;
		
		if(findFather(s)==findFather(t)) cout << edge[i].cost << endl,exit(0);
	}
	return 0;
}

2024/4/6 15:34
加载中...