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引擎,但在动画部分需要使用重定向技术来实现动画复用,考虑到有些项目开发人员没有过这方面的经 ...
随机推荐
- Csharp--Read Csv file to DataTable
在网上找的资料都不怎么好使,许多代码一看就知道根本没有考虑全面. 最后找到一个好用的,在codeproject上,这位老兄写成了一个framework,太重了. http://www.codeproj ...
- Python学习记录day6
title: Python学习记录day6 tags: python author: Chinge Yang date: 2016-12-03 --- Python学习记录day6 @(学习)[pyt ...
- 读 [The Root of Lisp]
首先,在对 Lisp 有一丢丢的了解下读这篇文章会大大激发你学下去的欲望.之后可以看作者的著作<ANSI Common Lisp>. 想要体会一下 Lisp 的强大,本文是不二之选. Co ...
- jquery的回调对象Callbacks详解
Callbacks : 对函数的统一管理 Callbacks的options参数接受4个属性,分别是once : 只执行一次momery : 记忆stopOnFalse : 强制退出循环unique ...
- android第一行代码-3.activity之间的调用跟数据传递
前面两节所有应用都是同一个activity中的,是时候讲activity之间交互的操作了,此后会涉及到intent这个概念,这也算一个新的里程碑开始. 主要内容包括intent的使用,以及activi ...
- iOS 3D Touch实践
本文主要讲解3DTouch各种场景下的开发方法,开发主屏幕应用icon上的快捷选项标签(Home Screen Quick Actions),静态设置 UIApplicationShortcutIte ...
- JS禁止选中文本方法
if (typeof(element.onselectstart) != "undefined") { // IE下禁止元素被选取 element.onselectstart = ...
- linux下,Python 多版本共存,及Pip,Easy_install 安装扩展包
Python2与Python3共存 安装Python3后,建立ln,使用Python(Python2),Python3 来区分两个版本 使用sudo apt-get install python3-s ...
- 通过实战理解C语言精要——函数篇
前言 本篇博客是对C语言函数部分的重点内容和细枝末节通过实战得到的经验的总结精炼,不涵盖C语言函数的全部内容,所有提炼内容均来自提炼与实战,阅读需要对函数部分有一定基础,可用于对C语言函数的理解提 ...
- python脚本实现scp上传下载功能
普通版本 1 # -*- coding:utf-8 -*- import paramiko,os,sys,time port = 22 user = 'root' def ssh_scp_put(ip ...