Submission #934222

#TimeUsernameProblemLanguageResultExecution timeMemory
934222oblantisTravelling Merchant (APIO17_merchant)C++17
12 / 100
115 ms3032 KiB
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#pragma GCC optimize("O3,unroll-loops")
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define pb push_back
#define ss second
#define ff first
#define vt vector
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int inf = 2e9;
const int mod = 1e9+7;
const int maxn = 100 + 1;
int to[maxn][maxn];
void solve() {
	int n, m, k;
	cin >> n >> m >> k;
	int b[n][k], s[n][k];
	int p[n][n], dist[n][n];
	vt<pii> g[n];
	for(int i = 0; i < n; i++){
		for(int j = 0; j < n; j++)p[i][j] = -1, dist[i][j] = inf;
		for(int j = 0; j < k; j++){
			cin >> b[i][j] >> s[i][j];
		}
	}
	for(int i = 0; i < n; i++){
		for(int j = 0; j < n; j++){
			for(int o = 0; o < k; o++){
				if(b[i][o] != -1)to[i][j] = max(to[i][j], s[j][o] - b[i][o]);
			}
		}
	}
	for(int i = 0, u, v, d; i < m; i++){
		cin >> u >> v >> d;
		--u, --v;
		g[u].pb({v, d});
	}
	for(int i = 0; i < n; i++){
		priority_queue<pii, vt<pii>, greater<pii>> pq;
		pq.push({0, i});
		dist[i][i] = 0, p[i][i] = i;
		while(!pq.empty()){
			pii nw = pq.top();
			pq.pop();
			if(dist[i][nw.ss] != nw.ff)continue;
			for(auto j : g[nw.ss]){
				if(dist[i][j.ff] > nw.ff + j.ss){
					dist[i][j.ff] = nw.ff + j.ss;
					p[i][j.ff] = nw.ss;
					pq.push({dist[i][j.ff], j.ff});
				}
			}
		}
	}
	ll ans = 0;
	for(int i = 0; i < n; i++){
		for(int j = 0; j < n; j++){
			if(i == j || dist[i][j] == inf || dist[j][i] == inf)continue;
			int x = i;
			ll dd = dist[i][j] + dist[j][i];
			vt<int> path; 
			while(x != j){
				path.pb(x);
				x = p[j][x];
			}
			while(x != i){
				path.pb(x);
				x = p[i][x];
			}
			path.pb(i);
			reverse(all(path));
			int sz = path.size();
			vt<ll> dp(sz, 0);
			for(int o = 1; o < sz; o++){
				for(int j = 0; j < o; j++){
					dp[o] = max(dp[o], dp[j] + to[path[j]][path[o]]);
				}
			}
			ans = max(ans, dp[sz - 1] / dd);
		}
	}
	cout << ans;
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int times = 1;
	//cin >> times;
	for(int i = 1; i <= times; i++) {
		solve();
	}
	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...