Submission #3618

#TimeUsernameProblemLanguageResultExecution timeMemory
3618blmarketFollowing Flow (kriii1_F)C++98
0 / 1
0 ms1680 KiB
#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 timeMemoryGrader output
Fetching results...