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引擎,但在动画部分需要使用重定向技术来实现动画复用,考虑到有些项目开发人员没有过这方面的经 ...
随机推荐
- python 利用 setup.py 手动安装django_chartit
手动安装django_chartit库 1 下载压缩包 2 解压到python安装目录下,文件夹名为django_chartit,并检查文件夹下是否有setup.py文件 3 在cmd中进入djang ...
- WPF系列-CheckBox
自定义样式1 效果: 代码: <!-- CheckBox的样式 --> <Style TargetType="{x:Type CheckBox}"> < ...
- Selenium-java-TestNg-的运行
package com.day.www; import org.testng.annotations.AfterClass;import org.testng.annotations.AfterMet ...
- __definedGetter\Setter__的一些想法
__definedGetter\Setter__ 是JS5在创建对象后内置的方法,用于在读写对象属性的时候执行的方法. zhangmingzhi.__defineSetter__('age',func ...
- JS组件系列——Bootstrap寒冬暖身篇:弹出框和提示框效果以及代码展示
前言:对于Web开发人员,弹出框和提示框的使用肯定不会陌生,比如常见的表格新增和编辑功能,一般常见的主要有两种处理方式:行内编辑和弹出框编辑.在增加用户体验方面,弹出框和提示框起着重要的作用,如果你的 ...
- .Net配置中心-服务端/客户端
服务端 管理应用,一个应用对应一个站点. 管理应用下的配置. 在保存配置的时候,会更新应用的版本号. 客服端 其他站点引用DLL,并在Global的App_Start中调用ConfigCenter的I ...
- Win10 UWP开发实现Bing翻译
微软在WP上的发展从原来的Win7到Win8,Win8.1,到现在的Win10 UWP,什么是UWP,UWP即Windows 10 中的Universal Windows Platform简称.即Wi ...
- SQLite剖析之异步IO模式、共享缓存模式和解锁通知
1.异步I/O模式 通常,当SQLite写一个数据库文件时,会等待,直到写操作完成,然后控制返回到调用程序.相比于CPU操作,写文件系统是非常耗时的,这是一个性能瓶颈.异步I/O后端是SQLit ...
- Android四大组件之—— 使用服务进行后台操作
什么是服务 服务是一个没有可视化界面的组件,它可以在后台长期运行并进行各种操作. 服务的创建 我们只需要继承Service类并实现相应的方法即可创建服务 要想启动服务,还得在AndroidManife ...
- mysql select
select 查询: 赋值:赋值不能应用在where中,因为where操作的是磁盘上的文件,可以应用在having筛选中. 例:select (market_price-shop_price) as ...