题意:有一些无向边m条权值是给定的k条权值在[l,r]区间可以由你来定,一个点s1 出发一个从s2出发  问s1 出发的能不能先打到f

思路:最短路。

首先检测能不能赢 在更新的时候  如果对于一条边 a->b  如果dis1[a] <dis2[a]  那么选择这条边就选择   l  因为这条边对于s1有利 如果两个起点都选择了这条边  则说明s1 赢定了,所以要让他们尽量走这条,所以边权越小越好。跑完之后检测 如果  dis1[f]<dis2[f] 那么 就赢了。

接下来判断能不能平局。因为目前已经没有赢的可能了  那么  把dis1[a]<dis2[a]改成dis1[a]<=dis2[a] 选择l  其他选择r 即可。原因:小于的话毫无疑问就是选择l  ;等于的话选择小的如果两个都走了这条边则平局。

  1. #include<cstring>
  2. #include<algorithm>
  3. #include<cstdio>
  4. #include<cmath>
  5. #include <iostream>
  6. #include<vector>
  7. #include<queue>
  8. #define INF 1e15
  9. #define LL long long
  10. #define P pair<LL,int>
  11. #define MP make_pair
  12. #define M 200000
  13. #define N 100000
  14. using namespace std;
  15. priority_queue<P> q;
  16. struct node {
  17. int l, r, to, nx;
  18. } e[M];
  19. int head[N];
  20. int ecnt;
  21. int ans[N];
  22. void addedge(int x, int y, int l, int r) {
  23. e[ecnt].l = l;
  24. e[ecnt].r = r;
  25. e[ecnt].to = y;
  26. e[ecnt].nx = head[x];
  27. head[x] = ecnt++;
  28. }
  29. LL d1[N], d2[N];
  30. int n, m, k, s1, s2, f;
  31. void gao(int bo) {
  32. while (!q.empty())
  33. q.pop();
  34. memset(ans, -, sizeof(ans));
  35. for (int i = ; i <= n; ++i)
  36. d1[i] = d2[i] = INF;
  37. d1[s1] = d2[s2] = ;
  38. q.push(MP(, s1));
  39. q.push(MP(, s2));
  40. while (!q.empty()) {
  41. P ee = q.top();
  42. q.pop();
  43. LL va = -ee.first;
  44. int id = ee.second;
  45. if (va > d1[id] && va > d2[id])
  46. continue;
  47. bool ok;
  48. if (bo == ) {
  49. if (d1[id] < d2[id])
  50. ok = true;
  51. else
  52. ok = false;
  53. } else {
  54. if (d1[id] <= d2[id])
  55. ok = true;
  56. else
  57. ok = false;
  58. }
  59. for (int i = head[id]; i != -; i = e[i].nx) {
  60. int u = e[i].to;
  61. LL add;
  62. if (ok)
  63. add = e[i].l;
  64. else
  65. add = e[i].r;
  66. ans[i] = add;
  67. if (d1[u] > d1[id] + add) {
  68. d1[u] = d1[id] + add;
  69. q.push(MP(-d1[u], u));
  70. }
  71. if (d2[u] > d2[id] + add) {
  72. d2[u] = d2[id] + add;
  73. q.push(MP(-d2[u], u));
  74. }
  75. }
  76. }
  77. }
  78. int main() {
  79. scanf("%d%d%d", &n, &m, &k);
  80. scanf("%d%d%d", &s1, &s2, &f);
  81. memset(head, -, sizeof(head));
  82. ecnt = ;
  83. for (int i = ; i < m; ++i) {
  84. int x, y, z;
  85. scanf("%d%d%d", &x, &y, &z);
  86. addedge(x, y, z, z);
  87. }
  88. for (int i = ; i < k; ++i) {
  89. int x, y, l, r;
  90. scanf("%d%d%d%d", &x, &y, &l, &r);
  91. addedge(x, y, l, r);
  92. }
  93. gao();
  94. if (d1[f] < d2[f]) {
  95. puts("WIN");
  96. for (int i = m; i < m + k; ++i) {
  97. if (ans[i] == -)
  98. ans[i] = e[i].l;
  99. printf("%d", ans[i]);
  100. if (i == m + k - )
  101. puts("");
  102. else
  103. printf(" ");
  104. }
  105. return ;
  106. }
  107. gao();
  108. if (d1[f] == d2[f]) {
  109. puts("DRAW");
  110. for (int i = m; i < m + k; ++i) {
  111. if (ans[i] == -)
  112. ans[i] = e[i].l;
  113. printf("%d", ans[i]);
  114. if (i == m + k - )
  115. puts("");
  116. else
  117. printf(" ");
  118. }
  119. return ;
  120. }
  121. puts("LOSE");
  122. return ;
  123. }

