@[P指向NULL](/space/show?uid=58399) 以后数组记得一定要开大一些,哪怕大一倍都没关系 ~~只要你开的出来~~ ~~另外你的代码秀的我头皮发麻~~
by 狸狸养的敏敏 @ 2018-07-13 15:43:56
@[PBCWZCC](/space/show?uid=28004)
by 狸狸养的敏敏 @ 2018-07-13 15:44:15
~~我好像只有F数组开小了没注意~~
谢谢@[P指向NULL](/space/show?uid=58399)
by PBCWZCC @ 2018-07-13 15:45:24
@[PBCWZCC](/space/show?uid=28004) 不客气呢QwQ ** (´・ω・`)**
by 狸狸养的敏敏 @ 2018-07-13 15:46:11
改了一处$\color{limegreen}\mathsf{AC}$啦
```cpp
#include<algorithm>
#include<cstdio>
using namespace std;
template <class T> inline void read(T &X)
{
X = 0;
register char symbol(0),ch(getchar());
while(ch<'0'||'9'<ch)
{
ch=='-' ? symbol = 1 : 1 , ch = getchar();
}
while('0'<=ch&&ch<='9')
{
X = (X<<3) + (X<<1) + (ch^48) , ch = getchar();
}
symbol ? X = -X : 1;
}
template <class T> inline T max_(T X,T Y)
{
return X<Y?Y:X;
}
template <class T> inline T min_(T X,T Y)
{
return X<Y?X:Y;
}
template <class T> inline T abs_(T X)
{
return X<0?-X:X;
}
#define MAXM 200000
#define MAXN 5000
struct edge{
int u,v,w;
bool operator<(const edge ee)const;
void addE(const int,const int,const int);
}E[MAXM|1];
int cnt,ans;
inline bool edge::operator<(const edge ee)const
{
return w < ee.w;
}
inline void edge::addE(const int u,const int v,const int w)
{
this->u = u , this->v = v , this->w = w ;
}
//inline bool cmp_(edge ea,edge eb)
//{
// return ea.w < eb.w;
//}
int F[MAXN|1];//这里
//inline int findf(int Fa[], int x)
//{
// return x==Fa[x] ? x : Fa[x]=findf(Fa,Fa[x]);
//}
inline int findf(int x)
{
return x == F[x] ? x : F[x] = findf(F[x]);
}
int n,m;
int main()
{
register int u,v,w;
read(n),read(m);
for(register int i(1);i<=n;++i)
{
F[i] = i;
}
for(register int i(1);i<=m;++i)
{
read(u) , read(v) , read(w);
E[i].addE(u,v,w);
}
sort(E+1,E+m+1);
register int fu,fv;
for(register int i(1);i<=m;++i)
{
fu = findf(E[i].u) , fv = findf(E[i].v) ;
if(fu!=fv)
{
++cnt;
F[fu] = fv;
ans += E[i].w;
if(cnt == n-1) break;
}
}
printf("%d",ans);
return 0;
}
```
by PBCWZCC @ 2018-07-13 15:48:05
看不懂
by 关嘉正 @ 2018-07-13 15:55:28
可以讲解吗
by 关嘉正 @ 2018-07-13 15:55:47