当前位置:网站首页>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
边栏推荐
- Attack and defense world miscall
- Attack and defense world ditf Misc
- Crawler obtains real estate data
- uniapp设置背景图效果demo(整理)
- ThreadLocal详解
- Gd32f4xx serial port receive interrupt and idle interrupt configuration
- NPDP certification | how do product managers communicate across functions / teams?
- 枚举与#define 宏的区别
- Unity3d Learning Notes 6 - GPU instantiation (1)
- rust知识思维导图xmind
猜你喜欢

Export MySQL table data in pure mode

rust知识思维导图xmind

Hardware development notes (10): basic process of hardware development, making a USB to RS232 module (9): create ch340g/max232 package library sop-16 and associate principle primitive devices

树的先序中序后序遍历

Management background --1 Create classification

Common sense: what is "preservation" in insurance?

新手程序员该不该背代码?

Leetcode exercise - Sword finger offer 26 Substructure of tree

CCNA Cisco network EIGRP protocol

Leetcode question brushing (XI) -- sequential questions brushing 51 to 55
随机推荐
leetcode:面试题 17.24. 子矩阵最大累加和(待研究)
Advantages of link local address in IPv6
UE4蓝图学习篇(四)--流程控制ForLoop和WhileLoop
基于 QEMUv8 搭建 OP-TEE 开发环境
Export MySQL table data in pure mode
SQL Server生成自增序号
变量与“零值”的比较
qt quick项目offscreen模式下崩溃的问题处理
MySQL----初识MySQL
Aardio - 利用customPlus库+plus构造一个多按钮组件
MySQL数据库基本操作-DML
const关键字
General implementation and encapsulation of go diversified timing tasks
return 关键字
做接口测试都测什么?有哪些通用测试点?
signed、unsigned关键字
Plafond du tutoriel MySQL, bien collecté, regardez lentement
0 basic learning C language - digital tube
【踩坑合辑】Attempting to deserialize object on CUDA device+buff/cache占用过高+pad_sequence
Seata聚合 AT、TCC、SAGA 、 XA事务模式打造一站式的分布式事务解决方案