hdu 4360 As long as Binbin loves Sangsang(最短路拆点,5级)

A - As long as Binbin loves Sangsang
Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

Description

Binbin misses Sangsang so much. He wants to meet with Sangsang as soon as possible. Now Binbin downloads a map from ELGOOG.There are N (1<=N<=1,314) cities in the map and these cities are connected by M(0<=M<=13,520) bi-direct roads. Each road has a length L (1<=L<=1,314,520)and is marked using a unique ID, which is a letter fromthe string “LOVE”! Binbin rides a DONKEY, the donkey is so strange that it has to walk in the following sequence ‘L’->’O’->’V’->’E’->’L’->’O’->’V’->’E’->.... etc. Can you tell Binbin how far the donkey has to walk in order to meet with Sangsang? WARNING: Sangsang will feel unhappy if Binbin ride the donkey without a complete”LOVE” string. Binbin is at node 1 and Sangsang is at node N.
 

Input

The first line has an integer T(1<=T<=520), indicate how many test cases bellow. Each test case begins with two integers N, M (N cities marked using an integer from 1…N and M roads). Then following M lines, each line has four variables“U V L letter”, means that there is a road between city U,V(1<=U,V<=N) with length L and the letter marked is‘L’,’O’,’V’ or ‘E’
 

Output

For each test case, output a string 1.  “Case ?: Binbin you disappoint Sangsang again, damn it!” If Binbin failed to meet with Sangsang or the donkey can’t finish a path withthe full “LOVE” string. 2.  “Case ?: Cute Sangsang, Binbin will come with a donkey after travelling ? meters and finding ? LOVE strings at last.” Of cause, the travel distance should be as short as possible, and at the same time the “LOVE” string should be as long as possible.
 

Sample Input

2 4 4 1 2 1 L 2 1 1 O 1 3 1 V 3 4 1 E 4 4 1 2 1 L 2 3 1 O 3 4 1 V 4 1 1 E
 

Sample Output

Case 1: Cute Sangsang, Binbin will come with a donkey after travelling 4 meters and finding 1 LOVE strings at last. Case 2: Binbin you disappoint Sangsang again, damn it!

思路:把一个点拆成末尾是LOVE的四个点,做最短路,当n节点对应的E有值则说明有答案。

深坑一个:n=1 的情况如有LOVE自身环则是可以的,否则不行,其中取最小的。

#include<iostream>
#include<cstring>
#include<queue>
#include<cstdio>
typedef __int64 LL;
using namespace std;
const int mm=2e5+9;
const LL oo=1e18;
class node
{
  public:int v,num,next;LL len;
}e[mm*4];
int head[mm],id[mm],edge;
int cas,n,m;
bool vis[mm][4];
class Dis
{
  public:LL d;int num;
}dis[mm][4];
void data()
{
  memset(head,-1,sizeof(head));edge=0;
}
void add(int u,int v,LL len,int num)
{
  e[edge].v=v;e[edge].len=len;e[edge].num=num;e[edge].next=head[u];head[u]=edge++;
}
void spfa()
{ queue<pair<int,int> >Q;
  pair<int,int>z;
  for(int i=1;i<=n;++i)
    for(int j=0;j<4;++j)
    dis[i][j].d=oo,dis[i][j].num=-1;
  dis[1][3].d=0;int u,v,num;
  Q.push(make_pair(1,3));
  memset(vis,0,sizeof(vis));vis[1][3]=1;
  memset(id,0,sizeof(id));
  while(!Q.empty())
  {
    z=Q.front();Q.pop();
    u=z.first;num=z.second;
    vis[u][num]=0;int vv=(num+1)%4;
    for(int i=head[u];~i;i=e[i].next)
    {
      v=e[i].v;
      if(dis[v][vv].d>=dis[u][num].d+e[i].len&&vv==e[i].num)
      {
        if(dis[v][vv].d==dis[u][num].d+e[i].len&&dis[u][num].num+1<dis[v][vv].num)continue;
        dis[v][vv].d=dis[u][num].d+e[i].len;dis[v][vv].num=dis[u][num].num+1;
        if(!vis[v][vv])
        {
          Q.push(make_pair(v,vv));vis[v][vv]=1;
        }
      }
    }
  }
}
int main()
{ int a,b,d;char z;LL c;
  while(~scanf("%d",&cas))
  {
    for(int ca=1;ca<=cas;++ca)
    { scanf("%d%d",&n,&m);
      data();
      printf("Case %d: ",ca);
      int mygod=0,god=0;
      LL aa=oo,bb=oo,cc=oo,dd=oo;
      for(int i=0;i<m;++i)
      {
        scanf("%d%d%I64d %c",&a,&b,&c,&z);
        if(z=='L')d=0,mygod|=1,aa=min(aa,c);
        else if(z=='O')d=1,mygod|=2,bb=min(bb,c);
        else if(z=='V')d=2,mygod|=4,cc=min(cc,c);
        else if(z=='E')d=3,mygod|=8,dd=min(dd,c);
        add(a,b,c,d);
        add(b,a,c,d);
      }
      spfa();
     //printf("love  %d\n",dis[n][3].num);
      int zzz=dis[n][3].num/4+1;
     // printf("zzz=%d\n",zzz);
     if(n==1)dis[1][3].d=aa+bb+cc+dd;
      if(dis[n][3].d==oo||(n==1&&mygod!=15))printf("Binbin you disappoint Sangsang again, damn it!\n");
      else {printf("Cute Sangsang, Binbin will come with a donkey after travelling %I64d meters and finding ",dis[n][3].d);
       printf("%d LOVE strings at last.\n",zzz);
      }
    }
  }
  return 0;
}

 

 

 

转载于:https://www.cnblogs.com/nealgavin/p/3204687.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值