传送门

题目大意

给出一个图,一些边带权,另一些边等待你赋权(最小赋为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. libmodbus相关资料整理

    /****************************************************************************** * libmodbus相关资料整理 * ...

  2. CodeForces - 156C:Cipher (不错的DP)

    Sherlock Holmes found a mysterious correspondence of two VIPs and made up his mind to read it. But t ...

  3. Cow Exhibition (背包中的负数问题)

    个人心得:背包,动态规划真的是有点模糊不清,太过于抽象,为什么有些是从后面递推, 有些状态就是从前面往后面,真叫人头大. 这一题因为涉及到负数,所以网上大神们就把开始位置从10000开始,这样子就转变 ...

  4. mysql5.6之 传输表空间迁移表或恢复误删除的表

    一,简单说明: 1),传输表空间的限制:  1,mysql 版本 5.6.6 及其以上,并且版本建议源和目标版本建议都是GA版并且大版本一样  2,表引擎为innodb并且开启独立表空间  innod ...

  5. bzoj 2744 [HEOI2012]朋友圈——补图!+匈牙利算法

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2744 求最大的团<==>补图(有边的变成没边.没边的变成有边)的最大独立集! A ...

  6. bzoj 3629 [JLOI2014]聪明的燕姿——约数和定理+dfs

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3629 如果要搜索,肯定得质因数分解吧:就应该朝这个方向想. **约数和定理: 对于任意一个大 ...

  7. python 修改文件内容

    python 修改文件内容 一.修改原文件方式 1 def alter(file,old_str,new_str): 2 """ 3 替换文件中的字符串 4 :param ...

  8. oracle如何查看表空间

    1.用户 查看当前用户的缺省表空间 SQL>select username,default_tablespace from user_users; 查看当前用户的角色 SQL>select ...

  9. SPI驱动框架-1(DM8127 Linux2.6.37为例)

    一.驱动程序结构 1.platform_device 文件:/arch/arm/mach-omap2/device.c static struct omap2_mcspi_platform_confi ...

  10. 【转】 Pro Android学习笔记(八四):了解Package(3):包间数据共享

    目录(?)[-] 共享User ID的设置 共享资源例子 文章转载只能用于非商业性质,且不能带有虚拟货币.积分.注册等附加条件.转载须注明出处:http://blog.csdn.net/flowing ...