acwing上这题数据弱了,在洛谷再次遇到这题时,我将acing上AC的代码复制提交,结果WA了。
acwing上打卡链接(未改)
https://www.acwing.com/file_system/file/content/whole/index/content/2830464/
洛谷
https://www.luogu.com.cn/problem/P4316
acwing上做法,AC代码
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int N = 100010, M = 200010;
int n, m;
int h[N], e[M], w[M], ne[M], idx;
int dout[N];
double f[N];
void add(int a,int b,int c)
{
e[idx] = b,ne[idx] = h[a],w[idx]=c,h[a]=idx++;
}
double dp(int u)
{
if(f[u]>=0)return f[u];
f[u]=0;
for(int i=h[u];i!=-1;i=ne[i])
{
int j=e[i];
f[u]+=(w[i]+dp(j))/dout[u];
}
return f[u];
}
int main()
{
cin >> n >> m;
memset(h,-1,sizeof h);
for(int i=0;i<m;i++)
{
int a,b,c;
cin >> a >> b >> c;
add(a,b,c);
dout[a]++;
}
memset(f,-1,sizeof f);
printf("%.2lf\n",dp(1));
return 0;
}
这位巨巨写的好
https://www.acwing.com/solution/content/25991/