kuangbin_ShortPath E (POJ 1860)
2015-12-26 09:32
597 查看
第一次做判环 然后RE了五次 死在了奇怪的点
memset(vis, 0, sizeof dis);
memset(dis, 0, sizeof vis);
什么鬼?? 什么鬼??
其实代码本身还是不难的 就是spfa另外开个数组记录入队次数
spfa不用写cmp真是太好了 operator什么的真的搞不清
memset(vis, 0, sizeof dis);
memset(dis, 0, sizeof vis);
什么鬼?? 什么鬼??
其实代码本身还是不难的 就是spfa另外开个数组记录入队次数
spfa不用写cmp真是太好了 operator什么的真的搞不清
#include <iostream> #include <string> #include <cstdio> #include <cmath> #include <cstring> #include <queue> #include <map> #include <vector> #include <set> #include <algorithm> #define INF 0x3F3F3F3F using namespace std; struct Node{ double c;//commission double r;//rate int point; int next; }node[1010]; int size, head[1010]; int n, m, s; double sq; void add(int from, int to, double rate, double commission) { node[size].r = rate; node[size].c = commission; node[size].point = to; node[size].next = head[from]; head[from] = size++; } bool spfa() { double dis[1010]; int count[1010]; bool vis[1010]; memset(count, 0, sizeof count); memset(dis, 0, sizeof dis); memset(vis, false, sizeof vis); queue<int> q; q.push(s); dis[s] = sq; vis[s] = true; while(!q.empty()){ int u = q.front(); q.pop(); vis[u] = false; for(int i = head[u]; ~i; i = node[i].next){ int j = node[i].point; if(dis[j] < (dis[u] - node[i].c) * node[i].r){ dis[j] = (dis[u] - node[i].c) * node[i].r; if(!vis[j]){ q.push(j); vis[j] = true; count[j]++; if(count[j] > n) return true; } } } } return false; } int main() { while(~scanf("%d%d%d%lf", &n, &m, &s, &sq)){ size = 0; memset(head, -1, sizeof head); while(m--){ int from, to; double r1, c1, r2, c2; scanf("%d%d%lf%lf%lf%lf", &from, &to, &r1, &c1, &r2, &c2); add(from, to, r1, c1); add(to, from, r2, c2); } if(spfa()) puts("YES"); else puts("NO"); } return 0; }
相关文章推荐
- PowerDesigner生成PHP代码 UML
- [看书日记20151226]MeasureSpec和LayoutParams的对应关系 , View的工作流程
- ThinkPHP 3.2 整合PHPmailer 发送SMTP邮件
- 81、交换机配置实验之NTP
- pureftpd 启用系统帐户登录
- 分享50个提高PHP执行效率的技巧
- thinkPHP中验证码的简单使用方法
- thinkPHP中分页用法实例分析
- thinkPHP下ueditor的使用方法详解
- thinkPHP下的widget扩展用法实例分析
- yii用户注册表单验证实例
- weiphp执行的流程
- PHP正则表达式教程
- kuangbin_ShortPath D (POJ 3268)
- php开发(TP框架使用)
- ubuntu14.04安装TFTP服务
- [PHP][TP]数据库查询语句
- php 赋值原理详解
- phpstorm 快捷键
- php解析html类