标签:
4 6
1 4 2534
2 3 3512
1 2 28351
1 3 6618
2 4 1805
3 4 12884
3512
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<cmath> 5 #include<algorithm> 6 #include<queue> 7 #include<cstdlib> 8 #include<iomanip> 9 #include<cassert> 10 #include<climits> 11 #define maxn 100001 12 #define F(i,j,k) for(int i=j;i<=k;i++) 13 #define M(a,b) memset(a,b,sizeof(a)) 14 #define FF(i,j,k) for(int i=j;i>=k;i--) 15 #define inf 0x7fffffff 16 #define p 23333333333333333 17 using namespace std; 18 int read(){ 19 int x=0,f=1;char ch=getchar(); 20 while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘)f=-1;ch=getchar();} 21 while(ch>=‘0‘&&ch<=‘9‘){x=x*10+ch-‘0‘;ch=getchar();} 22 return x*f; 23 } 24 int f[maxn]; 25 struct sd 26 { 27 int a; 28 int b; 29 int c; 30 int next; 31 }edge[maxn]; 32 bool cmp(const sd& x,const sd& y) 33 { 34 return x.c>y.c; 35 } 36 int find(int x) 37 { 38 return f[x]==x?x:f[x]=find(f[x]); 39 } 40 int head[maxn]; 41 int cnt=1; 42 int addedge(int x,int y,int v) 43 { 44 cnt++; 45 edge[cnt].a=x; 46 edge[cnt].b=y; 47 edge[cnt].c=v; 48 edge[cnt].next=head[x]; 49 head[x]=cnt; 50 } 51 int main() 52 { 53 std::ios::sync_with_stdio(false);//cout<<setiosflags(ios::fixed)<<setprecision(1)<<y; 54 // freopen("data.in","r",stdin); 55 // freopen("data.out","w",stdout); 56 int n,m; 57 cin>>n>>m; 58 F(i,1,m){ 59 int x,y,z; 60 cin>>x>>y>>z; 61 addedge(x,y,z); 62 } 63 int x,y; 64 for(int i=1;i<=n*2;i++) 65 f[i]=i; 66 sort(edge+1,edge+m+1,cmp); 67 F(i,1,m){ 68 x=find(edge[i].a); 69 y=find(edge[i].b); 70 if(x==y) 71 { 72 cout<<edge[i].c; 73 return 0; 74 } 75 f[y]=find(edge[i].a+n); 76 f[x]=find(edge[i].b+n); 77 } 78 cout<<"0"<<endl; 79 return 0; 80 }
【解法二】
敬请期待......
标签:
原文地址:http://www.cnblogs.com/SBSOI/p/5639432.html