Submission #409102

#TimeUsernameProblemLanguageResultExecution timeMemory
409102cheissmartTravelling Merchant (APIO17_merchant)C++14
12 / 100
33 ms1100 KiB
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define double long double

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;

string _reset = "\u001b[0m", _yellow = "\u001b[33m", _bold = "\u001b[1m";
void DBG() { cerr << "]" << _reset << endl; }
template<class H, class...T> void DBG(H h, T ...t) {
	cerr << to_string(h);
	if(sizeof ...(t)) cerr << ", ";
	DBG(t...);
}
#ifdef CHEISSMART
#define debug(...) cerr << _yellow << _bold << "Line(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#else
#define debug(...)
#endif

const int INF = 0x3f3f3f3f, N = 105, K = 1005;
const ll oo = 1e18;
const double eps = 1e-9;

int cost[N][K][2];
int a[N][N], b[N][N];
double c[N][N];

signed main()
{
	IO_OP;

	memset(a, 0x3f, sizeof a);

	int n, m, k;
	cin >> n >> m >> k;
	for(int i = 0; i < n; i++)
		for(int j = 0; j < k; j++) {
			cin >> cost[i][j][0] >> cost[i][j][1];
		}
	for(int i = 0; i < n; i++)
		a[i][i] = 0;
	for(int i = 0; i < m; i++) {
		int u, v, w;
		cin >> u >> v >> w;
		u--, v--;
		a[u][v] = min(a[u][v], w);
	}
	for(int k = 0; k < n; k++)
		for(int i = 0; i < n; i++)
			for(int j = 0; j < n; j++)
				a[i][j] = min(a[i][j], a[i][k] + a[k][j]);

	for(int i = 0; i < n; i++)
		for(int j = 0; j < n; j++)
			for(int l = 0; l < k; l++) {
				if(cost[j][l][1] != -1 && cost[i][l][0] != -1)
					b[i][j] = max(b[i][j], cost[j][l][1] - cost[i][l][0]);
			}

	auto ok = [&] (double eff) {
		// for(int i = 0; i < n; i++)
		// 	for(int j = 0; j < n; j++) {
		// 		if(a[i][j] < INF)
		// 			c[i][j] = a[i][j] * eff - b[i][j];
		// 		else 
		// 			c[i][j] = oo;
		// 	}
		// for(int k = 0; k < n; k++)
		// 	for(int i = 0; i < n; i++)
		// 		for(int j = 0; j < n; j++)
		// 			c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
		// for(int i = 0; i < n; i++)
		// 	if(c[i][i] < 0)
		// 		return true;
		// return false;
		for(int i = 1; i < n; i++) {
			int dist = a[0][i] + a[i][0];
			int get = b[0][i] + b[i][0];
			double ans = (double) get / dist;
			if(ans > eff)
				return true;
		}
		return false;
	};

	double lb = 0, rb = INF;
	for(int i = 0; i < 200; i++) {
		double mb = (lb + rb) / 2;
		if(ok(mb)) lb = mb;
		else rb = mb;
	}
	cout << int(lb + eps) << '\n';

}

#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...