当前位置:网站首页>POJ 1258 Agri-Net
POJ 1258 Agri-Net
2022-07-06 15:10:00 【全栈程序员站长】
大家好,又见面了,我是全栈君。
最小生成树问题。
矩阵输入。
这只是很伤心G++ 服从AC。
C++ 已经RE。
唯一的问题,说的最多的 100 X 100 矩阵啊。
Logically, they are N lines of N space-separated integers. Physically, they are limited in length to 80 characters, so some lines continue onto others.
→_→ 不知各位怎么理解这句。
#include<cstdio>
#include<cstring>
#include<string>
#include<queue>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<iostream>
#include<list>
#include<set>
#include<cmath>
#define INF 0x7fffffff
#define eps 1e-6
using namespace std;
int n;
struct lx
{
int u,v,len;
} l[500*1001];
int fa[1001];
bool cmp(lx a,lx b)
{
return a.len<b.len;
}
int father(int x)
{
if(x!=fa[x])
return fa[x]=father(fa[x]);
}
int main()
{
while(scanf("%d",&n)!=EOF)
{
for(int i=0; i<=n; i++)
fa[i]=i;
int cot=0;
for(int i=1; i<=n; i++)
for(int j=1; j<=n; j++)
{
int len;
scanf("%d",&len);
if(i==j)continue;
l[cot].u=i;
l[cot].v=j;
l[cot++].len=len;
}
sort(l,l+cot,cmp);
int ans=0;
for(int i=0; i<cot; i++)
{
int fu=father(l[i].u);
int fv=father(l[i].v);
if(fu==fv)continue;
fa[fv]=fu;
ans+=l[i].len;
}
printf("%d\n",ans);
}
}
版权声明:本文博主原创文章,博客,未经同意不得转载。
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/116986.html原文链接:https://javaforall.cn
边栏推荐
- UE4蓝图学习篇(四)--流程控制ForLoop和WhileLoop
- pytorch_YOLOX剪枝【附代码】
- 如何实现文字动画效果
- Attack and defense world miscall
- Advantages of link local address in IPv6
- 雅思口语的具体步骤和时间安排是什么样的?
- Aardio - 封装库时批量处理属性与回调函数的方法
- 二叉(搜索)树的最近公共祖先 ●●
- Data processing skills (7): MATLAB reads the data in the text file TXT with mixed digital strings
- Improving Multimodal Accuracy Through Modality Pre-training and Attention
猜你喜欢
随机推荐
The SQL response is slow. What are your troubleshooting ideas?
NPDP certification | how do product managers communicate across functions / teams?
云原生技术--- 容器知识点
中国固态氧化物燃料电池技术进展与发展前景报告(2022版)
2022-07-05 stonedb的子查询处理解析耗时分析
自定义 swap 函数
2022-07-04 the high-performance database engine stonedb of MySQL is compiled and run in centos7.9
Web APIs DOM time object
Assembly and interface technology experiment 5-8259 interrupt experiment
MySQL----初识MySQL
Memorabilia of domestic database in June 2022 - ink Sky Wheel
Management background --2 Classification list
[leetcode daily clock in] 1020 Number of enclaves
Should novice programmers memorize code?
PVL EDI project case
UDP programming
【编译原理】做了一半的LR(0)分析器
Chapter 3: detailed explanation of class loading process (class life cycle)
基於 QEMUv8 搭建 OP-TEE 開發環境
2022-07-05 使用tpcc对stonedb进行子查询测试