ccf魔数c语言,ccf 201609-4 交通规划

附上代码:

#include#include#include#include#include#include

using namespacestd;#define inf 0xfffffff

intn, m;

typedefstructNODE

{intto;intcost;

friendbool operator < (const NODE &a, const NODE &b) {return a.cost >b.cost;

}

}node;

typedefstructEdge

{int from;intnext;intto;intw;intvalue;

} edge;

edge maps[10000005];int head[100050];int dist[100050];int vids[100050];intcnt;voidcreat ()

{for(int i=0; i<100050; i++)

head[i]=-1;

cnt=0;

}void add(int u,int v,intw)

{

maps[cnt].from =u;

maps[cnt].to=v;

maps[cnt].w=w;

maps[cnt].value=w;

maps[cnt].next=head[u];///一开始放置为-1,-1的条件就可以跳出///下一步接着储存,head[u]的值,就是前面的位置

head[u]=cnt++;///head[u]会得到这条线的值

}int dijkstra(int s,intt)

{for(int i=0; i<100050; i++)

{

vids[i]=0;

dist[i]=inf;

}

priority_queueque;

node begins;

begins.to=s;

begins.cost=0;

que.push(begins);while(!que.empty())

{

node ends=que.top();

que.pop();if(!vids[ends.to])

{

vids[ends.to]=1;

dist[ends.to]=ends.cost;for(int i = head[ends.to]; ~i; i =maps[i].next)

{int to = maps[i].to, w =maps[i].w;

maps[i].w= ends.cost +w;if(!vids[to])

{

node ans;

ans.to=to;

ans.cost=ends.cost+w;

que.push(ans);

}

}

}

}if(dist[t] ==inf)

{return -1;

}else{returndist[t];

}

}bool cmp(const edge & a, const edge &b)

{if(a.w !=b.w)

{return a.w

}return a.value

}int pre[100050];voidInit()

{for(int i=1; i<=m; i++)

pre[i]=i;

}int finds(intx)

{if(pre[x]==x)returnx;else

return pre[x]=finds(pre[x]);

}void unionjoin(int x,inty)

{int u=finds(x);int v=finds(y);if(u==v)return;elsepre[u]=v;

}bool same(int x,inty)

{return finds(x)==finds(y);

}long longkruskal()

{long long ans=0;

sort(maps,maps+ 2 *m,cmp);for(int i = 0; i< 2 * m; i++)

{if(!same(maps[i].from,maps[i].to))

{

unionjoin(maps[i].from,maps[i].to);

ans+=maps[i].value;

}else

continue;

}returnans;

}intmain()

{while(~scanf("%d%d",&n,&m))

{

creat();for(int i = 0; i < m; i ++) {intu, v, w;

scanf("%d%d%d",&u, &v, &w);

add(u, v, w);

add(v, u, w);

}

dijkstra(1, n);

Init();long long re =kruskal();

printf("%lld\n",re);

}return 0;

}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/562841.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

python数据可视化是什么_Python数据分析:可视化

本文是《数据蛙三个月强化课》的第二篇总结教程&#xff0c;如果想要了解数据蛙社群&#xff0c;可以阅读对于我们数据分析师来说&#xff0c;不仅要自己明白数据背后的含义&#xff0c;而且还要给老板更直观的展示数据的意义。所以&#xff0c;对于这项不可缺少的技能&#xf…

c语言主函数名用户指定,C语言允许main函数带形参,且形参个数和形参名均可由用户指定。()...

听力原文&#xff1a;W: Oh, Ken, I have been meaning to talk to you.M: Hi, Denise! Whats up?W: I have this great job lined up to manage a clothing store at the mall.M: Oh, say in detail, please.W: Well, one of the professors in my department just told me a…

ENSP配置 实例一 不同VLAN间通信

