bzoj 3386: [Usaco2004 Nov]Til the Cows Come Home 带奶牛回家
来源:互联网 发布:女性自慰姿势图解知乎 编辑:程序博客网 时间:2024/05/18 20:05
→题目链接←
终于从silver进化成gold啦!
裸的最短路居然WA了两发...
第一次没看到是无向边...
第二次没看到这道题n m居然是反的...
裸的SPFA
→我的板子←
代码:
#include<iostream>#include<cstdio>#include<algorithm>#include<set>#include<vector>#include<queue>#define inf 233333333using namespace std;struct node{int to,len;node(int x,int y){to=x,len=y;}};int n,m;vector<node>v[20020];bool vis[20020];int dis[20020];void spfa(int s){for(int i=1; i<=n; i++)dis[i]=inf,vis[i]=0;queue<int>q;q.push(s);dis[s]=0;vis[s]=true;while(!q.empty()){int t=q.front();q.pop();for(int i=0; i<v[t].size(); i++){int to=v[t][i].to;int len=v[t][i].len;if(dis[to]>dis[t]+len){dis[to]=dis[t]+len;if(!vis[to])q.push(to),vis[to]=true;}}vis[t]=false;}}int main(){scanf("%d%d",&m,&n);for(int i=0; i<m; i++){int x,y,z;scanf("%d%d%d",&x,&y,&z);v[x].push_back(node(y,z));v[y].push_back(node(x,z));}spfa(n);printf("%d\n",dis[1]);return 0;}
阅读全文
0 0
- bzoj 3386: [Usaco2004 Nov]Til the Cows Come Home 带奶牛回家
- [Poj 2387][Usaco2004 Nov]Til the Cows Come Home 带奶牛回家
- Til the Cows Come Home
- Til the Cows Come Home
- Til the Cows Come Home
- Til the Cows Come Home
- Til the Cows Come Home
- Til the Cows Come Home
- Til the Cows Come Home
- Til the Cows Come Home
- Til the Cows Come Home
- Til the Cows Come Home
- Til the Cows Come Home
- Til the Cows Come Home
- Til the Cows Come Home
- POJ 2387 Til the Cows Come Home
- PKU2387 Til the Cows Come Home
- poj 2387 Til the Cows Come Home
- 告别乱码,针对GBK、UTF-8两种编码的智能URL解码器的java实现
- 在CentOS release 6.8 (Final) 上安装 rabbitmq-server-3.6.12
- Android 怎么生成App的keystore文件
- 【数据平台】sqoop支持hive和mysql互导的基本语句格式
- 网页布局方式
- bzoj 3386: [Usaco2004 Nov]Til the Cows Come Home 带奶牛回家
- Altium Designer多通道设计原理图添加端口
- js中SetInterval与setTimeout用法
- 16. 入口脚本
- TensorFlow使用next_batch()读取/tensorflow.python.framework.errors_impl.InvalidArgumentError: Expect 3 fi
- jupyter noteboook 的 markdown语法
- HDU3037Saving Beans(lucas定理模板)
- R语言树模型
- SpringBoot学习-mybatis逆向生成工具