【 ACM-ICPC 2018 沈阳赛区网络预赛 D】Made In Heaven
【链接】 我是链接,点我呀:)
【题意】
在这里输入题意
【题解】
点可以重复走的k短路。
【代码】
#include <bits/stdc++.h>
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define all(x) x.begin(),x.end()
#define pb push_back
#define lson l,mid,rt<<1
#define ri(x) scanf("%d",&x)
#define rl(x) scanf("%lld",&x)
#define rs(x) scanf("%s",x)
#define rson mid+1,r,rt<<1|1
const double pi = acos(-1);
const int dx[4] = {0,0,1,-1};
const int dy[4] = {1,-1,0,0};
using namespace std;
#define CL(a,num) memset(a,num,sizeof(a));
#define inf 9999999
#define eps 1e-6
const int N = 1050;
struct node
{
int u;
int w;
node (int uu,int ww):u(uu),w(ww){}
};
vector<node>g[N],rg[N];
int dis[N],vis[N],tol[N];
struct cnode
{
int u;
int len;
cnode (int uu,int ww):u(uu),len(ww){}
friend bool operator < (cnode a,cnode b)
{
return a.len+dis[a.u]>b.len+dis[b.u];
}
};
int n,m,s,t,k;
int T;
int A_star(int s)
{
if(dis[s]==inf)return -1;
priority_queue<cnode>que;
CL(tol,0);
que.push(cnode(s,0));
while(!que.empty())
{
cnode a=que.top();que.pop();
int u=a.u;
int len=a.len;
tol[u]++;
if(tol[t]==k)return len;
rep1(i,0,(int)g[u].size()-1){
node b=g[u][i];
int v=b.u;
que.push(cnode(v,len+b.w));
}
}
return -1;
}
void spfa(int s)
{
int i;
for(i=0;i<=n;i++)
{
dis[i]=inf;
vis[i]=0;
}
dis[s]=0;
queue<int>que;
que.push(s);
while(!que.empty())
{
int u=que.front();que.pop();
vis[u]=0;
//if (dis[u]>T) continue;
rep1(i,0,(int)rg[u].size()-1){
node b=rg[u][i];
int v=b.u;
if(dis[v]>dis[u]+b.w)
{
dis[v]=dis[u]+b.w;
if(!vis[v])
{
vis[v]=1;
que.push(v);
}
}
}
}
}
int main()
{
while(~scanf("%d%d",&n,&m))
{
int x,y,z;
rep1(i,0,n){
g[i].clear();rg[i].clear();
}
ri(s);ri(t);ri(k);ri(T);
rep1(i,0,m-1){
ri(x);ri(y);ri(z);
g[x].push_back(node(y,z));rg[y].push_back(node(x,z));
}
spfa(t);
int ans=A_star(s);
if (ans==-1 || ans>T){
puts("Whitesnake!");
}else{
puts("yareyaredawa");
}
}
return 0;
}
【 ACM-ICPC 2018 沈阳赛区网络预赛 D】Made In Heaven的更多相关文章
- 图上两点之间的第k最短路径的长度 ACM-ICPC 2018 沈阳赛区网络预赛 D. Made In Heaven
131072K One day in the jail, F·F invites Jolyne Kujo (JOJO in brief) to play tennis with her. Howe ...
- ACM-ICPC 2018 沈阳赛区网络预赛 D Made In Heaven(第k短路,A*算法)
https://nanti.jisuanke.com/t/31445 题意 能否在t时间内把第k短路走完. 分析 A*算法板子. #include <iostream> #include ...
- ACM-ICPC 2018 沈阳赛区网络预赛 D. Made In Heaven(第k短路模板)
求第k短路模板 先逆向求每个点到终点的距离,再用dij算法,不会超时(虽然还没搞明白为啥... #include<iostream> #include<cstdio> #inc ...
- ACM-ICPC 2018 沈阳赛区网络预赛 D. Made In Heaven(约束第K短路)
题意:求11到nn的第kk短的路径长度,如果超过TT输出Whitesnake!Whitesnake!,否则输出yareyaredawayareyaredawa. 好无以为 , 这就是一道模板题, 当是 ...
- ACM-ICPC 2018 沈阳赛区网络预赛 K Supreme Number(规律)
https://nanti.jisuanke.com/t/31452 题意 给出一个n (2 ≤ N ≤ 10100 ),找到最接近且小于n的一个数,这个数需要满足每位上的数字构成的集合的每个非空子集 ...
- ACM-ICPC 2018 沈阳赛区网络预赛-K:Supreme Number
Supreme Number A prime number (or a prime) is a natural number greater than 11 that cannot be formed ...
- ACM-ICPC 2018 沈阳赛区网络预赛-D:Made In Heaven(K短路+A*模板)
Made In Heaven One day in the jail, F·F invites Jolyne Kujo (JOJO in brief) to play tennis with her. ...
- ACM-ICPC 2018 沈阳赛区网络预赛 J树分块
J. Ka Chang Given a rooted tree ( the root is node 11 ) of NN nodes. Initially, each node has zero p ...
- ACM-ICPC 2018 沈阳赛区网络预赛 K. Supreme Number
A prime number (or a prime) is a natural number greater than 11 that cannot be formed by multiplying ...
- ACM-ICPC 2018 沈阳赛区网络预赛 F. Fantastic Graph
"Oh, There is a bipartite graph.""Make it Fantastic." X wants to check whether a ...
随机推荐
- [Javascript] IntersectionObserver -- Lazy Load Images on a Website
When it comes to websites performance is king. How long it takes for a page to load can mean the dif ...
- leetCode 20.Valid Parentheses (有效的括号) 解题思路和方法
Valid Parentheses Given a string containing just the characters '(', ')', '{', '}', '[' and ']', de ...
- oc22--多态
// // Animal.h #import <Foundation/Foundation.h> @interface Animal : NSObject { int _age; } - ...
- 深入Session
早上考虑Spring MVC和Structs2项目共用时看到一个问题,如何保持session一致?Session是怎么样被服务器处理的呢,Spring MVC中是如何封装处理Session并在不同请求 ...
- 院校-国外-美国:斯坦福大学( Stanford)
ylbtech-院校-国外-美国:斯坦福大学( Stanford) 斯坦福大学(Stanford University),全名小利兰·斯坦福大学(Leland Stanford Junior Univ ...
- 第一个"hello python!"
第一个python程序"hello python!" 首先打开我们的编辑器,在安装好python后,直接在windows快捷方式里,输入IDLE,就可以看到我们的python默认自 ...
- IDEA中Lombok插件的安装与使用
背景 我们在开发过程中,通常都会定义大量的JavaBean,然后通过IDE去生成其属性的构造器.getter.setter.equals.hashcode.toString方法,当要对某个属性进行 ...
- Codeforces Round #198 (Div. 2)A,B题解
Codeforces Round #198 (Div. 2) 昨天看到奋斗群的群赛,好奇的去做了一下, 大概花了3个小时Ak,我大概可以退役了吧 那下面来稍微总结一下 A. The Wall Iahu ...
- C - Twins(贪心)
Problem description Imagine that you have a twin brother or sister. Having another person that looks ...
- guice整合struts2,guice的使用(八)
平时我们习惯用了spring整合struts2,今天我们就来见识一下guice整合struts2吧. 看web.xml配置: <?xml version="1.0" enco ...