zoukankan      html  css  js  c++  java
  • 【洛谷P1462】通往奥格瑞玛的道路

    通往奥格瑞玛的道路

    题目链接

    这道题好像和电话线是同一道题。。

    二分答案(答案一定是某一顶点的花费),spfa求最小血量消耗

     1 #include<algorithm>
     2 #include<iostream>
     3 #include<cstring>
     4 #include<cstdio>
     5 using namespace std;
     6 #define int long long
     7 #define INF 9999999999999ll
     8 #define N 10010
     9 #define M 100010
    10 int n,m,b,dis[N],f[N],a[N];
    11 int Head[N],num;
    12 int que[10000010],head,tail;
    13 bool inque[N];
    14 struct NODE{
    15     int to,next,w;
    16 } e[M];
    17 inline int read(){
    18     int x=0; char c=getchar();
    19     while(c<'0'||c>'9') c=getchar();
    20     while('0'<=c&&c<='9') { x=(x<<3)+(x<<1)+c-'0'; c=getchar(); }
    21     return x;
    22 }
    23 inline void add(int x,int y,int w){
    24     e[++num].to=y;
    25     e[num].w=w;
    26     e[num].next=Head[x];
    27     Head[x]=num;
    28 }
    29 bool check(int s){
    30     memset(dis,127,sizeof(dis));
    31     memset(inque,0,sizeof(inque));
    32     head=tail=0;
    33     if(f[1]>s) return 0;
    34     que[++tail]=1;
    35     dis[1]=0;
    36     while(head<tail){
    37         int u=que[++head]; inque[u]=0;
    38         for(int i=Head[u];i;i=e[i].next){
    39             int v=e[i].to;
    40             if(f[v]>s) continue;
    41             if(dis[v]<=dis[u]+e[i].w) continue;
    42             dis[v]=dis[u]+e[i].w;
    43             if(!inque[v]){
    44                 inque[v]=1;
    45                 que[++tail]=v;
    46             }
    47         }
    48     }
    49     return dis[n]<b;
    50 }
    51 #undef int
    52 int main()
    53 #define int long long
    54 {
    55     n=read(); m=read(); b=read();
    56     for(int i=1;i<=n;i++){
    57         f[i]=read();
    58         a[i]=f[i];
    59     }
    60     sort(a+1,a+1+n);
    61     int x,y,w;
    62     for(int i=1;i<=m;i++){
    63         x=read(); y=read(); w=read();
    64         add(x,y,w); add(y,x,w);
    65     }
    66     if(!check(a[n])){
    67         puts("AFK");
    68         return 0;
    69     }
    70     int l=1,r=n;
    71     while(l<r){
    72         int mid=(l+r)>>1;
    73         if(check(a[mid])) r=mid;
    74         else l=mid+1;
    75     }
    76     printf("%lld",a[l]);
    77     return 0;
    78 }
  • 相关阅读:
    《C++反汇编与逆向分析技术揭秘》--构造函数 读书笔记
    《C++反汇编与逆向分析技术揭秘》--虚函数 读书笔记
    VPP-main() 源码学习
    【转】几种TCP连接中出现RST的情况
    动态追踪学习
    RCU学习总结
    内核栈回溯原理学习应用
    《C++反汇编与逆向分析技术揭秘》--单类继承 读书笔记
    C# 防火墙操作之创建规则
    C# 防火墙操作之特定程序
  • 原文地址:https://www.cnblogs.com/yjkhhh/p/9372067.html
Copyright © 2011-2022 走看看