对于这种坑爹题不想多说什么了。。
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<set>
#include<cmath>
#include<cassert>
#include<cstring>
#include<iomanip>
using namespace std;
#ifdef _WIN32
#define i64 __int64
#define out64 "%I64d\n"
#define in64 "%I64d"
#else
#define i64 long long
#define out64 "%lld\n"
#define in64 "%lld"
#endif
/************ for topcoder by zz1215 *******************/
#define FOR(i,a,b) for( int i = (a) ; i <= (b) ; i ++)
#define FFF(i,a) for( int i = 0 ; i < (a) ; i ++)
#define FFD(i,a,b) for( int i = (a) ; i >= (b) ; i --)
#define S64(a) scanf(in64,&a)
#define SS(a) scanf("%d",&a)
#define LL(a) ((a)<<1)
#define RR(a) (((a)<<1)+1)
#define pb push_back
#define CL(Q) while(!Q.empty())Q.pop()
#define MM(name,what) memset(name,what,sizeof(name))
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define read freopen("in.txt","r",stdin)
#define write freopen("out.txt","w",stdout)
const int inf = 0x3f3f3f3f;
const i64 inf64 = 0x3f3f3f3f3f3f3f3fLL;
const double oo = 10e9;
const double eps = 10e-9;
const double pi = acos(-1.0);
const int maxn = 1333;
struct zz
{
int from;
int to;
int cost;
int c;
}zx;
struct ss
{
int x;
int c;
}sd;
vector<zz>g[maxn];
int n,m;
i64 way[maxn][4];
int love[maxn][4];
bool inq[maxn][4];
i64 ans,ans2;
int nxt(int x)
{
if(x==3)
{
return 0;
}
return x+1;
}
void spfa()
{
ans=inf64;
ans2=0;
if(n==1)
{
int d[4];
for(int i=0;i<4;i++)
{
d[i]=inf;
}
for(int i=0;i<g[1].size();i++)
{
d[g[1][i].c]=min(d[g[1][i].c],g[1][i].cost);
}
ans=0;
for(int i=0;i<4;i++)
{
if(d[i]==inf)
{
return ;
}
ans+=d[i];
}
ans2=1;
return ;
}
queue<ss>q;
CL(q);
for(int i=1;i<=n;i++)
{
for(int j=0;j<4;j++)
{
inq[i][j]=0;
way[i][j]=inf64;
love[i][j]=0;
}
}
sd.x = 1;
sd.c = 3;
q.push(sd);
way[1][3]=0;
inq[1][3]=true;
ss now,to;
i64 temp;
i64 t2;
while(!q.empty())
{
now = q.front();
q.pop();
inq[now.x][now.c] = false;
for(int i=0;i<g[now.x].size();i++)
{
to.x=g[now.x][i].to;
to.c=g[now.x][i].c;
if(to.c == nxt(now.c) )
{
temp = way[now.x][now.c]+g[now.x][i].cost;
if(temp<way[to.x][to.c])
{
t2 = love[now.x][now.c];
if(to.c == 3)
{
t2++;
}
love[to.x][to.c]=t2;
way[to.x][to.c]=temp;
if(!inq[to.x][to.c])
{
inq[to.x][to.c]=true;
q.push(to);
}
}
else if(temp==way[to.x][to.c])
{
t2 = love[now.x][now.c];
if(to.c==3)
{
t2++;
}
if(t2>love[to.x][to.c])
{
love[to.x][to.c] = t2;
if(!inq[to.x][to.c])
{
inq[to.x][to.c]=true;
q.push(to);
}
}
}
}
}
}
ans=way[n][3];
ans2=love[n][3];
return ;
}
int main()
{
int T;
cin>>T;
for(int tt=1;tt<=T;tt++)
{
cin>>n>>m;
char c;
for(int i=1;i<=n;i++)
{
g[i].clear();
}
for(int i=1;i<=m;i++)
{
cin>>zx.from>>zx.to>>zx.cost;
cin>>c;
if(c=='L')
{
zx.c=0;
}
else if(c=='O')
{
zx.c=1;
}
else if(c=='V')
{
zx.c=2;
}
else if(c=='E')
{
zx.c=3;
}
else
{
assert(false);
}
g[zx.from].pb(zx);
swap(zx.from,zx.to);
g[zx.from].pb(zx);
}
spfa();
cout<<"Case "<<tt<<": ";
if(ans==inf64 || ans2 == 0)
{
cout<<"Binbin you disappoint Sangsang again, damn it!"<<endl;
}
else
{
cout<<"Cute Sangsang, Binbin will come with a donkey after travelling "<<ans<<" meters and finding "<<ans2<<" LOVE strings at last."<<endl;
}
}
return 0;
}