Codeforces Round #372 (Div. 2)
2017-08-22 09:33
176 查看
A题,每次输入的时候记录,保留上一个的值,做差判断
D
#include<bits/stdc++.h> #define C 0.5772156649 #define pi acos(-1.0) #define ll long long #define mod 1000000007 #define ls l,m,rt<<1 #define rs m+1,r,rt<<1|1 #pragma comment(linker, "/STACK:1024000000,1024000000") using namespace std; const double g=10.0,eps=1e-7; const int N=100000+10,maxn=100+10,inf=0x3f3f3f3f3f; struct edge{ int from,to,Next,c; }e[N*2]; int cnt,head ; int d ; int n,m,L,s,t; bool vis ; vector<int>p; void add(int u,int v,int w) { e[cnt].to=v; e[cnt].c=w; e[cnt].Next=head[u]; head[u]=cnt++; } void spfa() { memset(vis,0,sizeof vis); vis[s]=1; memset(d,inf,sizeof d); d[s]=0; queue<int>q; q.push(s); while(!q.empty()) { int x=q.front(); q.pop(); vis[x]=0; for(int i=head[x];~i;i=e[i].Next) { int To=e[i].to,W=e[i].c; if(d[To]>d[x]+W) { d[To]=d[x]+W; if(!vis[To]) { vis[To]=1; q.push(To); } } } } } int getspfa(ll c) { // cout<<c<<" "; for(int i=0;i<p.size();i++) { e[p[i]].c=e[p[i]^1].c=1+min(c,(ll)1e9); // cout<<e[p[i]].c<<" "; c-=e[p[i]].c-1; } // cout<<endl; spfa(); return d[t]; } int main() { ios::sync_with_stdio(false); cin.tie(0); cin>>n>>m>>L>>s>>t; cnt=0; memset(head,-1,sizeof head); for(int i=0;i<2*m;i+=2) { cin>>e[i].from>>e[i].to>>e[i].c; if(e[i].c==0)p.push_back(cnt); add(e[i].from,e[i].to,e[i].c); add(e[i].to,e[i].from,e[i].c); } if(getspfa(0)>L||getspfa(p.size()*(1e9))<L) { cout<<"NO"<<endl; return 0; } ll l=0,r=p.size()*(1e9); while(l<=r) { ll mid=(l+r)/2; if(getspfa(mid)>L)r=mid-1; else if(getspfa(mid)<L)l=mid+1; else break; } cout<<"YES"<<endl; for(int i=0;i<2*m;i+=2) cout<<e[i].from<<" "<<e[i].to<<" "<<e[i].c<<endl; return 0; } /******************** 4 4 13 1 3 1 3 14 2 3 0 2 0 0 1 0 0 ********************/
D
相关文章推荐
- code forces round 372 div2.c Plus and Square Root
- Codeforces Round #372 (Div. 2) C. Plus and Square Root —— 构造(数学题)
- Codeforces Round #372 (Div. 2)
- Codeforces Round #372 (Div. 2) -- C. Plus and Square Root(找规律枚举)
- Codeforces Round #372 (Div. 2) E. Digit Tree (点分治)
- codeforces round#372(div2 C) C. Plus and Square Root
- Codeforces Round #372 (Div. 2) C. Plus and Square Root 数论、方程、化简、推公式
- Codeforces Round #372 (Div. 2) D. Complete The Graph 图论、最短路、Dijkstra、路径、分配部分边权
- Codeforces Round #136 (Div. 2) A. Little Elephant and Function
- Codeforces Round #449 (Div. 1) B. Ithea Plays With Chtholly
- 【Codeforces Round 333 (Div 2)C】【最短路】The Two Routes 完全图两种双向边的最小最大距离
- Codeforces Round #415 (Div. 1) A Do you want a date?
- Codeforces Round #202 (Div. 2)A
- Codeforces Round #204 (Div. 2) C Jeff and Rounding
- Codeforces Round #238 (Div. 2)
- Codeforces Round #287 (Div. 2) C. Guess Your Way Out! 二叉树遍历
- Codeforces Round #295 (Div. 2)(A,B,C)
- Codeforces Round #238 (Div. 1)
- codeforces round# 177 div2
- Codeforces Round #265 (Div. 2) C.No to Palindromes!