Submission #516146

#TimeUsernameProblemLanguageResultExecution timeMemory
516146keta_tsimakuridzeTravelling Merchant (APIO17_merchant)C++14
100 / 100
142 ms2432 KiB
#include<bits/stdc++.h> #define int long long #define f first #define s second #define pii pair<int,int> using namespace std; const int N = 105 + 5, mod = 1e9 + 7, inf = 1e15; // ! int t, a[N][N * 10][2], n, k, m, d[N][N], p[N][N], di[N][N]; bool check(int x) { vector< pair<int, pii> > E; for(int i = 1; i <= n; i++) { for(int j = 1; j <= n; j++) { di[i][j] = inf; if(d[i][j] == inf || i == j) continue; di[i][j] = - (p[i][j] - d[i][j] * x); } } for(int k = 1; k <= n; k++) { for(int j = 1; j <= n; j++) { for(int i = 1; i <= n; i++) { di[i][j] = min(di[i][j], di[i][k] + di[k][j]); } } } for(int i = 1; i <= n; i++) { if(di[i][i] <= 0) return 1; } return 0; } main(){ cin >> n >> m >> k; for(int i = 1; i <= n; i++) { for(int j = 1; j <= k; j++) { for(int t = 0; t < 2; t++) cin >> a[i][j][t]; } } for(int i = 1; i <= n; i++) { for(int j = 1; j <= n; j++) d[i][j] = inf; d[i][i] = 0; } while(m--) { int u, v, w; cin >> u >> v >> w; d[u][v] = min(d[u][v], w); } for(int k = 1; k <= n; k++) { for(int j = 1; j <= n; j++) { for(int i = 1; i <= n; i++) { d[i][j] = min(d[i][j], d[i][k] + d[k][j]); } } } for(int i = 1; i <= n; i++) { for(int j = 1; j <= n; j++) { p[i][j] = 0; for(int x = 1; x <= k; x++) { if(a[i][x][0] == -1 || a[j][x][1] == -1) continue; p[i][j] = max(p[i][j], - a[i][x][0] + a[j][x][1]); } } } int l = 0, r = 1e9, ans = 0; while(l <= r) { int mid = (l + r) / 2; if(check(mid)) l = mid + 1, ans = mid; else r = mid - 1; } cout << ans; }

Compilation message (stderr)

merchant.cpp:30:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   30 | main(){
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...