ENSP配置 实例一 不同VLAN间通信 SW1 [SW1]vlan batch 10 20 [SW1]interface g0/0/1 [SW1-GigabitEthernet0/0/1]port link-type access [SW1-GigabitEthernet0/0/1]port default vlan 10 [SW1-GigabitEthernet0/0/1]int g0/0/2 [SW1-GigabitEthernet0/0/2]port link-type acce…

用python绘制心形_python小趣味_520绘制一个心形.

#!/usr/bin/env python#coding:utf-8 importturtleimporttime#画爱心的顶部 defLittleHeart():for i in range(200): turtle.right(1) turtle.forward(2)#输入表白的语句&#xff0c;默认I Love you love input(Please enter a sentence of love, otherwise the default is &q…

ENSP配置 实例二 单臂路由配置

ENSP配置 实例二 单臂路由配置 单臂路由配置 配置 路由&#xff1a; interface EigabitEthernet0/0/0 ip address 10.0.1.1 24 interface EigabitEthernet0/0/0.1 dot1q termination vid 10 ip address 192.168.1.254 24 arp broadcast enable interface EigabitEthernet0/0/…

用python画数学函数图像教程_Python 绘制你想要的数学函数图形

Python 非常热门&#xff0c;但除非工作需要没有刻意去了解更多&#xff0c;直到有个函数图要绘制&#xff0c;想起了它。结果发现&#xff0c;完全用不着明白什么是编程&#xff0c;就可以使用它完成很多数学函数图的绘制。 通过以下两个步骤&#xff0c;就可以进行数学函数的…

ENSP配置 实例三 静态路由配置

ENSP配置 实例三 静态路由配置 R1配置命令 system-view [R1]interface Ethernet 0/0/0 [R1-Ethernet0/0/0]ip add 192.168.1.254 24 [R1-Ethernet0/0/0]quit [R1]interface tEthernet 0/0/1 [R1-Ethernet0/0/1]ip addr 10.0.12.1 24 [R1-Ethernet0/0/1]quit [R1]ip route-stati…

单片机 c语言 概念题,(C语言版)单片机复习题.doc

单片机复习题一、名词解释1、时序&#xff1a;按照时间顺序显示的对象(或引脚、事件、信息)序列关系。2、指令&#xff1a;CPU用于指挥功能部件完成某一指定动作的指示和命令。3、变量&#xff1a;在程序执行过程中&#xff0c;数值可以发生改变的量称为变量。4、伪指令&#x…

python 散点图 不同颜色_python – pandas – 每个点都有不同颜色图例的散点图

以下方法将根据您的数据框创建颜色列表,然后使用每种颜色的标签绘制一个点&#xff1a; import matplotlib.pyplot as plt import matplotlib.cm as cm import matplotlib.colors as colors import numpy as np import pandas as pd fig, ax plt.subplots() df pd.DataFrame(…

ENSP配置 实例四 默认路由配置

ENSP默认路由配置 1&#xff0c;配置R1路由器 sys ##进入系统视图模式 [Huawei]sys R1 ##修改名字 [R1]int e0/0/0 ##进入接口 [R1-Ethernet0/0/0]ip add 192.168.1.254 24 ##配置ip地址 [R1-Ethernet0/0/0]undo shut ##开启物理接口 [R1-Ethernet0/0/1]int e0/0/1 [R1-Etherne…

套汇算法c语言,在金字塔下实现套利策略的测评

瀑布线是指用异同移动平均线(MACD)指标绘制的移动平均线&#xff0c;用于在证券中生成买入和卖出信号。瀑布线或信号线是交易者用来预测未来价格趋势的MACD指标线的九个周期指数移动平均线(EMA)。虽然九周期EMA是瀑布线的默认设置&#xff0c;但交易者可以调整EMA的长度以适应其…

python数据分析函数大全_python中数据分析常用函数整理

