当前位置:网站首页>POJ 1258 Agri-Net
POJ 1258 Agri-Net
2022-07-06 22:33:00 【Full stack programmer webmaster】
Hello everyone , I meet you again , I'm the king of the whole stack .
Minimum spanning tree problem .
Matrix input .
It's just sad G++ obey AC.
C++ already RE.
The only problem , The most talked about 100 X 100 Matrix .
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.
→_→ I don't know how you understand this sentence .
#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);
}
}
Copyright notice : This article is the original article of the blogger , Blog , Do not reprint without permission .
Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/116986.html Link to the original text :https://javaforall.cn
边栏推荐
- Classification, function and usage of MySQL constraints
- Memorabilia of domestic database in June 2022 - ink Sky Wheel
- 金融人士必读书籍系列之六:权益投资(基于cfa考试内容大纲和框架)
- ThreadLocal详解
- Web APIs DOM time object
- Return keyword
- Pit encountered by handwritten ABA
- 0 basic learning C language - interrupt
- Daily question 1: force deduction: 225: realize stack with queue
- [线性代数] 1.3 n阶行列式
猜你喜欢
【LeetCode】19、 删除链表的倒数第 N 个结点
Web APIs DOM time object
The SQL response is slow. What are your troubleshooting ideas?
云原生技术--- 容器知识点
[leetcode] 19. Delete the penultimate node of the linked list
Export MySQL table data in pure mode
软考高级(信息系统项目管理师)高频考点:项目质量管理
剑指offer刷题记录1
LeetCode 练习——剑指 Offer 26. 树的子结构
Seata aggregates at, TCC, Saga and XA transaction modes to create a one-stop distributed transaction solution
随机推荐
Advantages of link local address in IPv6
如何实现文字动画效果
[线性代数] 1.3 n阶行列式
UE4蓝图学习篇(四)--流程控制ForLoop和WhileLoop
Applet system update prompt, and force the applet to restart and use the new version
Web APIs DOM 时间对象
Netxpert xg2 helps you solve the problem of "Cabling installation and maintenance"
小程序系统更新提示,并强制小程序重启并使用新版本
How big is the empty structure?
NPDP certification | how do product managers communicate across functions / teams?
pytorch_YOLOX剪枝【附代码】
poj 1094 Sorting It All Out (拓扑排序)
Anaconda installs third-party packages
signed、unsigned关键字
2022-07-05 stonedb sub query processing parsing time analysis
The difference between enumeration and define macro
[IELTS speaking] Anna's oral learning record part1
void关键字
Jafka来源分析——Processor
The SQL response is slow. What are your troubleshooting ideas?