제출 #3943

#제출 시각아이디문제언어결과실행 시간메모리
3943Apple_CplusFollowing Flow (kriii1_F)C++98
0 / 1
0 ms1684 KiB
#include <stdio.h> #include <iostream> #include <vector> #include <queue> #include <algorithm> #include <sstream> #include <set> #include <map> #include <stack> #include <cmath> #include <cstdlib> #include <cstring> #include <string> using namespace std; #define EPS 1e-9 vector<int> adj[33]; vector<int> wht[33]; int in[33],out[33]; int n,m; double a[33][33],b[33]; void gauss() { for(int i=0;i<=n;++i) { double mx = 0; int idx = -1; for(int j=i;j<=n;++j) if(abs(a[j][i]) > mx) { mx = abs(a[j][i]); idx = j; } for(int j=0;j<=n;++j) swap(a[i][j],a[idx][j]); swap(b[i],b[idx]); double tt = a[i][i]; for(int k=i;k<=n;++k) a[i][k] /= tt; b[i] /= tt; for(int j=0;j<=n;++j) if(j != i && abs(a[j][i]) > EPS) { double tmp = a[j][i]; for(int k=0;k<=n;++k) { a[j][k] -= tmp * a[i][k]; } b[j] -= tmp * b[i]; } } } int main() { scanf("%d%d",&n,&m); for(int i=0;i<m;++i) { int u,v,w; scanf("%d%d%d",&u,&v,&w); adj[u].push_back(v); wht[u].push_back(w); out[u]++, in[v]++; } for(int u=0;u<=n;++u) { a[u][u] = 1; for(int i=0;i<adj[u].size();++i) { int v = adj[u][i]; int w = wht[u][i]; a[u][v] = -1.0/out[u]; b[u] += 1.0 * w / out[u]; } } gauss(); printf("%.10lf",b[0]); }
#Verdict Execution timeMemoryGrader output
Fetching results...