传送门

题目大意

给出一个图,一些边带权,另一些边等待你赋权(最小赋为1).请你找到一种赋权方式,使得 s 到 t 的最短路为 L
n ≤ 1e3 ,m ≤ 1e4 ,L ≤ 1e9

分析

二分所有边的边权和

使得二分后第p条边权值为k,1~p-1条边权值为inf,剩余边权值为1

对于每种情况跑一次最短路

如果结果小于L则增大点权和否则减少

代码

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<ctime>
#include<vector>
#include<set>
#include<map>
#include<stack>
using namespace std;
#define int long long
const int inf = 0x3f3f3f3f;
int n,m,s,t,L,d[],vis[];
priority_queue<pair<int,int> >q;
struct node {
int x,y,z;
};
node a[];
int head[],w[],to[],nxt[],cnt;
vector<int>wh;
inline void add(int i){
int x=a[i].x,y=a[i].y,z=a[i].z;
nxt[++cnt]=head[x];
head[x]=cnt;
to[cnt]=y;
w[cnt]=z;
nxt[++cnt]=head[y];
head[y]=cnt;
to[cnt]=x;
w[cnt]=z;
}
inline void dij(){
d[s]=;
q.push(make_pair(,s));
while(!q.empty()){
int x=q.top().second;
q.pop();
if(vis[x])continue;
vis[x]=;
for(int i=head[x];i;i=nxt[i]){
int y=to[i],z=w[i];
if(d[y]>d[x]+z){
d[y]=d[x]+z;
q.push(make_pair(-d[y],y));
}
}
}
}
inline int ck(int mid){
int i,j,k;
for(i=;i<wh.size();i++){
a[wh[i]].z=+min(mid,inf);
mid-=a[wh[i]].z-;
}
memset(head,,sizeof(head));
memset(w,,sizeof(w));
memset(to,,sizeof(to));
memset(nxt,,sizeof(nxt));
cnt=;
for(i=;i<=m;i++)add(i);
memset(d,0x3f,sizeof(d));
memset(vis,,sizeof(vis));
dij();
return d[t];
}
signed main(){
int i,j,k;
scanf("%lld%lld%lld%lld%lld",&n,&m,&L,&s,&t);
s++,t++;
for(i=;i<=m;i++){
scanf("%lld%lld%lld",&a[i].x,&a[i].y,&a[i].z);
a[i].x++,a[i].y++;
if(!a[i].z)wh.push_back(i);
}
int le=,ri=inf*wh.size();
if(ck(le)>L||ck(ri)<L){
puts("NO");
return ;
}
puts("YES");
while(ri-le>){
int mid=(le+ri)>>;
if(ck(mid)<=L)le=mid;
else ri=mid;
}
ck(le);
for(i=;i<=m;i++)printf("%lld %lld %lld\n",a[i].x-,a[i].y-,a[i].z);
return ;
}

