zoukankan      html  css  js  c++  java
  • luogu_1462 通往奥格瑞玛的道路

    #include <iostream>
    #include <cstdio>
    #include <queue>
    #include <algorithm>
    #include <cstring>
    using namespace std;
    const int maxn=10010;
    const int maxm=50010;
    const int INF=1<<30;
    struct edge{int v,b;};
    int n,m,b,cost[maxn],d[maxn],s=1,t,ans;
    bool vis[maxn];
    vector<edge> G[maxm];
    queue<int> q;
    
    bool spfa(int x){
    	memset(vis,0,sizeof(vis));
    	for(int i=1;i<=n;i++)d[i]=INF;
    	q.push(s); d[s]=0; vis[s]=1;
    	if(cost[s]>x)return false;
    	while(!q.empty()){
    		int u=q.front(); q.pop(); vis[u]=0;
    		for(int i=0;i<G[u].size();i++){
    			int v=G[u][i].v,rd=G[u][i].b;
    			if(d[u]+rd<d[v] && d[u]+rd<=b && cost[v]<=x){
    				d[v]=d[u]+rd;
    				if(!vis[v]){q.push(v); vis[v]=1;}
    			}
    		}
    	}
    	return d[t]!=INF;
    }
    
    int main(){
    	scanf("%d%d%d",&n,&m,&b);
    	t=n;
    	int l=0,r=0;
    	for(int i=1;i<=n;i++){scanf("%d",&cost[i]); r=max(r,cost[i]);}
    	while(m--){
    		int u,v,b;
    		scanf("%d%d%d",&u,&v,&b);
    		G[u].push_back((edge){v,b}); G[v].push_back((edge){u,b});
    	}
    
    	while(l<=r){
    		int mid=(l+r)/2;
    		if(spfa(mid)){
    			ans=mid;
    			r=mid-1;
    		}
    		else l=mid+1;
    	}
    	if(!ans)puts("AFK");
    	else printf("%d
    ",ans);
    	return 0;
    }
    

      

  • 相关阅读:
    一本通1647迷路
    一本通1646GT 考试
    矩阵
    矩阵快速幂
    数学基础
    清北学堂学习经验(论颓废)
    钟皓曦第二天讲课
    P3275 [SCOI2011]糖果
    P1270 “访问”美术馆
    P2015 二叉苹果树
  • 原文地址:https://www.cnblogs.com/codetogether/p/7570879.html
Copyright © 2011-2022 走看看