先把所有边可动设为r[i]又这些边不是l就是r(如果想一个方向改变能更优的话就尽量多的改变),每次跑dijsktra,对于可动边(x,y),如果dis1[x]<=dis2[x],那么就把这条边改为l[i]
感性理解是对于dis1[x]<=dis2[x]一定是希望这条边向后能成为最短路以符合要求,所以把这样的边到t的距离尽量缩短
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#define ll long long
using namespace std;
const int N=20005;
int n,m,k,h[N],cnt,id[N],l[N],r[N],ans[N],s1,s2,t;
long long dis1[N],dis2[N];
bool v[N];
struct qwe
{
int ne,no,to,va;
}e[N];
int read()
{
int r=0,f=1;
char p=getchar();
while(p>'9'||p<'0')
{
if(p=='-')
f=-1;
p=getchar();
}
while(p>='0'&&p<='9')
{
r=r*10+p-48;
p=getchar();
}
return r*f;
}
void add(int u,int v,int w)
{
cnt++;
e[cnt].ne=h[u];
e[cnt].no=u;
e[cnt].to=v;
e[cnt].va=w;
h[u]=cnt;
}
void dij()
{
priority_queue<pair<long long,int> > q;
memset(dis1,0x3f,sizeof dis1);
memset(v,0,sizeof v);
dis1[s1]=0;
q.push(make_pair(0,s1));
while(!q.empty())
{
int u=q.top().second;
q.pop();
if(v[u])
continue;
v[u]=1;
for(int i=h[u];i;i=e[i].ne)
if(dis1[e[i].to]>dis1[u]+e[i].va)
dis1[e[i].to]=dis1[u]+e[i].va,q.push(make_pair(-dis1[e[i].to],e[i].to));
}
memset(dis2,0x3f,sizeof dis2);
memset(v,0,sizeof v);
dis2[s2]=0;
q.push(make_pair(0,s2));
while(!q.empty())
{
int u=q.top().second;
q.pop();
if(v[u])
continue;
v[u]=1;
for(int i=h[u];i;i=e[i].ne)
if(dis2[e[i].to]>dis2[u]+e[i].va)
dis2[e[i].to]=dis2[u]+e[i].va,q.push(make_pair(-dis2[e[i].to],e[i].to));
}
}
int main()
{
n=read(),m=read(),k=read(),s1=read(),s2=read(),t=read();
for(int i=1;i<=m;i++)
{
int x=read(),y=read(),z=read();
add(x,y,z);
}
for(int i=1;i<=k;i++)
{
int x=read(),y=read();
l[i]=read(),r[i]=read();
add(x,y,r[i]);
id[i]=cnt;
}
bool fl=1;
while(fl)
{
dij();
fl=0;
for(int i=1;i<=k;i++)
if(e[id[i]].va!=l[i]&&dis1[e[id[i]].no]<=dis2[e[id[i]].no])
{
e[id[i]].va=l[i];
ans[i]=1;
fl=1;
}
}
dij();
if(dis1[t]>dis2[t])
{
puts("LOSE");
return 0;
}
if(dis1[t]==dis2[t])
puts("DRAW");
else
puts("WIN");
for(int i=1;i<=k;i++)
printf("%d ",ans[i]?l[i]:r[i]);
return 0;
}