# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
19183 | cki86201 | Following Flow (kriii1_F) | C++98 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <iostream>
#include <functional>
#include <unordered_set>
#include <unordered_map>
#include <time.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> Pi;
#define Fi first
#define Se second
#define pb(x) push_back(x)
#define sz(x) (int)x.size()
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) x.begin(),x.end()
double A[35][35], b[35];
int n, m;
int deg[35], sl[35];
int E[35][35];
int main(){
scanf("%d%d", &n, &m);
rep(i, m){
int x, y, z;
scanf("%d%d%d", &x, &y, &z);
deg[x]++;
E[x][y]++;
sl[x] += z;
}
rep(i, n)b[i] = (double)sl[i] / deg[i], A[i][i] = 1;
rep(i, n)rep(j, n){
A[i][j] -= (double)E[i][j] / deg[i];
}
for(int i=1;i<n;i++){
for(int j=0;j<i;j++){
//A[i][j] to 0;
//A[i] -= x * A[j]
double x = A[i][j] / A[j][j];
for(int k=j;k<n;k++)A[i][k] -= x * A[j][k];
b[i] -= x * b[j];
}
}
for(int i=n-1;i>=0;i--){
b[i] /= A[i][i];
for(int j=i-1;j>=0;j--)b[j] -= b[i] * A[j][i];
}
printf("%.10f", b[0]);
return 0;
}