# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
3618 | blmarket | Following Flow (kriii1_F) | C++98 | 0 ms | 1680 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 <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <sstream>
#include <numeric>
#include <iterator>
#include <queue>
#include <set>
#include <map>
#include <vector>
#define mp make_pair
#define pb push_back
#define sqr(x) ((x)*(x))
#define foreach(it,c) for(typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it)
using namespace std;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int,int> PII;
template<typename T> int size(const T &a) { return a.size(); }
int n,m;
double mat[33][33];
double num[33];
vector<PII> out[33];
int main(void)
{
cin >> n >> m;
for(int i=0;i<m;i++) {
int a,b,c;
cin >> a >> b >> c;
out[a].pb(mp(b,c));
num[a] += c;
if(b < n) mat[a][b] += 1;
}
for(int i=0;i<n;i++) {
num[i] /= out[i].size();
for(int j=0;j<n;j++) {
mat[i][j] /= out[i].size();
cout << mat[i][j] << " ";
}
cout << "= " << num[i] << endl;
}
while(n) {
int t = n-1;
// do something for mat[t][t]
double divi = 1 - mat[t][t];
for(int i=0;i<t;i++) mat[t][i] /= divi;
num[t] /= divi;
if(n == 1) {
printf("%.12lf\n", num[t]);
return 0;
}
for(int i=0;i<t;i++) {
for(int j=0;j<t;j++) {
mat[i][j] += mat[i][t] * mat[t][j];
}
num[i] += mat[i][t] * num[t];
}
n--;
for(int i=0;i<n;i++) {
for(int j=0;j<n;j++) {
cout << mat[i][j] << " ";
}
cout << "= " << num[i] << endl;
}
}
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |