codevs2645 Spore
/*
spfa + 判环
*/
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
#include<queue>
#define ll long long
using namespace std;
const int maxn = ;
const ll inf = 987654321234LL;
struct edge{
int v;
int w;
int nxt;
}e[maxn*];
int n,m;
int cnt,head[maxn],flag,vis[maxn],rd[maxn];
ll dis[maxn];
ll read(){
char ch=getchar();
ll x=,f=;
while(!(ch>=''&&ch<='')){if(ch=='-')f=-;ch=getchar();};
while(ch>=''&&ch<=''){x=x*+(ch-'');ch=getchar();};
return x*f;
}
void ins(int u,int v,int w){
cnt++;
e[cnt].v = v;
e[cnt].w = w;
e[cnt].nxt = head[u];
head[u] = cnt;
}
bool spfa(){
for(int i = ;i <= n;i++){
dis[i] = inf;
rd[i] = ;
}
dis[] = ;
flag++;
queue<int> q;
int now,to;
q.push();
vis[] = flag;
rd[] = ;
while(!q.empty()){
now = q.front();
q.pop();
for(int i = head[now];i;i = e[i].nxt){
to = e[i].v;
if(dis[to] > dis[now] + e[i].w){
dis[to] = dis[now] + e[i].w;
if(vis[to] != flag){
vis[to] = flag;
q.push(to);
rd[to]++;
if(rd[to] > n) return false;
}
}
}
vis[now] = ;
}
if(dis[n] >= inf) return false;
else return true;
}
int main(){
while(){
cnt = ;
n = read();
m = read();
if(!n && !m) break;
for(int i = ;i <= n;i++) head[i] = ;
int g1,g2,c1,c2;
for(int i = ;i <= m;i++){
g1 = read();
g2 = read();
c1 = read();
c2 = read();
ins(g1,g2,c1);
ins(g2,g1,c2);
}
if(spfa()) cout<<dis[n]<<endl;
else cout<<"No such path"<<endl;
}
return ;
}
codevs2645 Spore的更多相关文章
- codevs——2645 Spore
2645 Spore 时间限制: 1 s 空间限制: 32000 KB 题目等级 : 钻石 Diamond 题解 题目描述 Description 某陈和某Y 最近对一个游戏着迷.那 ...
- 【最短路】【spfa】CODEVS 2645 Spore
spfa最短路+判负权回路(是否某个点入队超过n次). #include<cstdio> #include<queue> #include<cstring> usi ...
- 使用行为树(Behavior Tree)实现游戏AI
——————————————————————— 谈到游戏AI,很明显智能体拥有的知识条目越多,便显得更智能,但维护庞大数量的知识条目是个噩梦:使用有限状态机(FSM),分层有限状态机(HFSM),决策 ...
- OpenCV码源笔记——Decision Tree决策树
来自OpenCV2.3.1 sample/c/mushroom.cpp 1.首先读入agaricus-lepiota.data的训练样本. 样本中第一项是e或p代表有毒或无毒的标志位:其他是特征,可以 ...
- AI 行为树
by AKara 2010-12-09 @ http://blog.csdn.net/akara @ akarachen(at)gmail.com @weibo.com/akaras 谈到游戏AI,很 ...
- [luogu P2391] 白雪皑皑
[luogu P2391] 白雪皑皑 题目背景 “柴门闻犬吠,风雪夜归人”,冬天,不期而至.千里冰封,万里雪飘.空中刮起了鸭毛大雪.雪花纷纷,降落人间. 美能量星球(pty 在 spore 上的一个殖 ...
- 日常英语---十二、MapleStory/Monsters/Level 1-10(Horny Mushroom)
日常英语---十二.MapleStory/Monsters/Level 1-10(Horny Mushroom) 一.总结 一句话总结: horny-['hɔːnɪ]-adj.角的 Another m ...
- 智课雅思词汇---十七、前綴il-, in-, ir-, im-有什麼關係
智课雅思词汇---十七.前綴il-, in-, ir-, im-有什麼關係 一.总结 一句话总结:这几个长得非常像,并且意思也非常像 1.前綴il-, in-, ir-, im-是什麼意思? 前缀:i ...
- 动画重定向技术分析和Unity中的应用
http://www.jianshu.com/p/6e9ba1b9c99e 因为一些手游项目需要使用Unity引擎,但在动画部分需要使用重定向技术来实现动画复用,考虑到有些项目开发人员没有过这方面的经 ...
随机推荐
- Excel自文本导入内容时如何做到单元格内换行
前言:今天在处理数据的时候,在数据库中用到了\n换行符号,目的是在同表格内做到数据多行显示,比如 字段名1 字段名2 字段名3 1 数据一行 数据二行 数据三行 例子是在sql查询后的结果 ...
- 【WPF系列】基础 PasswordBox
参考 How to bind to a PasswordBox in MVVM
- ADO.net 连接字符串中的 |DataDirectory| 是什么
|DataDirectory| does not come from config settings; you're mixing up three different things: Configu ...
- NYOJ 451
光棍节的快乐 描述 光棍们,今天是光棍节.聪明的NS想到了一个活动来丰富这个光棍节. 规则如下: 每个光棍在一个纸条上写一个自己心仪女生的名字,然后把这些纸条装进一个盒子里,这些光 棍依次抽取一张纸条 ...
- iOS Photos.framework框架
链接: iOS8.0 使用Photos.framework对相册的常用操作 iOS AssetsLibrary和Photos的使用总结: 权限及相册的获取 iOS 开发之照片框架详解 iOS Asse ...
- CWMP开源代码研究2——easycwmp安装和学习
声明:本文是对开源程序代码学习和研究,严禁用于商业目的. 如有任何问题,欢迎和我交流.(企鹅号:408797506) 本文所有笔记和代码可以到csdn下载:http://download.csdn.n ...
- Python-13-堡垒机开发
今天主要是熟悉堡垒机开发流程.
- 熟悉MyEclipse
资源网址:http://www.myeclipsecn.com/learningcenter/ 20151126 [从这里开始]量身打造自己的MyEclipse(多图) 主要讲在MyEclipse里面 ...
- 关于vs2012、tfs2012、windows server 2008r2一些记录
windows server 2008r2安装在虚拟机中,装有tfs2012.sql server 2012. 物理机装有vs2012 1.用vs2012连接tfs时候,会让输入一个有效用户.输入的是 ...
- mysql的sql_mode模式
在oracle或sqlserver中,如果某个表的字段设置成not null,insert或update时不给这个字段赋值,比如下面这样: 表t_test(id,name)中id,name都不允许为空 ...