CodeForces 360E Levko and Game(Codeforces Round #210 (Div. 1))的更多相关文章

  1. (BestCoder Round #64 (div.2))Array

    BestCoder Round #64 (div.2) Array 问题描述 Vicky是个热爱数学的魔法师,拥有复制创造的能力. 一开始他拥有一个数列{1}.每过一天,他将他当天的数列复制一遍,放在 ...

  2. Codeforces Round #433 (Div. 2)【A、B、C、D题】

    题目链接:Codeforces Round #433 (Div. 2) codeforces 854 A. Fraction[水] 题意:已知分子与分母的和,求分子小于分母的 最大的最简分数. #in ...

  3. CodeForces 816B Karen and Coffee(前缀和,大量查询)

    CodeForces 816B Karen and Coffee(前缀和,大量查询) Description Karen, a coffee aficionado, wants to know the ...

  4. 【CodeForces】841D. Leha and another game about graph(Codeforces Round #429 (Div. 2))

    [题意]给定n个点和m条无向边(有重边无自环),每个点有权值di=-1,0,1,要求仅保留一些边使得所有点i满足:di=-1或degree%2=di,输出任意方案. [算法]数学+搜索 [题解] 最关 ...

  5. CodeForces - 1207G :Indie Album(AC自动机 fail树上DFS)

    题意:有N个串,给出的形式是拼接给出,对于第i行:  (1,c)表示字符串i是单个字母c: (2,p,c)表示字符串i=在字符串p后面接上一个字母c. 然后给出M个提问,形式是(i,string).问 ...

  6. 「日常训练」Skills(Codeforce Round #339 Div.2 D)

    题意(CodeForces 614D) 每个人有\(n(n\le 10^5)\)个技能,技能等级都在\([0,10^9]\)的范围,每个技能有一个当前等级,所有技能的最高等级都为A.一个人的力量被记做 ...

  7. 「知识学习&日常训练」莫队算法(一)(Codeforce Round #340 Div.2 E)

    题意 (CodeForces 617E) 已知一个长度为\(n\)的整数数列\(a[1],a[2],-,a[n]\),给定查询参数\(l,r\),问\([l,r]\)内,有多少连续子段满足异或和等于\ ...

  8. B. Ohana Cleans Up(Codeforces Round #309 (Div. 2))

    B. Ohana Cleans Up   Ohana Matsumae is trying to clean a room, which is divided up into an n by n gr ...

  9. B. The Number of Products(Codeforces Round #585 (Div. 2))

    本题地址: https://codeforces.com/contest/1215/problem/B 本场比赛A题题解:https://www.cnblogs.com/liyexin/p/11535 ...

随机推荐

  1. BJFU 1034

    描述 对于任意的两个非负整数a,b(0<=a,b<10000),请计算a^b各位数字的和的各位数字的和-- 输入 输入两个非负整数a,b(0<=a,b<10000),注意哦,输 ...

  2. js实现继承的五种方式

    function Parent(firstname) { this.fname=firstname; ; this.sayAge=function() { console.log(this.age); ...

  3. 11. 星际争霸之php设计模式--备忘模式

    题记==============================================================================本php设计模式专辑来源于博客(jymo ...

  4. configure.ac:32: error: possibly undefined macro: AC_DEFINE

    在ubuntu 下编译snappy时,在检查依赖关系时,处理autoconf的包时,在相关依赖包都已经安装的情况下,报如下错误,死活不过. configure.ac:32: error: possib ...

  5. Windows Azure Mangement API 之 更方便的使用Mangement API

    许多.Net 程序员在使用Azure Management API的时候都选择参考微软官方示例,通过创建HttpWebRequest来创建. 或者自己创建类库来封装这些API,使之调用起来更加方便. ...

  6. C#使用DataSet Datatable更新数据库的三种实现方法

    本文以实例形式讲述了使用DataSet Datatable更新数据库的三种实现方法,包括CommandBuilder 方法.DataAdapter 更新数据源以及使用sql语句更新.分享给大家供大家参 ...

  7. Android中的动态加载机制

    在目前的软硬件环境下,Native App与Web App在用户体验上有着明显的优势,但在实际项目中有些会因为业务的频繁变更而频繁的升级客户端,造成较差的用户体验,而这也恰恰是Web App的优势.本 ...

  8. HDU1532 Drainage Ditches 网络流EK算法

    Drainage Ditches Problem Description Every time it rains on Farmer John's fields, a pond forms over ...

  9. Winform开发框架之单据窗体生成(主从表,流水单号)

    源码地址:https://github.com/GarsonZhang/GZFramework.ShareDemo 前言 1.在开始本节前请先重置代码为 chapter-03-start 懒人地址:h ...

  10. 《BI那点儿事—数据的艺术》理解维度数据仓库——事实表、维度表、聚合表

    事实表 在多维数据仓库中,保存度量值的详细值或事实的表称为“事实表”.一个按照州.产品和月份划分的销售量和销售额存储的事实表有5个列,概念上与下面的示例类似. Sate Product Mouth U ...