Submission #8197123


Source Code Expand

Copy
#include <bits/stdc++.h>
using namespace std;
using Int = int_fast64_t;

void func(Int n, vector<double> &ex, vector<vector<Int>> &g, Int f, Int t){
	ex.assign(n, 0.0);
	for(Int i=n-2; i>=0; --i){
		Int cnt = 0;
		for(Int j=i+1; j<n; ++j)
			if(g[i][j] == 1 && (i != f || j != t))
				++cnt;
		for(Int j=i+1; j<n; ++j)
			if(g[i][j] == 1 && (f != i || t != j))
				ex[i] += (ex[j] + 1) / cnt;
		if(cnt == 0) ex[i] = 1e10;
	}
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	Int n, m; cin >> n >> m;
	vector<vector<Int>> g(n, vector<Int>(n, 0));
	for(Int i=0; i<m; ++i){
		Int s, t; cin >> s >> t;
		g[s-1][t-1] = 1;
	}
	vector<double> ex(n);
	func(n, ex, g, -1, -1);
	double ans = ex[0];
//	cerr << ans << "\n";
//	for(Int i=0; i<n; ++i)
//		cerr << i << " " << ex[i] << "\n";
	vector<Int> w(n-1, -1);
	for(Int i=0; i<n-1; ++i)
		for(Int j=i+1; j<n; ++j)
			if(g[i][j] == 1 && (w[i] == -1 || ex[w[i]] < ex[j]))
				w[i] = j;
	for(Int i=0; i<n-1; ++i){
		func(n, ex, g, i, w[i]);
		ans = min(ans, ex[0]);
//		cerr << i << " " << w[i] << " " << ex[0] << " " << ans << "\n";
//		if(i == 6)
//			for(Int j=0; j<n; ++j)
//				cerr << j << " " << ex[j] << "\n";
	}
	cout << fixed << setprecision(10) << ans << "\n";
}

Submission Info

Submission Time
Task F - Fork in the Road
User Power730
Language C++14 (GCC 5.4.1)
Score 600
Code Size 1268 Byte
Status AC
Exec Time 778 ms
Memory 3072 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 600 / 600
Status
AC × 3
AC × 65
Set Name Test Cases
Sample 00-sample-00, 00-sample-01, 00-sample-02
All 00-sample-00, 00-sample-01, 00-sample-02, 01-handmade-03, 01-handmade-04, 01-handmade-05, 01-handmade-06, 01-handmade-07, 01-handmade-08, 01-handmade-09, 02-small-10, 02-small-11, 02-small-12, 02-small-13, 02-small-14, 02-small-15, 02-small-16, 02-small-17, 02-small-18, 02-small-19, 02-small-20, 02-small-21, 02-small-22, 02-small-23, 02-small-24, 03-medium-25, 03-medium-26, 03-medium-27, 03-medium-28, 03-medium-29, 03-medium-30, 03-medium-31, 03-medium-32, 03-medium-33, 03-medium-34, 03-medium-35, 03-medium-36, 03-medium-37, 03-medium-38, 03-medium-39, 03-medium-40, 03-medium-41, 03-medium-42, 03-medium-43, 03-medium-44, 04-large-45, 04-large-46, 04-large-47, 04-large-48, 04-large-49, 04-large-50, 04-large-51, 04-large-52, 04-large-53, 04-large-54, 04-large-55, 04-large-56, 04-large-57, 04-large-58, 04-large-59, 04-large-60, 04-large-61, 04-large-62, 04-large-63, 04-large-64
Case Name Status Exec Time Memory
00-sample-00 AC 1 ms 256 KB
00-sample-01 AC 1 ms 256 KB
00-sample-02 AC 1 ms 256 KB
01-handmade-03 AC 623 ms 3072 KB
01-handmade-04 AC 622 ms 3072 KB
01-handmade-05 AC 1 ms 256 KB
01-handmade-06 AC 629 ms 3072 KB
01-handmade-07 AC 161 ms 3072 KB
01-handmade-08 AC 619 ms 3072 KB
01-handmade-09 AC 1 ms 256 KB
02-small-10 AC 1 ms 256 KB
02-small-11 AC 1 ms 256 KB
02-small-12 AC 1 ms 256 KB
02-small-13 AC 1 ms 256 KB
02-small-14 AC 1 ms 256 KB
02-small-15 AC 1 ms 256 KB
02-small-16 AC 1 ms 256 KB
02-small-17 AC 1 ms 256 KB
02-small-18 AC 1 ms 256 KB
02-small-19 AC 1 ms 256 KB
02-small-20 AC 1 ms 256 KB
02-small-21 AC 1 ms 256 KB
02-small-22 AC 1 ms 256 KB
02-small-23 AC 1 ms 256 KB
02-small-24 AC 1 ms 256 KB
03-medium-25 AC 1 ms 256 KB
03-medium-26 AC 2 ms 256 KB
03-medium-27 AC 2 ms 256 KB
03-medium-28 AC 2 ms 256 KB
03-medium-29 AC 4 ms 384 KB
03-medium-30 AC 1 ms 256 KB
03-medium-31 AC 2 ms 256 KB
03-medium-32 AC 2 ms 256 KB
03-medium-33 AC 3 ms 256 KB
03-medium-34 AC 3 ms 384 KB
03-medium-35 AC 2 ms 384 KB
03-medium-36 AC 2 ms 256 KB
03-medium-37 AC 4 ms 384 KB
03-medium-38 AC 2 ms 256 KB
03-medium-39 AC 1 ms 256 KB
03-medium-40 AC 2 ms 384 KB
03-medium-41 AC 2 ms 256 KB
03-medium-42 AC 3 ms 256 KB
03-medium-43 AC 3 ms 384 KB
03-medium-44 AC 3 ms 384 KB
04-large-45 AC 145 ms 2688 KB
04-large-46 AC 217 ms 3072 KB
04-large-47 AC 372 ms 2688 KB
04-large-48 AC 522 ms 2688 KB
04-large-49 AC 633 ms 2688 KB
04-large-50 AC 160 ms 2944 KB
04-large-51 AC 199 ms 2816 KB
04-large-52 AC 400 ms 2816 KB
04-large-53 AC 598 ms 2944 KB
04-large-54 AC 733 ms 3072 KB
04-large-55 AC 140 ms 2688 KB
04-large-56 AC 227 ms 3072 KB
04-large-57 AC 371 ms 2688 KB
04-large-58 AC 551 ms 2816 KB
04-large-59 AC 610 ms 2688 KB
04-large-60 AC 169 ms 2944 KB
04-large-61 AC 225 ms 3072 KB
04-large-62 AC 437 ms 3072 KB
04-large-63 AC 652 ms 3072 KB
04-large-64 AC 778 ms 3072 KB