Submission #3618

# Submission time Handle Problem Language Result Execution time Memory
3618 2013-08-31T07:01:43 Z blmarket Following Flow (kriii1_F) C++
0 / 1
0 ms 1680 KB
#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
1 Incorrect 0 ms 1680 KB Output isn't correct
2 Halted 0 ms 0 KB -