제출 #934267

#제출 시각아이디문제언어결과실행 시간메모리
934267oblantis여행하는 상인 (APIO17_merchant)C++17
0 / 100
1064 ms2128 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 ll inf = 4e9;
const ll INF = 1e15;
const int mod = 1e9+7;
const int maxn = 100 + 1;
ll c[maxn][maxn];
ll dp[maxn][maxn];
void solve() {
	int n, m, k;
	cin >> n >> m >> k;
	ll b[n][k], s[n][k];
	ll a[n][n];
	vt<pii> g[n];
	for(int i = 0; i < n; i++){
		for(int j = 0; j < n; j++)a[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)c[i][j] = max(c[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});
		a[i][i] = 0;
		while(!pq.empty()){
			pii nw = pq.top();
			pq.pop();
			if(a[i][nw.ss] != nw.ff)continue;
			for(auto j : g[nw.ss]){
				if(a[i][j.ff] > nw.ff + j.ss){
					a[i][j.ff] = nw.ff + j.ss;
					pq.push({a[i][j.ff], j.ff});
				}
			}
		}
	}
	ll l = 0, r = 10000001;
	while(l + 1 < r){
		ll mid = l + (r - l) / 2;
		for(int i = 0; i < n; i++){
			for(int j = 0; j < n; j++){
				if(i != j)dp[i][j] = c[i][j] - a[i][j] * mid;
				else dp[i][j] = -INF;
			}
		}
		bool ok = 0, ch = 1;
		while(ch){
			ch = 0;
			for(int i = 0; i < n; i++){
				for(int j = 0; j < n; j++){
					for(int o = 0; o < n; o++){
						if(dp[i][o] <= dp[i][j] + c[j][o] - a[j][o] * mid)dp[i][o] = dp[i][j] + c[j][o] - a[j][o] * mid, ch = 1;
					}
				}
				if(dp[i][i] >= 0){
					ok = 1;
					break;
				}
			}
			if(ok)break;
		}
		if(ok)l = mid;
		else r = mid;
	}
	cout << l;
}

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...