제출 #1254248

#제출 시각아이디문제언어결과실행 시간메모리
1254248M_SH_O여행하는 상인 (APIO17_merchant)C++20
100 / 100
51 ms2376 KiB
#include <bits/stdc++.h> #define ll long long #define ll1 long long #define ull unsigned long long #define dou long double #define str string #define vll vector<ll> #define vi vector<int> #define pll pair<ll, ll> #define vpll vector<pll> #define vbool vector<bool> #define vstr vector<str> #define vvll vector<vll> #define pb push_back #define pf push_front #define endl "\n" #define fr first #define se second // #define sortcmp(a) sort(a.begin(), a.end(), cmp) #define sort(a) sort(a.begin(), a.end()) #define reverse(a) reverse(a.begin(), a.end()) #define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0) #define ordered_set tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> using namespace std; //using namespace __gnu_pbds; const ll INF = 1e18; const int lg = 20; mt19937 rng(time(0)); ll randll(ll l, ll r){ return uniform_int_distribution<ll>(l, r)(rng); } vector<vpll> b; vvll g; int main(){ speed; ll n, m, k; cin >> n >> m >> k; g.resize(n+7, vll(n+7, INF)); b.resize(n+7, vpll(k, {-1, -1})); for(int i = 1; i <= n; i ++){ //g[i][i] = 0; for(int j = 0; j < k; j ++){ cin >> b[i][j].fr >> b[i][j].se; } } for(int i = 0; i < m; i ++){ ll a, b, c; cin >> a >> b >> c; g[a][b] = c; } for(int i = 1; i <= n; i ++){ for(int j = 1; j <= n; j ++){ for(int i1 = 1; i1 <= n; i1 ++){ g[j][i1] = min(g[j][i1], g[j][i]+g[i][i1]); } } } vvll p(n+7, vll(n+7, 0)); ll maxl = 0; for(int a = 1; a <= n; a ++){ for(int c = 1; c <= n; c ++){ for(int i = 0; i < k; i ++){ if(b[a][i].fr == -1 || b[c][i].se == -1) continue; //cout << a << ' ' << c << ' ' << i << ' ' << b[a][i].fr << ' ' << b[c][i].se << endl; p[a][c] = max(p[a][c], b[c][i].se-b[a][i].fr); } } maxl = max(maxl, p[a][a]); } ll l = 0, r = 1e9+7; while(r - l > 1){ ll x = (l+r)/2; vvll newg(n+7, vll(n+7, INF)); for(int i = 1; i <= n; i ++){ for(int j = 1; j <= n; j ++){ newg[i][j] = min(newg[i][j], x*min(INF/x, g[i][j]) - p[i][j]); } } /*for(int i = 1; i <= n; i ++){ for(int j = 1; j <= n; j ++){ if(p[i][j] == -INF) continue; cout << i << ' ' << j << ' ' << p[i][j] << endl; } cout << endl; } for(int i = 1; i <= n; i ++){ for(int j = 1; j <= n; j ++){ cout << newg[i][j] << ' '; } cout << endl; }*/ for(int i = 1; i <= n; i ++){ for(int j = 1; j <= n; j ++){ for(int i1 = 1; i1 <= n; i1 ++){ newg[j][i1] = min(newg[j][i1], newg[j][i]+newg[i][i1]); } } } bool q = 0; for(int i = 1; i <= n; i ++){ //cout << newg[i][i] << ' '; if(newg[i][i] <= 0) q = 1; } //cout << endl; if(q) l = x; else r = x; } cout << max(maxl, l) << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...