样例未过,结果AC,求调并求原因
查看原帖
样例未过,结果AC,求调并求原因
749175
114514xxx楼主2024/10/23 20:14
#include<bits/stdc++.h>
using namespace std;
const int N=2e6+25;
struct Edge{
    int next,to;
    double w;
}edge[N];
int head[N],cnt;
int n,m,out[N];
inline void add(int x,int y,double z){
    edge[++cnt].to=y;
    edge[cnt].w=z;
    edge[cnt].next=head[x];
    head[x]=cnt;
}
double f[N];
inline void dfs(int u){
    for(int i=head[u];i;i=edge[i].next){
        int v=edge[i].to;
        dfs(v);
        f[u]+=(f[v]+edge[i].w*1.0)/out[u]*1.0;
    }
}
int main(){
    cin>>n>>m;
    int u,v;
    double w;
    for(int i=1;i<=m;i++){
        cin>>u>>v>>w;
        add(u,v,w);
        out[u]++;
    }
    dfs(1);
    printf("%.2lf",f[1]);
}

2024/10/23 20:14
加载中...