#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>
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;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
1736 KB |
Output is correct |
2 |
Correct |
0 ms |
1736 KB |
Output is correct |
3 |
Correct |
0 ms |
1736 KB |
Output is correct |
4 |
Correct |
0 ms |
1736 KB |
Output is correct |
5 |
Correct |
0 ms |
1736 KB |
Output is correct |
6 |
Correct |
0 ms |
1736 KB |
Output is correct |
7 |
Correct |
0 ms |
1736 KB |
Output is correct |
8 |
Correct |
0 ms |
1736 KB |
Output is correct |
9 |
Correct |
0 ms |
1736 KB |
Output is correct |
10 |
Correct |
0 ms |
1736 KB |
Output is correct |
11 |
Correct |
0 ms |
1736 KB |
Output is correct |
12 |
Correct |
0 ms |
1736 KB |
Output is correct |
13 |
Correct |
0 ms |
1736 KB |
Output is correct |
14 |
Correct |
0 ms |
1736 KB |
Output is correct |
15 |
Correct |
0 ms |
1736 KB |
Output is correct |