【 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;
}

原文地址:https://www.cnblogs.com/AWCXV/p/9625383.html

时间: 2024-07-30 03:07:26

【 ACM-ICPC 2018 沈阳赛区网络预赛 D】Made In Heaven的相关文章

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

"Oh, There is a bipartite graph.""Make it Fantastic." X wants to check whether a bipartite graph is a fantastic graph. He has two fantastic numbers, and he wants to let all the degrees to between the two boundaries. You can pick up sev

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 two smaller natural numbers. Now lets define a number NN as the supreme number if and only if each number made up of an non-empty subsequence of all

【ACM-ICPC 2018 沈阳赛区网络预赛 I】Lattice&#39;s basics in digital electronics

[链接] 我是链接,点我呀:) [题意] 每个单词的前缀都不同. 不能更明示了... 裸的字典树. 模拟一下.输出一下就ojbk了. [题解] #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(

ACM-ICPC 2018 沈阳赛区网络预赛 F. Fantastic Graph (贪心)

分析:贪心地删边后检查每个点的度即可,这也是正确的做法? #include <bits/stdc++.h> using namespace std; const int MAXN = 1e4+5; struct Edge{ int u,v,next; }edges[MAXN<<2]; int head[MAXN],tot; int deg[MAXN]; void init() { memset(head,-1,sizeof(head)); tot =0 ; memset(deg,0

ACM-ICPC 2018 沈阳赛区网络预赛

A. Gudako and Ritsuka 留坑 B. Call of Accepted 留坑 C. Convex Hull 留坑 D. Made In Heaven 留坑 E. The cake is a lie 留坑 F. Fantastic Graph 留坑 G. Spare Tire 留坑 H. Hamming Weight 留坑 I. Lattice's basics in digital electronics 留坑 J. Ka Chang 留坑 K. Supreme Number

Made In Heaven 2018 沈阳赛区网络预赛 D题

求第k短路 模板题 套模板即可 #include <iostream> #include <cstring> #include <cstdio> #include <cmath> #include <queue> using namespace std; const int maxn=1005; const int maxe=100005; struct State{ int f; // f=g+dis dis表示当前点到终点的最短路径,即之前的

ACM-ICPC 2018 沈阳赛区网络预赛 G. Spare Tire

这题很好啊,好在我没做出来...大概分析了一下,题目大概意思就是求 问所有满足1<=i<=n且i与m互素的ai之和 最开始我们队的做法是类似线性筛的方法去筛所有数,把数筛出来后剩下数即可,但是这样的是时间复杂度十分大,我们需要遍历每个质因 的倍数,这样最坏的复杂度是很大的1e8,因为我们需要把i的倍数筛到1e8,这样肯定不行,那么想想其他办法 我们想到了容斥-----(赛后想到的) 我们可以推处一个公式ai=i*i+i; 那么ai的前n项和Tn=n*(n+1)*(2*n+1)/6+n*(n+1

【ACM-ICPC 2018 沈阳赛区网络预赛 K】Supreme Number

[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 显然每个数字只可能是1,3,5,7 然后如果3,5,7这些数字出现两次以上.显然两个3||5||7都能被11整除. 然后1的话最多能出现两次. 那么也就是说最多只可能有5位数字. 把小于等于5位的全都枚举一遍.求出合法的就好. 如果n>=5位就直接输出那个最大的就Ok. [代码] #include <bits/stdc++.h> #define LL long long #define rep1(i,a,b) for (

ACM-ICPC 2018 沈阳赛区网络预赛-I模拟题啊!!!

垃圾题,题目巨TM长...这题题意就是说给你一个16进制串,让你把每一位转成长度为4的2进制数,并把这些数连接起来,连接完成后,进行奇偶校验,把字符串切割成每个长度为9的字符串,然后计算前8位的 1的个数,,最后一位是校验位,如果1的个数为奇数 那么校验位应该是1,如果1的个数为偶数,那么校验位应该是0,如果满足,就保留验证的8位去掉校验位,否则去掉整个:然后给了M个字符串对应的ASCll,把验证位置留下来的东西,进行和字符串匹配,然后输出N个对应ASCll的字符??? 这题意很绕啊...不过纯