Submission #278643

#TimeUsernameProblemLanguageResultExecution timeMemory
278643luciocfTravelling Merchant (APIO17_merchant)C++14
0 / 100
103 ms3160 KiB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int maxn = 110;
const int maxk = 1e3+10;
const ll inf = 1e18+10;

int n, m, k;
int b[maxn][maxk], s[maxn][maxk];

ll dist[maxn][maxn], g[maxn][maxn], p[maxn][maxn];

bool ok(int x)
{
	for (int i = 1; i <= n; i++)
		p[i][i] = -inf;

	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j <= n; j++)
		{
			if (j == i) continue;

			p[i][j] = g[i][j] - 1ll*x*dist[i][j];
		}
	}

	for (int l = 1; l <= n; l++)
		for (int i = 1; i <= n; i++)
			for (int j = 1; j <= n; j++)
				p[i][j] = max(p[i][j], p[i][l]+p[l][j]);

	for (int i = 1; i <= n; i++)
		if (p[i][i] >= 0)
			return true;

	return false;
}

int main(void)
{
	scanf("%d %d %d", &n, &m, &k);

	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= k; j++)
			scanf("%d %d", &b[i][j], &s[i][j]);

	for (int i = 1; i <= n; i++)
		for (int j = i+1; j <= n; j++)
			dist[i][j] = dist[j][i] = inf;

	for (int i = 1; i <= m; i++)
	{
		int u, v, w;
		scanf("%d %d %d", &u, &v, &w);

		dist[u][v] = min(dist[u][v], 1ll*w);
	}

	for (int l = 1; l <= n; l++)
		for (int i = 1; i <= n; i++)
			for (int j = 1; j <= n; j++)
				dist[i][j] = min(dist[i][j], dist[i][l]+dist[l][j]);

	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j <= n; j++)
		{
			if (i == j) continue;

			for (int l = 1; l <= k; l++)
				if (b[i][l] != -1 && s[j][l] != -1)
					g[i][j] = max(g[i][j], 1ll*s[j][l]-1ll*b[i][l]);
		}
	}

	int ini = 1, fim = 1e9+10, ans = 0;

	while (ini <= fim)
	{
		int mid = (ini+fim)>>1;

		if (ok(mid)) ans = mid, ini = mid+1;
		else fim = mid-1;
	}

	printf("%d\n", ans);
}

Compilation message (stderr)

merchant.cpp: In function 'int main()':
merchant.cpp:45:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   45 |  scanf("%d %d %d", &n, &m, &k);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
merchant.cpp:49:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   49 |    scanf("%d %d", &b[i][j], &s[i][j]);
      |    ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
merchant.cpp:58:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   58 |   scanf("%d %d %d", &u, &v, &w);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...