我的代码为什么会wa啊和题解一模一样啊
查看原帖
我的代码为什么会wa啊和题解一模一样啊
1062697
hellocccl楼主2024/11/7 11:44
//ALL IN
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define int long long
#define double long double
const int N=2e5+7;
const int mod=1e9+7;
const int inf=4e18;
mt19937 rnd(time(0));
clock_t start,over;// start=clock(); last=(final-over)*1.0/1000
inline int read(){int x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=x*10+ch-'0',ch=getchar();}return x*f;}
inline void write(int x){if(x<0)putchar('-'),x=-x;if(x>9)write(x/10);putchar(x%10+'0');return;}
int dout[N];
double f[N];
struct node{
    int v,w;
};
vector<node>g[N];
void dfs(int x){
    double res=0;
    for(auto &[y,w]:g[x]){
        dfs(y);
        int k=g[x].size();
        res+=(f[y]+w)*1.0/dout[x];
    }
    f[x]=res;
}
void solve(){
    int n,m;cin>>n>>m;
    for(int i=1;i<=n;i++){
        int u,v,w;cin>>u>>v>>w;
        dout[u]++;
        g[u].push_back({v,w});
    }
    dfs(1);
    double ans=f[1];
    cout<<fixed<<setprecision(2)<<ans<<'\n';
}

signed main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    int _=1;
    // cin>>_;
    while(_--)solve();
}

2024/11/7 11:44
加载中...