715B Complete The Graph的更多相关文章

  1. CodeForces 715B Complete The Graph 特殊的dijkstra

    Complete The Graph 题解: 比较特殊的dij的题目. dis[x][y] 代表的是用了x条特殊边, y点的距离是多少. 然后我们通过dij更新dis数组. 然后在跑的时候,把特殊边都 ...

  2. Codeforces 715B. Complete The Graph 最短路,Dijkstra,构造

    原文链接https://www.cnblogs.com/zhouzhendong/p/CF715B.html 题解 接下来说的“边”都指代“边权未知的边”. 将所有边都设为 L+1,如果dis(S,T ...

  3. Codeforces 715B & 716D Complete The Graph 【最短路】 (Codeforces Round #372 (Div. 2))

    B. Complete The Graph time limit per test 4 seconds memory limit per test 256 megabytes input standa ...

  4. CF715B. Complete The Graph

    CF715B. Complete The Graph 题意: 给一张 n 个点,m 条边的无向图,要求设定一些边的边权 使得所有边权都是正整数,最终 S 到 T 的最短路为 L 1 ≤ n ≤ 100 ...

  5. 【Codeforces】716D Complete The Graph

    D. Complete The Graph time limit per test: 4 seconds memory limit per test: 256 megabytes input: sta ...

  6. codeforces 715B:Complete The Graph

    Description ZS the Coder has drawn an undirected graph of n vertices numbered from 0 to n - 1 and m ...

  7. Codeforces Round #372 (Div. 1) B. Complete The Graph (枚举+最短路)

    题目就是给你一个图,图中部分边没有赋权值,要求你把无权的边赋值,使得s->t的最短路为l. 卡了几周的题了,最后还是经群主大大指点……做出来的…… 思路就是跑最短路,然后改权值为最短路和L的差值 ...

  8. Codeforces715 B. Complete The Graph

    传送门:>Here< 题意:给出一张带权无向图,其中有一些边权为0.要求将边权为0的边的边权重置为一个任意的正整数,使得从S到T的最短路为L.判断是否存在这种方案,如果存在输出任意一种 解 ...

  9. Codeforces Round #372 (Div. 1) B. Complete The Graph

    题目链接:传送门 题目大意:给你一副无向图,边有权值,初始权值>=0,若权值==0,则需要把它变为一个正整数(不超过1e18),现在问你有没有一种方法, 使图中的边权值都变为正整数的时候,从 S ...

随机推荐

  1. python3中zip()函数的用法

    >>>a = [1,2,3] >>> b = [4,5,6] >>> c = [4,5,6,7,8] >>> zipped = ...

  2. [基本操作]决策单调性优化dp

    一般的式子都是 $f_i = max\{g_j + w_{(i,j)}\}$ 然后这个 $w$ 满足决策单调性,也就是对于任意 $i < j$ ,$best_i \leq best_j$ 这样就 ...

  3. UVA - 11768 Lattice Point or Not (扩展欧几里得)

    求一条线段上有多少个整点. 是道扩欧基础题,列出两点式方程,然后分四种情况讨论即可.但细节处理较多很容易写挫(某zzWA了十几发才过掉的). 由于数据精度较小,浮点数比较没有用eps,直接==比较了. ...

  4. CodeForces - 650D:Zip-line (LIS & DP)

    Vasya has decided to build a zip-line on trees of a nearby forest. He wants the line to be as long a ...

  5. 六、Jmeter后置处理器JSON Extractor

    一.当接口返回是JSON格式的时候,就可以用JSON Extractor来抓取返回的值,用来关联或者断言. 1.首先,到V2EX中找一个接口,地址为:https://www.v2ex.com/p/7v ...

  6. WPF基本概念入门

    关于数据类型,有原子类型,列表类型,字典类型等等,而wpf对应控件有contentControl,itemsControl,headerItemsControl等. 控件和类型一一对应,控件和类型之间 ...

  7. Java-API-Package:javax.annotation

    ylbtech-Java-API-Package:javax.annotation 1.返回顶部 1. Package javax.annotation Enum Summary Resource.A ...

  8. 转:InnoDB Crash Recovery 流程源码实现分析

    此文章转载给登博的文章,给大家分享 InnoDB Crash Recovery 流程源码实现分析 Crash Recovery问题 本文主要分析了InnoDB整个crash recovery的源码处理 ...

  9. Oracle OCM提纲

    ocm提纲 数据库创建详解 ◆ 通过手动方式创建数据库 环境变量的设置 密码文件的创建过程以及使用情景 Oracle数据库中参数文件的演进过程 参数文件的对比 参数的修改方式介绍 数据库启动过程时的内 ...

  10. Python函数(一)-return返回值

    定义一个函数可以在最后加上return返回值,方便查看函数是否运行完成和返回函数的值 # -*- coding:utf-8 -*- __author__ = "MuT6 Sch01aR&qu ...