【codevs 2273】扬帆远洋大战牧师妹酱
来源:互联网 发布:ubuntu root登录密码 编辑:程序博客网 时间:2024/04/29 06:10
spfa+slf
#include<cstdio>#include<iostream>#include<algorithm>#include<cmath>#include<queue>#include<cstring>using namespace std;int T,R,P,S;const int maxn=200000+5;deque<int>q;bool used[maxn];int first[maxn],next[maxn<<1],tot=0,dis[maxn];struct edge{ int f,t,v;}es[maxn<<1];void build(int f,int t,int v){ es[++tot]=(edge){f,t,v}; next[tot]=first[f]; first[f]=tot;}void read(int &a){ a=0; int h=1; char c=getchar(); while(c<'0'||c>'9') { if(c=='-') h=-1; c=getchar(); } while(c>='0'&&c<='9') { a*=10; a+=c-'0'; c=getchar(); } a*=h;}void spfa(){ while(!q.empty()) { int x=q.front(); q.pop_front(); used[x]=0; for(int i=first[x];i;i=next[i]) { int v=es[i].v,t=es[i].t; if(dis[t]>dis[x]+v) { dis[t]=dis[x]+v; if(!used[t]) { if(q.empty()) q.push_front(t); else if(dis[t]>dis[q.front()] ) q.push_back(t); else q.push_front(t); used[t]=1; } } } }}int main(){ memset(used,0,sizeof(used)); memset(dis,0x3f3f3f3f,sizeof(dis)); int x,y,z; read(T),read(R),read(P),read(S); for(int i=1;i<=R;i++) { read(x),read(y),read(z); build(x,y,z); build(y,x,z); } for(int i=1;i<=P;i++) { read(x),read(y),read(z); build(x,y,z); } q.push_front(S); used[S]=1; dis[S]=0; spfa(); int cnt=0; for(int i=1;i<=T;i++) { if(dis[i]==0x3f3f3f3f) printf("Need Teleport To Repair\n"),cnt++; else printf("%d\n",dis[i]); } printf("%d\n",cnt); return 0;}
阅读全文
0 0
- 【codevs 2273】扬帆远洋大战牧师妹酱
- 【codevs 2273】扬帆远洋大战牧师妹酱
- codevs 2273 扬帆远洋大战牧师妹酱 SPFA双端队列优化
- 【codevs】2273 扬帆远洋大战牧师妹酱 SPFA slf 优化
- codevs 2273 扬帆远洋大战牧师妹酱(spfa+slf)
- codevs 2273 扬帆远洋大战牧师妹酱(spfa+slf优化)
- USACO 扬帆远洋大战牧师妹酱
- CODE[VS] 2273 USACO 扬帆远洋大战牧师妹酱 双端队列优化SPFA
- 扬帆,起航!
- 扬帆,前进!
- 扬帆起航
- 扬帆起航
- 扬帆,起航
- 扬帆,起航!
- 扬帆起航
- 扬帆起航
- 扬帆起航
- 扬帆起航
- Implementing a Simple Calculator Using Antlr
- 从零学习嵌入式
- PHP 函数定义
- 北京赛区(2017)网络赛 之 Minimum(线段树)
- Ajax -- 发送 GET 请求
- 【codevs 2273】扬帆远洋大战牧师妹酱
- scrapy爬虫多次启动异常
- 中国气象台API(2017.09)
- 让yii2能够处理postman发来的json数据
- 73. Set Matrix Zeroes
- Yii 错误Unable to locate message source for category 'common;
- MQL5-构造函数和析构函数
- Java9新特性之HTTP2和REPL
- Linux命令 zgrep