一. apply函数 作用&#xff1a;对 DataFrame 的某行/列应用函数之后&#xff0c;Apply 返回一些值。函数既可以使用默认的&#xff0c;也可以自定义。注意&#xff1a;在第二个输出中应用 head() 函数&#xff0c;因为它包含了很多行。 #创建一个新函数 def num_missing(x): r…

ENSP配置 实例五 RIP配置

ENSP配置 实例五 RIP配置 配置 R1 sy [Huawei]sy R1 [R1]int e0/0/0 [R1-Ethernet0/0/0]ip add 192.168.1.254 24 [R1-Ethernet0/0/0]int e0/0/1 [R1-Ethernet0/0/1]ip add 10.0.12.1 24 [R1-Ethernet0/0/1]q [R1]rip 1 [R1-rip-1]network 192.168.1.0 [R1-rip-1]network 10.0.…

如何用c语言读文件,如何用C语言读写文件

打开文件fopen("需要打开的路径")然后使用fgets函数读取行#include<stdio.h>#include<stdlib.h>#include<string.h>#defineMAX_LINE1024 intmain() { charbuf[MAX_LINE]; /*缓冲区*/ FILE*fp; /*文件指针*/ intlen; /*行字符个数*/if((…

ENSP配置 实例六 OSPF配置

ENSP配置 实例六 OSPF配置 R1 [R1]interface e0/0/0 [R1-Ethernet0/0/0]ip add 192.168.1.254 24 [R1-Ethernet0/0/0]int e0/0/1 [R1-Ethernet0/0/1]ip add 10.0.12.1 24 [R1]ospf 1 router-id 1.1.1.1 [R1-ospf-1]area 0 [R1-ospf-1-area-0.0.0.0]network 192.168.1.0 0.0.0.…

python用户登录_python用户登录系统

本文实例为大家分享了用户登录系统python实现代码&#xff0c;供大家参考&#xff0c;具体内容如下 注意事项&#xff1a; 1、使用python3执行程序。按提示输入1或2&#xff0c;登录或退出程序 2、输入用户名后&#xff0c;如果用户名被锁定及无效用户名&#xff0c;程序会退出…

ENSP配置 实例七 DHCP配置

ENSP配置 实例七 DHCP配置 简单dhcp配置 [R]dhcp enable [R-Ethernet0/0/0]ip add 192.168.1.254 24 [R]ip pool 1 [R-ip-pool-1]network 192.168.1.0 mask 24 [R-ip-pool-1]gateway-list 192.168.1.254 ##配置出口网关地址 [R-ip-pool-1]dns-list 1.1.1.1 [R-Ethernet0/0/0]dh…

python调用cmd命令释放端口_Python——cmd调用(os.system阻塞处理)(多条命令执行)...

原博文 2017-11-14 15:29 − os.system&#xff08;返回值为0,1,2&#xff09;方法 0&#xff1a;成功 1&#xff1a;失败 2&#xff1a;错误 os.system默认阻塞当前程序执行&#xff0c;在cmd命令前加入start可不阻塞当前程序执行。 例如&#xff1a; import os &nbs... 相…

android+引用非+android+工程,[非原创]编译android C++工程找不到exception handle的解决办法...

C工程有时候会进行异常处理&#xff0c;所以在编译的过程中&#xff0c;可能会遇到这种提示:exception handling disabled, use-fexceptions to enable这是编译选项没有支持错误处理导致的。这种情况下要做两处修改&#xff1a;1) Android.mk里面增加&#xff1a;LOCAL_CPPFLAG…

mac抹掉磁盘重装系统未能与服务器取得联系_Mac重装系统不再难:苹果电脑重装系统教程...

我们在使用mac电脑的过程中&#xff0c;因为Mac电脑长时间使用或多或少都可能会出现一些问题&#xff0c;这个时候我们可以选择重新安装系统来解决这些问题。Mac电脑重装系统方法其实很简单&#xff0c;分为两种&#xff0c;一种可以在线重装系统&#xff0c;一种可以将Mac系统…