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引擎,但在动画部分需要使用重定向技术来实现动画复用,考虑到有些项目开发人员没有过这方面的经 ...
随机推荐
- Ubuntu 部署 Node.js 应用
安装Node.js环境 sudo apt-get install nodejs sudo apt-get install npm 对于不同环境依赖 的node_module可以采用以下命令来重新生成 ...
- Virtualbox虚机无法启动因断电
The virtual machine 'nn1' has terminated unexpectedly during startup with exit code 1 (0x1). More ...
- Linux File Recovery Study
Background Today I did stupid things that I went into the ~/Downloads/ and pressed [Alt] + [A] then ...
- 当我学完Python时我学了些什么
本文是本人学完Python后的一遍回顾,加深理解而已,Python大神请过~ 学习Python的这几天来,觉得Python还是比较简单,容易上手的,就基本语法而言,但是有些高级特性掌握起来还是有些难度 ...
- UVALive 4870 Roller Coaster --01背包
题意:过山车有n个区域,一个人有两个值F,D,在每个区域有两种选择: 1.睁眼: F += f[i], D += d[i] 2.闭眼: F = F , D -= K 问在D小于等于一定限度的时 ...
- mysql表复制和修改部分字段
今天在工作中,需要造大量的加数据,1000多条数据如果都是手工输入的话,那么我今天不要干别的了,就造吧! 当时手工操作重复的事情,对程序员来说,是一件很丢人的事情,所以就上网查了一下,需要用到两个知识 ...
- android第一行代码-6.自定义控件的实现
0.假设一个应用中标题栏控件都是共用的,如果每个activity都需要设置button,绑定方法,那代码就会很臃肿.那我们可以自定义控件,然后继承这个控件就行了. 自定义控件为TitleLayout, ...
- Linux内核模块开发基础【转】
本文转载自:http://blog.csdn.net/coding__madman/article/details/51298180 1. 什么是内核模块 内核模块具有以下两个特点:1. 模块本身并不 ...
- 基于jquery的bootstrap在线文本编辑器插件Summernote
Summernote是一个基于jquery的bootstrap超级简单WYSIWYG在线编辑器.Summernote非常的轻量级,大小只有30KB,支持Safari,Chrome,Firefox.Op ...
- 分享 Ionic 开发 Hybrid App 中遇到的问题以及后期发布 iOS/Android 的方方面面
此篇文章主要整理了最近在使用 Ionic 开发 Hybrid App 过程中遇到的一些疑难点以及后期发布生成 iOS 和 Android 版本过程中的种种问题. 文章目录 Ionic 简介和项目需求介 ...