【链接】 我是链接,点我呀:)

【题意】

在这里输入题意

【题解】

点可以重复走的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的更多相关文章

  1. 图上两点之间的第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 ...

  2. ACM-ICPC 2018 沈阳赛区网络预赛 D Made In Heaven(第k短路,A*算法)

    https://nanti.jisuanke.com/t/31445 题意 能否在t时间内把第k短路走完. 分析 A*算法板子. #include <iostream> #include ...

  3. ACM-ICPC 2018 沈阳赛区网络预赛 D. Made In Heaven(第k短路模板)

    求第k短路模板 先逆向求每个点到终点的距离,再用dij算法,不会超时(虽然还没搞明白为啥... #include<iostream> #include<cstdio> #inc ...

  4. ACM-ICPC 2018 沈阳赛区网络预赛 D. Made In Heaven(约束第K短路)

    题意:求11到nn的第kk短的路径长度,如果超过TT输出Whitesnake!Whitesnake!,否则输出yareyaredawayareyaredawa. 好无以为 , 这就是一道模板题, 当是 ...

  5. ACM-ICPC 2018 沈阳赛区网络预赛 K Supreme Number(规律)

    https://nanti.jisuanke.com/t/31452 题意 给出一个n (2 ≤ N ≤ 10100 ),找到最接近且小于n的一个数,这个数需要满足每位上的数字构成的集合的每个非空子集 ...

  6. 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 ...

  7. 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. ...

  8. 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 ...

  9. 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 ...

  10. ACM-ICPC 2018 沈阳赛区网络预赛 F. Fantastic Graph

    "Oh, There is a bipartite graph.""Make it Fantastic." X wants to check whether a ...

随机推荐

  1. 打造终端下mutt收发邮件环境(fbterm,fetchmail,msmtp,procmail,mutt)

    实现mutt下收发邮件须要安装,mutt,fbterm,fetchmail,msmtp,procmail 下面是各配置文件.在home文件夹下,隐私信息有马赛克... .muttrc : 当中Mail ...

  2. 【c语言】 模拟实现库函数的atoi函数

    // 模拟实现库函数的atoi函数 #include <stdio.h> #include <string.h> #include <assert.h> #incl ...

  3. swing Jlable中存放变量显示问题

    java swing 学习 在做一个ATM机系统小案例中.碰到JLable中存放变量,变量发生改变.而JLable中还是显示原来的值,网上寻找答案,用updateUI()和revalidate();方 ...

  4. 问题1-The type java.lang.String cannot be resolved. It is indirectly referenced from required .class files

    问题一:The type java.lang.String cannot be resolved. It is indirectly referenced from required .class f ...

  5. Cocos2d-X直接使用OpenGL接口

    Cocos2d-X是基于基于OpenGL ES的2D游戏引擎,所以Cocos2d-X能够直接使用OpenGL接口 首先建立一个Draw类,用于处理OpenGL接口 在Draw.h中加入以下的代码 #i ...

  6. 每天一个linux命令(01):ifconfig命令

    许多windows非常熟悉ipconfig命令行工具,它被用来获取网络接口配置信息并对此进行修改.Linux系统拥有一个类似的工具,也就是ifconfig(interfaces config).通常需 ...

  7. devenv.exe 编译Solution

    Build https://docs.microsoft.com/en-us/visualstudio/ide/reference/build-devenv-exe Builds a solution ...

  8. ASP.NET Razor - C# Variables

    http://www.w3schools.com/aspnet/razor_cs_variables.asp Variables are named entities used to store da ...

  9. Windows下Vim主题变更

    默认的好丑! 主题位置. 修改配置文件. 添加主题设置. 新的主题,很高端大气. set fileencodings=utf8,ucs-bom,cp936,big set fileencoding=u ...

  10. 我的spark python 决策树实例

    from numpy import array from pyspark.mllib.regression import LabeledPoint from pyspark.mllib.tree im ...