记录编号 |
479007 |
评测结果 |
AAAAAAAAAA |
题目名称 |
最优布线问题 |
最终得分 |
100 |
用户昵称 |
APWTMECRD |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
1.211 s |
提交时间 |
2017-12-15 19:53:38 |
内存使用 |
8.73 MiB |
显示代码纯文本
- #include<cstdio>
- #include<algorithm>
- using namespace std;
- bool flags;char ch;
- int read(int &x)
- {flags=false;
- while(ch=getchar(),ch<47 || 58<ch)if(ch=='-')flags=true;
- x=ch^'0';
- while(ch=getchar(),48<=ch && ch<=57)x=x*10+(ch^'0');
- if(flags)return -x;
- else return x;
- }
- int n,p[1501],ans,cnt;
- class node
- {public:
- int a,b,key;
- }s[1500001];
- int find(int u)
- {
- return p[u]==u ? u : p[u]=find(p[u]);
- }
- int sb()
- {
- for(int i=1;i<=n;i++)p[i]=i;
- for(int i=1;i<=cnt;i++)
- {
- int x=find(s[i].a);
- int y=find(s[i].b);
- if(p[x]!=p[y])
- {
- p[x]=p[y];
- ans+=s[i].key;
- }
- }
- }
- int cmp(node x,node y)
- {
- return x.key<y.key;
- }
- int LL()
- {
- freopen ("wire.in","r",stdin);
- freopen ("wire.out","w",stdout);
- read(n);
- int op;
- for(int i=1;i<=n;i++)
- {
- for(int j=1;j<=n;j++)
- {
- read(op);
- if(i>j && op)
- {
- s[++cnt].a=i;
- s[cnt].b=j;
- s[cnt].key=op;
- }
- }
- }
- sort(s+1,s+cnt+1,cmp);
- sb();
- printf("%d",ans);
- return 0;
- }
- int work=LL();
- int main(){;}