CodeForces 360E Levko and Game(Codeforces Round #210 (Div. 1))

题意:有一些无向边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  ;等于的话选择小的如果两个都走了这条边则平局。

#include<cstring>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include <iostream>
#include<vector>
#include<queue>
#define INF 1e15
#define LL long long
#define P pair<LL,int>
#define MP make_pair
#define M 200000
#define N 100000
using namespace std;
priority_queue<P> q;
struct node {
    int l, r, to, nx;
} e[M];
int head[N];
int ecnt;
int ans[N];
void addedge(int x, int y, int l, int r) {
    e[ecnt].l = l;
    e[ecnt].r = r;
    e[ecnt].to = y;
    e[ecnt].nx = head[x];
    head[x] = ecnt++;
}
LL d1[N], d2[N];
int n, m, k, s1, s2, f;
void gao(int bo) {
    while (!q.empty())
        q.pop();
    memset(ans, -1, sizeof(ans));
    for (int i = 0; i <= n; ++i)
        d1[i] = d2[i] = INF;
    d1[s1] = d2[s2] = 0;
    q.push(MP(0, s1));
    q.push(MP(0, s2));
    while (!q.empty()) {
        P ee = q.top();
        q.pop();
        LL va = -ee.first;
        int id = ee.second;
        if (va > d1[id] && va > d2[id])
            continue;
        bool ok;
        if (bo == 1) {
            if (d1[id] < d2[id])
                ok = true;
            else
                ok = false;
        } else {
            if (d1[id] <= d2[id])
                ok = true;
            else
                ok = false;
        }
        for (int i = head[id]; i != -1; i = e[i].nx) {
            int u = e[i].to;
            LL add;
            if (ok)
                add = e[i].l;
            else
                add = e[i].r;
            ans[i] = add;
            if (d1[u] > d1[id] + add) {
                d1[u] = d1[id] + add;
                q.push(MP(-d1[u], u));
            }
            if (d2[u] > d2[id] + add) {
                d2[u] = d2[id] + add;
                q.push(MP(-d2[u], u));
            }
        }
    }
}
int main() {
    scanf("%d%d%d", &n, &m, &k);
    scanf("%d%d%d", &s1, &s2, &f);
    memset(head, -1, sizeof(head));
    ecnt = 0;
    for (int i = 0; i < m; ++i) {
        int x, y, z;
        scanf("%d%d%d", &x, &y, &z);
        addedge(x, y, z, z);
    }
    for (int i = 0; i < k; ++i) {
        int x, y, l, r;
        scanf("%d%d%d%d", &x, &y, &l, &r);
        addedge(x, y, l, r);
    }
    gao(1);
    if (d1[f] < d2[f]) {
        puts("WIN");
        for (int i = m; i < m + k; ++i) {
            if (ans[i] == -1)
                ans[i] = e[i].l;
            printf("%d", ans[i]);
            if (i == m + k - 1)
                puts("");
            else
                printf(" ");
        }
        return 0;
    }
    gao(0);
    if (d1[f] == d2[f]) {
        puts("DRAW");
        for (int i = m; i < m + k; ++i) {
            if (ans[i] == -1)
                ans[i] = e[i].l;
            printf("%d", ans[i]);
            if (i == m + k - 1)
                puts("");
            else
                printf(" ");
        }
        return 0;
    }
    puts("LOSE");
    return 0;
}

CodeForces 360E Levko and Game(Codeforces Round #210 (Div. 1)),布布扣,bubuko.com

时间: 2024-08-09 10:36:00

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

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

BestCoder Round #64 (div.2) Array 问题描述 Vicky是个热爱数学的魔法师,拥有复制创造的能力. 一开始他拥有一个数列{1}.每过一天,他将他当天的数列复制一遍,放在数列尾,并在两个数列间用0隔开.Vicky想做些改变,于是他将当天新产生的所有数字(包括0)全加1.Vicky现在想考考你,经过100天后,这个数列的前M项和是多少?. 输入描述 输入有多组数据. 第一行包含一个整数T,表示数据组数.T. \left( 1 \leq T \leq 2 * {10}^

HDU 5056 Boring count(BestCoder Round #11 (Div. 2))

Problem Description: You are given a string S consisting of lowercase letters, and your task is counting the number of substring that the number of each lowercase letter in the substring is no more than K. Input: In the first line there is an integer

Codeforces Round #433 (Div. 2)

题目链接:Codeforces Round #433 (Div. 2) codeforces 854 A. Fraction[水] 题意:已知分子与分母的和,求分子小于分母的 最大的最简分数. 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <algorithm> 5 using namespace std; 6 int gcd(int a,int b){re

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

CodeForces 816B Karen and Coffee(前缀和,大量查询) Description Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading several recipe books, including the universally ac

hdu4931 Happy Three Friends(BestCoder Round#4签到题)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4931 Happy Three Friends Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 150    Accepted Submission(s): 128 Problem Description Dong-hao , Grandpa

小蒟蒻初次CF滚粗+爆炸记 (Codeforces Round #466 Div.2)

比赛链接:http://codeforces.com/blog/entry/57981 小蒟蒻今天初次在ZCDHJ张大佬的带领下,打了一场CF (张大佬cnblogs链接:https://www.cnblogs.com/ZCDHJ)' 英文完全看不懂,后面几题直接放弃,各位dalao请见谅 T1: 题目链接:http://codeforces.com/contest/940/problem/A 题目大意: 给你一个n个数的集合,要求你删掉若干数,其中最大的差不应该超过d,求最小删除量. (小蒟蒻

Codeforces Round #424 (Div. 2) D 思维 E set应用,树状数组

Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) D. Office Keys 题意:一条直线上,有个办公室坐标 p,有 n个人在a[i],有 k把钥匙在b[i],每个人必须拿到一把钥匙,然后到办公室.问怎么安排花的时间最短. tags:还是不懂套路啊..其实多画两下图就能够感觉出来,2333 关键是要看出来,n个人拿的 n把钥匙应该是连续的. 然后,就是瞎暴力.. #include<bits/stdc++.h> usi

HDU 5671 Matrix (BestCoder Round #81 (div.2) 1002)

传送门 Matrix Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 311    Accepted Submission(s): 142 Problem Description There is a matrix M that has n rows and m columns (1≤n≤1000,1≤m≤1000).Then we

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

题意 已知一个长度为\(n\)的整数数列\(a[1],a[2],-,a[n]\),给定查询参数\(l,r\),问\([l,r]\)内,有多少连续子段满足异或和等于\(k\). 也就是说,对于所有的\(x,y (l\le x\le y\le r)\),能够满足\(a[x]\oplus a[x+1]\oplus ...\oplus a[y]=k\)的\((x,y)\)有多少组. 分析 对于这种离线区间的查询问题(不涉及对区间的更改),我们可以使用莫队算法解决.这类问题是什么类型?对于序列上的区间询问