题目:http://codeforces.com/contest/360/problem/E

首先,每条边不是选 \( l[i] \) 就是选 \( r[i] \);

做法就是先把边权都设成 \( r[i] \),然后做 \( dijkstra \),如果有一条可改的边 \( (a,b) \) 而且 \( dis1[a] < dis2[a] \),那么就改边权为 \( l[i] \);

然后重复这个过程直到无边可改;

因为要考虑平局,所以只要 \( dis1[a] <= dis2[a] \) 就改,这样先让第一个人的路是最优的;

其实也不用一条一条改,一次改所有能改的就行,因为据题解的证明,一次改了一条边后,不会使一个 \( dis1[a] <= dis2[a] \) 的边突然变得 \( dis1[a] > dis2[a] \)

题解的证明...看不动了...感性理解...

代码如下:

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std;
typedef long long ll;
int const xn=1e4+,xm=;
int n,m,cnt,hd[xn],ct,to[xn],nxt[xn],w[xn],s1,s2,f;
ll dis[][xn],inf=1e17;
bool vis[xn];
struct E{int u,v,bh,l,r,w;}ed[xm];
struct N{
ll d; int id;
N(ll d=,int i=):d(d),id(i) {}
bool operator < (const N &y) const
{return d>y.d;}
};
priority_queue<N>q;
int rd()
{
int ret=,f=; char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=; ch=getchar();}
while(ch>=''&&ch<='')ret=ret*+ch-'',ch=getchar();
return f?ret:-ret;
}
void add(int x,int y,int z){to[++ct]=y; nxt[ct]=hd[x]; hd[x]=ct; w[ct]=z;}
void dij(int t)
{
for(int i=;i<=n;i++)dis[t][i]=inf;
for(int i=;i<=n;i++)vis[i]=;
int st=(t?s2:s1);
dis[t][st]=; q.push(N(,st));
while(q.size())
{
int x=q.top().id; q.pop();
if(vis[x])continue; vis[x]=;
for(int i=hd[x],u;i;i=nxt[i])
if(dis[t][u=to[i]]>dis[t][x]+w[i])
{
dis[t][u]=dis[t][x]+w[i];
q.push(N(dis[t][u],u));
}
}
}
int main()
{
n=rd(); m=rd(); cnt=rd();
s1=rd(); s2=rd(); f=rd();
for(int i=,x,y,z;i<=m;i++)x=rd(),y=rd(),z=rd(),add(x,y,z);
for(int i=;i<=cnt;i++)
ed[i].u=rd(),ed[i].v=rd(),ed[i].l=rd(),ed[i].r=rd(),
ed[i].bh=ct+,ed[i].w=,add(ed[i].u,ed[i].v,ed[i].r);
dij(); dij();
while(dis[][f]>=dis[][f])
{
int i;
for(i=;i<=cnt;i++)
if(dis[][ed[i].u]<=dis[][ed[i].u]&&ed[i].w)break;
if(i>cnt)
{
if(dis[][f]>dis[][f])puts("LOSE");
else
{
puts("DRAW");
for(int j=;j<=cnt;j++)printf("%d ",ed[j].w?ed[j].r:ed[j].l);
puts("");
}
return ;
}
ed[i].w=; w[ed[i].bh]=ed[i].l; dij(); dij();
}
puts("WIN");
for(int j=;j<=cnt;j++)printf("%d ",ed[j].w?ed[j].r:ed[j].l);
puts("");
return ;
}

CF 360 E Levko and Game —— 贪心+最短路的更多相关文章

  1. [codeforces 360]A. Levko and Array Recovery

    [codeforces 360]A. Levko and Array Recovery 试题描述 Levko loves array a1, a2, ... , an, consisting of i ...

  2. CF 360E Levko and Game——贪心

    题目:http://codeforces.com/contest/360/problem/E 官方题解与证明:http://codeforces.com/blog/entry/9529 一条可以调整的 ...

  3. [ 10.05 ]CF每日一题系列—— 962B贪心和思维?

    Description: 非 * 号的地方可以放A或B,不能AA或BB,一共有a个A,b个B,问你最多放几个 Solution: 1.模拟一下,找连续空位长度,如果长度为奇数,则我可以有一个位置放任意 ...

  4. [ 10.03 ]CF每日一题系列—— 534B贪心

    Descripe: 贪心,贪在哪里呢…… 给你初始速度,结尾速度,行驶秒数,每秒速度可变化的范围,问你行驶秒数内最远可以行驶多少距离 Solution: 贪心,我是否加速,就是看剩下的时间能不能减到原 ...

  5. CF GukiZ hates Boxes 【二分+贪心】

    Professor GukiZ is concerned about making his way to school, because massive piles of boxes are bloc ...

  6. CF 990B. Micro-World【数组操作/贪心/STL/二分搜索】

    [链接]:CF [题意]:对任意一个数a[i] ,可以对任意 满足 i != j 且 a[i] > a[j] && a[i] <= a[j] +k 的 a[j] 可以被删掉 ...

  7. CF R 639 div2 F Review 贪心 二分

    LINK:Résumé Review 这道题让我眼前一亮没想到二分这么绝. 由于每个\(b_i\)都是局部的 全局只有一个限制\(\sum_{i=1}^nb_i=k\) 所以dp没有什么用 我们只需要 ...

  8. CF 321B Kefa and Company(贪心)

    题目链接: 传送门 Kefa and Company time limit per test:2 second     memory limit per test:256 megabytes Desc ...

  9. CF#301 B:School Marks(贪心)

    B:School Marks 有n个测试,已经完成了k个,每个测试得分为a[i],接下来的分数不知道,让我们求出任何一个满足题意的即可,满足题意就是n个测试的得分总和<=x, 中位数>=y ...

随机推荐

  1. vue中handsontable 使用

    handsontable是目前在前端界最接近excel的插件,可以执行编辑,复制粘贴,插入删除行列,排序等复杂操作 1.安装模块包 npm install handsontable-pro @hand ...

  2. poj 3714 Raid【(暴力+剪枝) || (分治法+剪枝)】

    题目:  http://poj.org/problem?id=3714 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=27048#prob ...

  3. 算法设计 mac 字符串 标识 n维度 2 3维度 字符串 标识值 特征值

    基向量

  4. Django 之 ModelForm 组件

    Django的model form组件 扩展:Django 之Form组件 首先我们要知道 Model 和 Form 分别时干什么的 Model  生成表数据 Form  对表单.字段进行校验 Dja ...

  5. Bootstrap 轮播图(Carousel)插件

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  6. (转)复习TCP/IP协议与Http协议的区别

    TPC/IP协议是传输层协议,主要解决数据如何在网络中传输,而HTTP是应用层协议,主要解决如何包装数据.关于TCP/IP和HTTP协议的关系,网络有一段比较容易理解的介绍:“我们在传输数据时,可以只 ...

  7. DOM指针

    dom节点改变 会自动改变节点的指针 child = formula.firstChild while(child){ next = child.nextSibling; formula.remove ...

  8. gulp 打包报错:ReferenceError: internalBinding is not defined

    > gulp build internal/util/inspect.js:31 const types = internalBinding('types'); ^ ReferenceError ...

  9. elk示例-精简版

    作者:Danbo 2016-03-09 1.Grok正则捕获 input {stdin{}} filter { grok { match => { "message" =&g ...

  10. Data Structure Linked List: Write a function to get the intersection point of two Linked Lists.

    http://www.geeksforgeeks.org/write-a-function-to-get-the-intersection-point-of-two-linked-lists/ 第一第 ...