Pagini recente » Cod sursa (job #2961032) | Cod sursa (job #2223137) | Cod sursa (job #1123280) | Cod sursa (job #2883144) | Cod sursa (job #1521548)
#include <cstdio>
#include <vector>
#include <stack>
#include <algorithm>
#include <conio.h>
#define MMAX 100007
#define PII pair<int, int>
#define pb push_back
using namespace std;
int n, m, x, y, z, sze, update;
double ans;
vector <PII> adj[MMAX];
PII tmp;
struct dfp
{
int lung;
int nod;
int prob;
} aux, curr;
stack <dfp> dfs;
inline void compute_dfs()
{
aux.lung = 0;
aux.nod = 1;
aux.prob = 1;
dfs.push(aux);
while(!dfs.empty())
{
curr = dfs.top();
dfs.pop();
//printf("node = %d\n", curr.nod);
//getch();
if(curr.lung >= 1000) continue;
if(curr.prob > 400000000) continue;
if(curr.nod == n)
{
//printf("addval = %lf\n", ((double)curr.lung/(double)curr.prob));
//printf("compo : %d %d\n", curr.lung, curr.prob);
ans += ((double)curr.lung/(double)curr.prob);
continue;
}
sze = adj[curr.nod].size();
update = curr.prob * sze;
for(int i = 0; i< sze; ++i)
{
aux.lung = curr.lung + adj[curr.nod][i].second;
aux.nod = adj[curr.nod][i].first;
aux.prob = update;
dfs.push(aux);
}
}
}
int main()
{
freopen("tunel.in", "r", stdin);
freopen("tunel.out", "w", stdout);
scanf("%d %d", &n, &m);
for(; m; --m)
{
scanf("%d%d%d", &x, &y, &z);
tmp.second = z;
tmp.first = y;
adj[x].pb(tmp);
swap(tmp.first, x);
adj[x].pb(tmp);
}
compute_dfs();
printf("%lf\n", ans);
//printf("%lf\n", (double)(3/4));
return 0;
}