Submission #937008

#TimeUsernameProblemLanguageResultExecution timeMemory
937008ByeWorldTravelling Merchant (APIO17_merchant)C++14
0 / 100
41 ms3152 KiB
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define int long long
#define lf (id<<1)
#define rg ((id<<1)|1)
#define md ((l+r)>>1)
#define ld long double
using namespace std;
typedef pair<int,int> pii;
typedef pair<string, pii> ipii;
const int INF = 1e9+10;
const int MAXN = 110;
const int MAXK = 1010;
const int LOG = 20;

int n, m, k;
int b[MAXN][MAXK], s[MAXN][MAXK];
vector <pii> adj[MAXN][3];
int dis[MAXN][3];
priority_queue <pii> pq;

void dji(int nw, int ty){
	for(int i=1; i<=n; i++) dis[i][ty] = INF;
	pq.push({0, nw});
	dis[nw][ty] = 0;

	while(!pq.empty()){
		int nw = pq.top().se; int dist = pq.top().fi; pq.pop();
		if(dist > dis[nw][ty]) continue;

		for(auto ed : adj[nw][ty]){
			int wei = ed.se, nx = ed.fi;
			if(dis[nx][ty] <= dis[nw][ty] + wei) continue;
			dis[nx][ty] = dis[nw][ty] + wei;
			pq.push({dis[nx][ty], nx});
		}
	}
}
signed main(){
	cin >> n >> m >> k;
	for(int i=1; i<=n; i++){
		for(int j=1; j<=k; j++){
			cin >> b[i][j] >> s[i][j];
		}
	}
	for(int i=1; i<=m; i++){
		int x, y, z; cin >> x >> y >> z;
		adj[x][0].pb({y, z});
		adj[y][1].pb({x, z});
	}
	dji(1, 0);
	dji(1, 1);
	ld ans = 0;
	int norm = 0;
	for(int j=1; j<=k; j++){
		if(s[1][j] > b[1][j]) norm += s[1][j] - b[1][j];
	}
	//cout << norm << " p\n";

	for(int i=2; i<=n; i++){
		int val = 0;
		for(int j=1; j<=k; j++){
			int te = norm;
			if(s[1][j] > b[1][j]){
				te -= s[1][j] - b[1][j]; // remove
				te += s[i][j] - b[1][j]; // beli j, jual di i
			} else {
				te += s[i][j] - b[1][j];
			}
			val = max(val, te);
		}
		int dist = dis[i][0] + dis[i][1];
		ans = max(ans, (ld)val / (ld)dist );
		//cout << i << ' ' << dist << " dist\n";
	}
	cout << floor(ans) << '\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...