@[蒟蒻烟雨平生](/space/show?uid=85682) 我找到了,是```if(cr(s[i].z,s[i].x));```加了;
但是去掉之后只有90?
by 魏之哲它椰叶 @ 2019-03-01 21:56:01
@[蒟蒻烟雨平生](/space/show?uid=85682) ```
#include<bits/stdc++.h>
using namespace std;
int n,m,z,x,y,a[1010],lu=0,ss;
struct QAQ
{
int z,x,y;
}s[100002];
int bcj(int x)
{
if(a[x]==x)return x;
return a[x]=bcj(a[x]);
}
bool cr(int aa,int bb)
{
aa=bcj(aa);
bb=bcj(bb);
if(aa!=bb)
{
++lu;
a[aa]=bb;
return 1;
}
return 0;
}
bool tmd(QAQ d, QAQ e)
{
return d.y<e.y;
}
int main()
{
cin>>n>>m;
for(int i=1;i<=m;i++)a[i]=i;
for(int i=1;i<=m;i++)
{
cin>>s[i].z>>s[i].x>>s[i].y;
}
sort(s+1,s+m+1,tmd);
for(int i=1;i<=m;i++)
{
if(cr(s[i].z,s[i].x))
ss=max(ss,s[i].y);
}
if(lu<n-1)cout<<-1;
else cout<<ss;
}
```
by 魏之哲它椰叶 @ 2019-03-01 21:56:32
```
#include<bits/stdc++.h>
using namespace std;
int n,m,z,x,y,a[1010],lu=0,ss;
struct QAQ
{
int z,x,y;
}s[100002];
int bcj(int x)
{
if(a[x]==x)return x;
return a[x]=bcj(a[x]);
}
bool cr(int aa,int bb)
{
aa=bcj(aa);
bb=bcj(bb);
if(aa!=bb)
{
++lu;
a[aa]=bb;
return 1;
}
return 0;
}
bool tmd(QAQ d, QAQ e)
{
return d.y<e.y;
}
int main()
{
cin>>n>>m;
for(int i=1;i<=m;i++)a[i]=i;
for(int i=1;i<=m;i++)
{
cin>>s[i].z>>s[i].x>>s[i].y;
}
sort(s+1,s+m+1,tmd);
for(int i=1;i<=m;i++)
{
if(cr(s[i].z,s[i].x))
ss=max(ss,s[i].y);
}
if(lu<n-1)cout<<-1;
else cout<<ss;
}
```
by 魏之哲它椰叶 @ 2019-03-01 21:56:41
找到了,已A,谢谢
by 魏之哲它椰叶 @ 2019-03-01 22:00:03
@[魏之哲它椰叶](/space/show?uid=171518) 不用谢
by 绝顶我为峰 @ 2019-03-01 22:14:43
qwq
by 豌豆射手皮0608 @ 2019-03-02 08:43:24