ACdream 群赛11.10 Problem J: I can't describe the problem

Problem J: I can't describe the problem

Time Limit: 10 Sec   Memory Limit: 128 MB
Submit: 38   Solved: 5
[ Submit][ Status][ Web Board]

Description

Input

Output

Sample Input

2 1 100 21 2 12

Sample Output

3 96

HINT



#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <algorithm>
#include <iostream>
using namespace std;
const int N = 10009;
struct TT{
    int a,b,c;
    int nex;
} re[10009];
int FF[N],C=1;
void FFadd(int v,int a,int b,int c)
{
    re[C].a = a,re[C].b = b;
    re[C].c = c,re[C].nex = FF[v];
    FF[v] = C++;
}
void init()
{
    memset(re,-1,sizeof(re));
    for(int i=2;i<N;i++)
    for(int j=i;j<N;j++)
    {
        int t = i*i+j*j;
        int c = (int)sqrt(t);
        if(i+j+c>=N) break;
        if(c*c==t&&c>=j)
        {
            FFadd(i+j+c,i,j,c);
        }
    }
}
int n,m,p,T;
struct LT{
    int to,nex,dis,hp;
} L[400009];
int F[309],cnt;
void add(int f,int t,int dis,int hp)
{
    L[cnt].dis = dis,L[cnt].nex = F[f];
    L[cnt].hp = hp;L[cnt].to =t;
    F[f] = cnt++;
}
struct nod{
    int to,dis,hp;
    bool operator<(const nod t)const
    {
        return dis>t.dis||(dis==t.dis&&hp<t.hp);
    }
};
queue<nod> que;
int in[309][109];
int dis[309][109];
const int INF = 0x3f3f3f3f;
void solve()
{
    memset(dis,INF,sizeof(dis));
    memset(in,0,sizeof(in));
    while(!que.empty()) que.pop();
    nod e,t;
    e.dis = 0,e.hp = p,e.to = 1;
    que.push(e);
    dis[1][p] = 0;
    while(!que.empty())
    {
        e = que.front();que.pop();
        in[e.to][e.hp] = 0;
        for(int i=F[e.to];i;i=L[i].nex)
        {
            int to = L[i].to;
            t.hp = e.hp - L[i].hp;
            t.to = to;
            if(t.hp<0) continue;
            if(dis[to][t.hp]<=e.dis+L[i].dis) continue;

            dis[to][t.hp] = dis[e.to][e.hp]+L[i].dis;
            t.dis = dis[to][t.hp];
            if(!in[t.to][t.hp])
            que.push(t);
        }
    }
    int mindis = INF,maxhp=-1;
    for(int i=0;i<=p;i++)
    if(dis[T][i]<=mindis)
    {
        mindis = dis[T][i];
        maxhp = i;
    }
    if(mindis!=INF)
    {
        printf("%d %d\n",mindis,maxhp);
        return ;
    }
    printf("-1\n");
}
int main()
{
    freopen("in.txt","r",stdin);
    init();
    while(~scanf("%d%d%d%d",&n,&m,&p,&T))
    {
        memset(F,0,sizeof(F));cnt=1;
        int a,b,c;
        for(int i=0;i<m;i++)
        {
            scanf("%d%d%d",&a,&b,&c);
            add(a,b,c,0);
            for(int j=FF[c];j;j=re[j].nex)
            {
                add(a,b,re[j].a,(re[j].a%10)+1);
                add(a,b,re[j].b,(re[j].b%10)+1);
                add(a,b,re[j].c,(re[j].c%10)+1);
            }
        }
        solve();
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值