# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
388358 | talant117408 | Travelling Merchant (APIO17_merchant) | C++17 | 19 ms | 1868 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/*
Code written by Talant I.D.
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
#define precision(n) fixed << setprecision(n)
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define mp make_pair
#define eps (double)1e-9
#define PI 2*acos(0.0)
#define endl "\n"
#define sz(v) int((v).size())
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define do_not_disturb ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define OK cout << "OK" << endl;
const int mod = 1e9+7;
ll mode(ll a) {
a %= mod;
if (a < 0) a += mod;
return a;
}
ll subt(ll a, ll b) {
return mode(mode(a)-mode(b));
}
ll add(ll a, ll b) {
return mode(mode(a)+mode(b));
}
ll mult(ll a, ll b) {
return mode(mode(a)*mode(b));
}
ll binpow(ll a, ll b, ll m) {
ll res = 1;
while (b) {
if (b&1) res = ((res*a)%m+m)%m;
a = ((a*a)%m+m)%m;
b >>= 1;
}
return res;
}
void usaco(string s) {
freopen((s+".in").c_str(), "r", stdin);
freopen((s+".out").c_str(), "w", stdout);
}
const int N = 103, K = 1003;
vector <pll> graph[N];
ll buy[N][K], sell[N][K], dist[N];
int n, k;
void subtask1() {
for (int i = 1; i <= n; i++) {
dist[i] = 9e18;
}
dist[1] = 0;
priority_queue <pll> K;
K.push(mp(0, 1));
while (!K.empty()) {
auto v = K.top().second; K.pop();
for (auto to : graph[v]) {
if (dist[to.first] > dist[v]+to.second) {
dist[to.first] = dist[v]+to.second;
K.push(mp(-dist[to.first], to.first));
}
}
}
int flag = 1;
for (int i = 2; i <= n; i++) {
for (int j = 1; j <= k; j++) {
if (buy[i][j] != -1) {
flag = 0;
}
}
}
if (!flag) return;
ll ans = 0;
for (int i = 2; i <= n; i++) {
for (int j = 1; j <= k; j++) {
if (buy[1][j] != -1 && sell[i][j] != -1 && sell[i][j] > buy[1][j]) {
ans = max(ans, (sell[i][j]-buy[1][j])/dist[i]/2);
}
}
}
cout << ans;
exit(0);
}
int main() {
do_not_disturb
int m;
cin >> n >> m >> k;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= k; j++) {
cin >> buy[i][j] >> sell[i][j];
}
}
for (int i = 0; i < m; i++) {
ll x, y, t;
cin >> x >> y >> t;
graph[x].pb(mp(y, t));
graph[y].pb(mp(x, t));
}
subtask1();
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |