题意很好理解。

由于点是可以重复到达的,但可能每次经过路径的标志不一样,所以可以设每个点有四种状态"L”,'O','V','E'。然后按这些状态进行求最短路,当然是SPFA了。

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <cstring>
#define LL __int64
using namespace std;
const LL inf=1ll<<58;
LL dis[1350][4];
int cnt[1350][4];
LL n1j[4];
int n,m;
int hed,tail;
int que[5350000];
bool inq[1350];
struct Edge{
int u,v,nxt;
LL c;
char t;
}edge[30000];
int tot;
int head[1350]; void addedge(int u,int v,int c,char t){
edge[tot].u=u;
edge[tot].v=v;
edge[tot].c=c;
edge[tot].t=t;
edge[tot].nxt=head[u];
head[u]=tot++;
} int isure(char c){
if(c=='L') return 0;
else if (c=='O') return 1;
else if(c=='V') return 2;
return 3;
} void spfa(){
hed=tail=0;
memset(inq,false,sizeof(inq));
inq[1]=true;
que[tail++]=1;
while(hed<tail){
int u=que[hed++]; inq[u]=false;
for(int e=head[u];e!=-1;e=edge[e].nxt){
int v=edge[e].v,nt=isure(edge[e].t);
if(dis[u][nt]+edge[e].c<=dis[v][(nt+1)%4]){
bool flag=false;
if(dis[v][(nt+1)%4]>dis[u][nt]+edge[e].c){
dis[v][(nt+1)%4]=dis[u][nt]+edge[e].c;
cnt[v][(nt+1)%4]=cnt[u][nt]+1;
flag=true;
}
else{
if(cnt[v][(nt+1)%4]<cnt[u][nt]+1){
cnt[v][(nt+1)%4]=cnt[u][nt]+1;
flag=true;
}
else continue;
}
if(flag){
if(!inq[v]){
inq[v]=true;
que[tail++]=v;
}
}
}
}
}
if(dis[n][0]==inf||cnt[n][0]==0){
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 %d LOVE strings at last.\n",dis[n][0],cnt[n][0]/4); } int main(){
int T,u,v,c; char t;
int icase=0;
scanf("%d",&T);
while(T--){
scanf("%d%d",&n,&m);
tot=0;
memset(head,-1,sizeof(head));
n1j[0]=n1j[1]=n1j[2]=n1j[3]=inf;
for(int i=0;i<m;i++){
scanf("%d %d %d %c",&u,&v,&c,&t);
if(n==1){
int f=isure(t);
n1j[f]=min(n1j[f],(LL)c);
continue;
}
addedge(u,v,c,t);
addedge(v,u,c,t);
}
printf("Case %d: ",++icase);
LL leng=0;
for(int i=0;i<4;i++){
leng+=n1j[i];
}
if(n==1){
if(leng>=inf){ 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 1 LOVE strings at last.\n",leng);
}
continue;
} for(int i=1;i<=n;i++){
dis[i][0]=dis[i][1]=dis[i][2]=dis[i][3]=inf;
cnt[i][0]=cnt[i][1]=cnt[i][2]=cnt[i][3]=0;
}
dis[1][0]=0;
spfa();
}
return 0;
}

  

HDU 4360的更多相关文章

  1. HDU 4360 As long as Binbin loves Sangsang spfa

    题意: 给定n个点m条边的无向图 每次必须沿着LOVE走,到终点时必须是完整的LOVE,且至少走出一个LOVE, 问这样情况下最短路是多少,在一样短情况下最多的LOVE个数是多少. 有自环. #inc ...

  2. 8-12-COMPETITION

    链接:最短路 A.HDU 2544    最短路 算是最基础的题目了吧.............我采用的是Dijkstra算法....... 代码: #include <iostream> ...

  3. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  4. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

  5. hdu 4859 海岸线 Bestcoder Round 1

    http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...

  6. HDU 4569 Special equations(取模)

    Special equations Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

  7. HDU 4006The kth great number(K大数 +小顶堆)

    The kth great number Time Limit:1000MS     Memory Limit:65768KB     64bit IO Format:%I64d & %I64 ...

  8. HDU 1796How many integers can you find(容斥原理)

    How many integers can you find Time Limit:5000MS     Memory Limit:32768KB     64bit IO Format:%I64d ...

  9. hdu 4481 Time travel(高斯求期望)(转)

    (转)http://blog.csdn.net/u013081425/article/details/39240021 http://acm.hdu.edu.cn/showproblem.php?pi ...

随机推荐

  1. php微信开放平台--第三方网页微信扫码登录(OAuth2.0)

    第一.OAuth2.0 OAuth(开放授权)是一个开放标准,允许用户让第三方应用访问该用户在某一网站上存储的私密的资源(如照片,视频,联系人列表),而无需将用户名和密码提供给第三方应用. 允许用户提 ...

  2. 个人作业 - Alpha 项目测试

    写在前面 课程链接:https://edu.cnblogs.com/campus/xnsy/SoftwareEngineeringClass2 作业要求:https://edu.cnblogs.com ...

  3. SPOJ 1811 SAM 初探

    思路: 一个串建SAM 另一个串在SAM上跑 //By SiriusRen #include <cstdio> #include <cstring> #include < ...

  4. c++枚举变量初始值

    #include <iostream> // std::cout, std::boolalpha, std::noboolalpha enum foo { c = -1, a = 1, b ...

  5. C# Task多线程

    来自Eleven老师示例 private void btnTask_Click(object sender, EventArgs e) { Console.WriteLine(); Console.W ...

  6. post发送数据 mypost input 改变事件

    //name=或者 "&name=" + "123" + "&data=" + "slice" (可以获 ...

  7. Cesium学习笔记(九):导入3D模型(obj转gltf)

    在用cesium的过程中难免需要导入别人做好的3D模型,这时候就需要将这些模型转成gltf格式了 当然,官方也给了我们一个网页版的转换器,但是毕竟是网页版的,效率极其低下,文件还不能太大,所以我们就需 ...

  8. vc++6.0创建console32之.c的应用程序详解

    文件-->新建-->win32-->取一个名字,确定 文件-->新建-->c++Source-->取一个名字,记住以.c为后缀,确定 编写简单的程序调试

  9. includes() 方法用来判断一个数组是否包含一个指定的值,根据情况,如果包含则返回 true,否则返回false。

    注意:对象数组不能使用includes方法来检测. JavaScript Demo: Array.includes() var array1 = [1, 2, 3]; console.log(arra ...

  10. javascript中 (function(){})();如何理解?

    javascript中 (function(){})();如何理解? javascript中: (function(){})()是匿名函数,主要利用函数内的变量作用域,避免产生全局变量,影响整体页面环 ...