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

来源:互联网 发布:阿里云的机房 编辑:程序博客网 时间:2024/05/01 04:22

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


原创粉丝点击