把样例推翻了!!!
查看原帖
把样例推翻了!!!
125966
VOILinK楼主2021/11/12 19:36

0 4 2 1 2.63
0 5 2 3 1 2.66成功推翻样例

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pdi pair<double,pair<int,int> >
#define mp make_pair
const int maxn=501*150+5;
double dis[maxn];
bool vis[maxn];
int base=501,cnt=0,head[maxn],last[maxn],n,m,t;
struct edge{
    int to,next,L,V;
}e[maxn];
void add(int u,int v,int V,int L){
    e[++cnt].to=v,e[cnt].next=head[u],head[u]=cnt,e[cnt].V=V,e[cnt].L=L;
}
void dijkstra(int x){
    for(int i=1;i<=150*501;i++) dis[i]=2000000000.0;
    memset(vis,0,sizeof(vis));
    priority_queue<pdi> q;
    q.push(mp(0.0,mp(70,70)));
    dis[70]=0.0;
    while(!q.empty()){
        int now=q.top().second.first,nv=q.top().second.second;
        q.pop();
        if(vis[now]) continue;
        vis[now]=1;
        for(int i=head[now];i;i=e[i].next){
            int v=e[i].to*base+e[i].V;
            if(e[i].V&&dis[v]>dis[now]+e[i].L*1.0/e[i].V&&!vis[v]){
                dis[v]=dis[now]+e[i].L*1.0/e[i].V;
                last[v]=now;
                q.push(mp(-dis[v],mp(v,e[i].V)));
            }
            if(e[i].V==0&&dis[v]>dis[now]+e[i].L*1.0/nv&&!vis[v]){
                last[v]=now;
                dis[v]=dis[now]+e[i].L*1.0/nv;
                q.push(mp(-dis[v],mp(v,nv)));
            }
        }
    }
}
int main(){
    cin>>n>>m>>t;
    for(int i=1;i<=m;i++){
        int u,v,V,L;
        scanf("%d%d%d%d",&u,&v,&V,&L);
        for(int j=1;j<base;j++) add(u*base+j,v,V,L);
    }
    dijkstra(0);
    double ans=2000000000.0;
    int flag;
    for(int i=base-1;i>=0;i--) if(dis[t*base+i]<ans) ans=dis[t*base+i],flag=t*base+i;
    while(flag) printf("%d ",flag/base),flag=last[flag];
    printf("\n%0.6f",ans);
    return 0;
}

2021/11/12 19:36
加载中...