跳到正文

题解

Delay Constrained Maximum Capacity Path

wanghaoran000约 4 分钟
原文
文章信息与版本

文章信息

发布
2026年7月15日
收录
2026年7月15日
更新
2026年11月13日
篇幅
约 4 分钟

版本

  1. v1当前

题意
给出N个点,M条边的无向图。而根据题意,序号为1的点为矿山,序号为n的点为加工厂。给出每条边的容量与通过时间,而每一条路径的最大容量为这条路径上的边容量的最小值,求当总时间<T时,寻找一条从1到N的路径,保证其路径容量最大,输出最大值。
思路
先用二分取对于边的限制,再用spfa跑一遍图,如果走通就可以,不行取下一个二分的值,最后取最大容量即可。
代码

C++
#include<bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int N = 10005;
struct Edge
{
    int v, cap, time;
};//
int n,m,T;
vector<Edge> g[N];
int dist[N];
bool vis[N];
int limit;
void spfa(int s)
{
    memset(dist,0x3f,sizeof(dist));
    memset(vis,0,sizeof(vis));
    queue<int> q;
    dist[s]=0;
    q.push(s);
    vis[s]=true;
    while(!q.empty())
    {
        int u=q.front();
        q.pop();
        vis[u]=false;
        for(auto e:g[u])
        {
            if(e.cap<limit) continue;
            int v=e.v;
            if(dist[v]>dist[u]+e.time)
            {
                dist[v]=dist[u]+e.time;
                if(!vis[v])
                {
                    vis[v]=true;
                    q.push(v);
                }
            }
        }
    }
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t;
    cin>>t;
    while(t--)
    {
        cin>>n>>m>>T;
        for(int i=1;i<=n;i++) g[i].clear();
        vector<int> a(m);
        for(int i=0;i<m;i++)
        {
            int u,v,c,d;
            cin>>u>>v>>c>>d;
            g[u].push_back({v,c,d});
            g[v].push_back({u,c,d});
            a[i]=c;
        }
        sort(a.begin(),a.end());
        int l=0,r=m-1,ans=a[0];
        while(l<=r)
        {
            int mid=(l+r)/2;
            limit=a[mid];
            spfa(1);
            if(dist[n]<=T)
            {
                ans=a[mid];
                l=mid+1;
            }
            else
            {
                r=mid-1;
            }
        }
        cout<<ans<<'\n';
    }
    return 0;
}
原文