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

【题意】

在这里输入题意

【题解】

点可以重复走的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. [Angular] Increasing Performance by using Pipe

    For example you make a function to get rating; getRating(score: number): string { let rating: string ...

  2. 【Java】基本类型和引用类型(值传递)

    [关键词] [问题] · 加深对基本类型和引用类型的理解: [效果图] [分析] 參见最后的[參考资料] [解决方式] [代码] public void test() throws Exception ...

  3. Android动态部署五:怎样从插件apk中启动Service

    转载请注明出处:http://blog.csdn.net/ximsfei/article/details/51072332 github地址:https://github.com/ximsfei/Dy ...

  4. 51-nod -1284 2 3 5 7的倍数

    1284 . 2 3 5 7的倍数 基准时间限制:1 秒 空间限制:65536 KB 分值: 5 给出一个数N,求1至N中,有多少个数不是2 3 5 7的倍数. 比如N = 10,仅仅有1不是2 3 ...

  5. zoj3822 Domination 概率dp --- 2014 ACM-ICPC Asia Mudanjiang Regional Contest

    一个n行m列的棋盘,每次能够放一个棋子.问要使得棋盘的每行每列都至少有一个棋子 须要的放棋子次数的期望. dp[i][j][k]表示用了k个棋子共能占据棋盘的i行j列的概率. 那么对于每一颗棋子,在现 ...

  6. luogu1403 约数研究

    题目大意:给出n,求1~n所有数的约数个数的和. 将“1~n所有数的约数”的模板中的factor[i*j].push_back(i)改为FactorCnt[i*j]++,最后再求一次和即可. #inc ...

  7. nyoj--973--天下第一(SPFA判断负环)

    天下第一 时间限制:1000 ms  |  内存限制:65535 KB 难度:3 描述 AC_Grazy一直对江湖羡慕不已,向往着大碗吃肉大碗喝酒的豪情,但是"人在江湖漂,怎能 不挨刀&qu ...

  8. H3BPM实例分享——金额规则大写

    v\:* {behavior:url(#default#VML);} o\:* {behavior:url(#default#VML);} w\:* {behavior:url(#default#VM ...

  9. Cracking the Coding Interview 5.2

    Given a(decimal -e.g. 3.72)number that is passed in as a string, print the binary representation. If ...

  10. js编写时间选择框

    效果图: 代码: 新建js:WdatePicker.js /* * My97 DatePicker 4.72 Release * License: http://www.my97.net/dp/lic ...