제출 #913828

#제출 시각아이디문제언어결과실행 시간메모리
913828pan여행하는 상인 (APIO17_merchant)C++17
33 / 100
105 ms3960 KiB
#include <bits/stdc++.h>
//#include "bits_stdc++.h"
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
//#define input(x) scanf("%lld", &x);
//#define print(x, y) printf("%lld%c", x, y);
#define show(x) cerr << #x << " is " << x << endl;
#define show2(x,y) cerr << #x << " is " << x << " " << #y << " is " << y << endl;
#define show3(x,y,z) cerr << #x << " is " << x << " " << #y << " is " << y << " " << #z << " is " << z << endl;
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ld, ll> pd;
typedef pair<string, ll> psl;
typedef pair<ll, ll> pi;
typedef pair<ll, pi> pii;
ll n, m ,k, x,y, z;
vector<pi> adj[105];
ll buy[105][1005];
ll sell[105][1005];
ll p[105][105];

bool floydwarshall(ll mid)
{
	vector<vector<ll> > dist;
	dist.assign(n+1, vector<ll> (n+1, LLONG_MAX));
	for (ll i=1; i<=n;++i)
	{
		for (pi a: adj[i])
		{
			ll y= a.f, w = a.s;
			dist[i][y] = min(dist[i][y], mid*w-(p[i][y]));
		}
	}
    for (ll k = 1; k <= n; k++) 
        for (ll i = 1; i <= n; i++) 
           for (ll j = 1; j <= n; j++) 
			   if (dist[i][k]!=LLONG_MAX && dist[k][j]!=LLONG_MAX)
			   {
				dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
			   }
    bool ans = false;
    for (ll i=1; i<=n;++i) ans = ans || (dist[i][i]<=0);
    return ans;
}

int main()
{
	cin >> n >> m >>k;
	for (ll i=1; i<=n; ++i)
	{
		for(ll j=1;j<=k;++j) cin >> buy[i][j] >> sell[i][j];
	}
	for (ll i=1; i<=n; ++i)
	{
		for (ll j=1; j<=n; ++j)
		{
			for (ll x=1; x<=k;++x)
			{
				if (buy[i][x]!=-1 && sell[j][x]!=-1)
				{
					p[i][j] = max(p[i][j], -buy[i][x]+sell[j][x]);
				}
			}
		}
	}
	for (ll i=0; i<m; ++i)
	{
		cin >>x >> y >> z;
		adj[x].pb(mp(y,z));
	}
	ll lo=0, hi = 1e9;
	while (lo!=hi)
	{
		ll mid = (lo+hi+1)/2;
		if (floydwarshall(mid)) lo = mid;
		else hi = mid-1;
	}
	cout << lo << endl;
	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...