拓扑排序:绿豆蛙的归宿
作者:互联网
题目链接:点击这里
#include<cstdio>
#include<iostream>
#include<cstring>
#include<queue>
#include<algorithm>
typedef long long ll;
typedef long double ld;
using namespace std;
const int maxn=1e5+5;
const int maxm=2e5+5;
ll in[maxn],head[maxn],num=0,ans=0,out[maxn];
double dp[maxn];
struct node{
ll next,to,len;
}kkk[maxm];
void addedge(ll u,ll v,ll w){
kkk[++num].next=head[u];
kkk[num].to=v;
kkk[num].len=w;
head[u]=num;
}
int main()
{
int n,m;
scanf("%d%d",&n,&m);
for(ll i=0;i<m;++i){
ll u,v,w;
scanf("%lld%lld%lld",&u,&v,&w);
addedge(v,u,w);
++out[u],++in[u];
}
queue<ll>q;
q.push(n);
while(!q.empty()){
ll u=q.front();q.pop();
for(ll i=head[u];i;i=kkk[i].next){
ll v=kkk[i].to;
dp[v]+=(kkk[i].len+dp[u])/out[v];
--in[v];
if(!in[v]) q.push(v);
//printf("%d %d\n",v,in[v]);
}
}
printf("%.2f",dp[1]);
return 0;
}
标签:include,int,拓扑,绿豆蛙,num,maxn,kkk,排序,ll 来源: https://blog.csdn.net/qq_45695839/article/details/114464178