답안 #3621

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
3621 2013-08-31T07:03:00 Z blmarket Following Flow (kriii1_F) C++
1 / 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--;
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 1680 KB Output is correct
2 Correct 0 ms 1680 KB Output is correct
3 Correct 0 ms 1680 KB Output is correct
4 Correct 0 ms 1680 KB Output is correct
5 Correct 0 ms 1680 KB Output is correct
6 Correct 0 ms 1680 KB Output is correct
7 Correct 0 ms 1680 KB Output is correct
8 Correct 0 ms 1680 KB Output is correct
9 Correct 0 ms 1680 KB Output is correct
10 Correct 0 ms 1680 KB Output is correct
11 Correct 0 ms 1680 KB Output is correct
12 Correct 0 ms 1680 KB Output is correct
13 Correct 0 ms 1680 KB Output is correct
14 Correct 0 ms 1680 KB Output is correct
15 Correct 0 ms 1680 KB Output is correct