#include<bits/stdc++.h>
#define inf 999999999
#define mx 10000
using namespace std;
typedef long long ll;
struct s
{
ll from,to,cost;
}edge[mx];
ll edges,nodes,rat;
ll dist[mx];
int main()
{
ll i,j,k,l,m,n,test;
cin>>test;
for(k=1;k<=test;k++)
{
fill(dist,dist+mx,inf);
cin>>nodes>>edges>>rat;
for(i=0;i<edges;i++)
{
cin>>edge[i].from>>edge[i].to;
ll earn,exp;
cin>>earn>>exp;
edge[i].cost=rat*exp-earn;
}
ll now;
ll u,v;
for(i= 1;i<nodes;i++ )
{
for(j= 0;j<edges;j++ )
{
u=edge[j].from;
v=edge[j].to;
now=dist[u]+edge[j].cost;
if(now<dist[v])
dist[v]=now;
}
}
bool flag=false;
for(i= 0;i<edges;i++)
{
u=edge[i].from;
v=edge[i].to;
now=dist[u]+edge[i].cost;
if(now<dist[v])
{
flag=true;
break;
}
}
cout<<"Case "<<k<<": ";
if(flag)
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}
return 0;
}
#define inf 999999999
#define mx 10000
using namespace std;
typedef long long ll;
struct s
{
ll from,to,cost;
}edge[mx];
ll edges,nodes,rat;
ll dist[mx];
int main()
{
ll i,j,k,l,m,n,test;
cin>>test;
for(k=1;k<=test;k++)
{
fill(dist,dist+mx,inf);
cin>>nodes>>edges>>rat;
for(i=0;i<edges;i++)
{
cin>>edge[i].from>>edge[i].to;
ll earn,exp;
cin>>earn>>exp;
edge[i].cost=rat*exp-earn;
}
ll now;
ll u,v;
for(i= 1;i<nodes;i++ )
{
for(j= 0;j<edges;j++ )
{
u=edge[j].from;
v=edge[j].to;
now=dist[u]+edge[j].cost;
if(now<dist[v])
dist[v]=now;
}
}
bool flag=false;
for(i= 0;i<edges;i++)
{
u=edge[i].from;
v=edge[i].to;
now=dist[u]+edge[i].cost;
if(now<dist[v])
{
flag=true;
break;
}
}
cout<<"Case "<<k<<": ";
if(flag)
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}
return 0;
}
No comments:
Post a Comment