跳至正文

1 条题解

  • 0
    @ 2026-10-2 2:21:54

    用long double计算最大保留比例,优先队列处理所有转账方式,避免double在1999段99%手续费链上溢出或下溢。

    #include <bits/stdc++.h>
    using namespace std;
    
    int main(){ios::sync_with_stdio(false);cin.tie(nullptr);
    
    int n,m;cin>>n>>m;vector<vector<pair<int,int>>>graph(n+1);while(m--){int u,v,z;cin>>u>>v>>z;graph[u].push_back({v,z});graph[v].push_back({u,z});}int start,end;cin>>start>>end;vector<long double>d(n+1);d[start]=1;priority_queue<pair<long double,int>>q;q.push({1,start});while(!q.empty()){auto[p,u]=q.top();q.pop();if(p<d[u])continue;if(u==end)break;for(auto[v,z]:graph[u]){long double next=p*(100-z)/100;if(next>d[v]){d[v]=next;q.push({next,v});}}}cout<<fixed<<setprecision(8)<<100/d[end]<<"\n";
    
    return 0;
    }
    
    • 1

    信息

    ID
    4019
    时间
    1000ms
    内存
    128MiB
    难度
    5
    标签
    递交数
    0
    已通过
    0
    上传者