题意及思路:https://blog.csdn.net/huanghongxun/article/details/49846927

在假设所有边都是最大值的情况下,如果第一个人能比第二个人先到,那就缩短这条边。

代码:

#include <bits/stdc++.h>
#define LL long long
using namespace std;
const int maxn = 10010;
int head[maxn], Next[maxn * 2], ver[maxn * 2], f[maxn * 2], tot;
LL l[maxn * 2], r[maxn * 2];
LL d[2][maxn];
bool v[2][maxn];
queue<int> q[2];
int s1, s2, t, n, m, k;
void add(int x, int y, LL lb, LL rb) {
ver[++tot] = y, l[tot] = lb, r[tot] = rb, Next[tot] = head[x], head[x] = tot, f[tot] = x;
}
void spfa(int pos, int s) {
// memset(d[pos], 0x3f, sizeof(d[pos]));
// memset(v[pos], 0, sizeof(v[pos]));
// q[pos].push(s), v[pos][s] = 1, d[pos][s] = 0;
while(q[pos].size()) {
int x = q[pos].front();
q[pos].pop();
v[pos][x] = 0;
for (int i = head[x]; i; i = Next[i]) {
int y = ver[i], z = r[i];
if(d[pos][y] > d[pos][x] + z) {
d[pos][y] = d[pos][x] + z;
if(!v[pos][y])
q[pos].push(y), v[pos][y] = 1;
}
}
}
}
bool solve(int flag) {
memset(d, 0x3f, sizeof(d));
memset(v, 0, sizeof(v));
d[0][s1] = d[1][s2] = 0;
v[0][s1] = v[1][s2] = 1;
q[0].push(s1), q[1].push(s2);
bool flag1 = 1;
while(flag1) {
spfa(0, s1), spfa(1, s2);
flag1 = 0;
for (int i = m + 1; i <= k + m; i++) {
if(d[0][f[i]] + flag <= d[1][f[i]] && l[i] != r[i]) {
flag1 = 1;
q[0].push(f[i]), q[1].push(f[i]);
v[0][f[i]] = 1, v[1][f[i]] = 1;
r[i] = l[i];
}
}
}
return d[0][t] + flag <= d[1][t];
}
int main() {
int x, y;
LL z, t1;
scanf("%d%d%d", &n, &m, &k);
scanf("%d%d%d", &s1, &s2, &t);
for (int i = 1; i <= m; i++) {
scanf("%d%d%lld", &x, &y, &z);
add(x, y, z, z);
}
for (int i = 1; i <= k; i++) {
scanf("%d%d%lld%lld", &x, &y, &z, &t1);
add(x, y, z, t1);
}
if(solve(1)) {
printf("WIN\n");
for (int i = m + 1; i <= m + k; i++)
printf("%d ", r[i]);
printf("\n");
return 0;
}
if(solve(0)) {
printf("DRAW\n");
for (int i = m + 1; i <= m + k; i++)
printf("%d ", r[i]);
printf("\n");
return 0;
}
printf("LOSE\n");
}

  

Codeforces 360E 贪心 最短路的更多相关文章

  1. codeforces DIV2 D 最短路

    http://codeforces.com/contest/716/problem/D 题目大意:给你一些边,有权值,权值为0的表示目前该边不存在,但是可以把0修改成另外一个权值.现在,我们重新建路, ...

  2. CodeForces - 893D 贪心

    http://codeforces.com/problemset/problem/893/D 题意 Recenlty Luba有一张信用卡可用,一开始金额为0,每天早上可以去充任意数量的钱.到了晚上, ...

  3. Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Problem D (Codeforces 831D) - 贪心 - 二分答案 - 动态规划

    There are n people and k keys on a straight line. Every person wants to get to the office which is l ...

  4. Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals) Problem D (Codeforces 828D) - 贪心

    Arkady needs your help again! This time he decided to build his own high-speed Internet exchange poi ...

  5. CodeForces - 93B(贪心+vector<pair<int,double> >+double 的精度操作

    题目链接:http://codeforces.com/problemset/problem/93/B B. End of Exams time limit per test 1 second memo ...

  6. [CSP-S模拟测试]:午餐(贪心+最短路)

    题目传送门(内部题115) 输入格式 第一行两个正整数$n,m$. 接下来$m$行,每行$4$个正整数$u_j,v_j,L_j,R_j$. 接下来一行$n$个数,若第$i$个数为$1$,则$i$号同学 ...

  7. C - Ordering Pizza CodeForces - 867C 贪心 经典

    C - Ordering Pizza CodeForces - 867C C - Ordering Pizza 这个是最难的,一个贪心,很经典,但是我不会,早训结束看了题解才知道怎么贪心的. 这个是先 ...

  8. Codeforces 570C 贪心

    题目:http://codeforces.com/contest/570/problem/C 题意:给你一个字符串,由‘.’和小写字母组成.把两个相邻的‘.’替换成一个‘.’,算一次变换.现在给你一些 ...

  9. Codeforces 732e [贪心][stl乱搞]

    /* 不要低头,不要放弃,不要气馁,不要慌张 题意: 给n个插座,m个电脑.每个插座都有一个电压,每个电脑都有需求电压. 每个插座可以接若干变压器,每个变压器可以使得电压变为x/2上取整. 有无限个变 ...

随机推荐

  1. HttpRunnerManager安装部署(centos7)

    一.安装python3环境 参考 二.安装依赖环境 根据根目录requirements.txt文件安装依赖,可以使用pip安装 #pip3 install -r requirements.txt 会遇 ...

  2. 线程池(ThreadPool)创建

    线程池创建方式jdk1.5 Java通过Executors(jdk1.5并发包)提供四种线程池,分别为: newCachedThreadPool创建一个可缓存线程池,如果线程池长度超过处理需要,可灵活 ...

  3. C# 批量修改考勤设备时间

    自己工作中用到的小程序,每次远行后批量改一次 如下: 其中的zkemkeeper是中控的相关组件,因是系统组件,须要先注册相关文件后才有效 using System; using System.Col ...

  4. 人生苦短_我用Python_logging日志操作_011

    话不多说,开搞,基础是先使用自带loggin模块,level为warning以上, 进一步是自定义logger,level可自定义 #!/usr/bin/env python # -*- coding ...

  5. springBoot 连接数据库

    心得:1.先添加依赖. 2.在application.yml文件中创建mybatis的连接,与项目连接起来. 3.application.yml文件中可以自行配置服务器的端口,配置mybatis的路径 ...

  6. PHP curl_errno函数

    curl_errno — 返回最后一次的错误号 说明 int curl_errno ( resource $ch ) 返回最后一次cURL操作的错误号. 参数 ch 由 curl_init() 返回的 ...

  7. JS中数据结构之二叉查找树

    树是一种非线性的数据结构,以分层的方式存储数据.在二叉树上进行查找非常快,为二叉树添加或删除元素也非常快. 一棵树最上面的节点称为根节点,如果一个节点下面连接多个节点,那么该节点称为父节点,它下面的节 ...

  8. MISC_刷题笔记

    图片隐写 png类型 查看文件头文件尾,更改长宽(bugku_隐写) zip类型 压缩包的多层嵌套,用strings看打印出来的是不是一个目录的样子(bugku_眼见非实)

  9. js策略模式vs状态模式

    一.策略模式 1.定义:把一些小的算法,封装起来,使他们之间可以相互替换(把代码的实现和使用分离开来)2.利用策略模式实现小方块缓动 html代码: <div id="containe ...

  10. Jdk1.8 之 Integer类源码浅析

    先看一下它的继承.实现关系: public final class Integer extends Number implements Comparable<Integer> Number ...