제출 #258719

#제출 시각아이디문제언어결과실행 시간메모리
258719aggu_01000101여행하는 상인 (APIO17_merchant)C++14
100 / 100
207 ms4216 KiB
#include <iostream> #include <assert.h> #include <algorithm> #include <vector> #include <set> #include <string> #include <queue> #include <map> #include <bits/stdc++.h> #define initrand mt19937 mt_rand(time(0)); #define rand mt_rand() #define int long long #define INF 10000000000; using namespace std; #define mid(l, u) ((l+u)/2) //#define cin fin //#define cout fout signed main(){ int n, m, k; cin>>n>>m>>k; int mat[n][n], p[n][n]; int b[n][k], s[n][k]; for(int i =0;i<n;i++){ for(int j =0 ;j<n;j++){ mat[i][j] = INF; p[i][j] = INF; } p[i][i] = 0; mat[i][i] = 0; } for(int i =0 ;i<n;i++){ for(int j =0 ;j<k;j++){ cin>>b[i][j]>>s[i][j]; } } for(int i = 0;i<m;i++){ int u, v, t; cin>>u>>v>>t; mat[u-1][v-1] = min(mat[u-1][v-1], t); } for(int x = 0;x<n;x++){ for(int i = 0;i<n;i++){ for(int j = 0;j<n;j++){ mat[i][j] = min(mat[i][j], mat[i][x] + mat[x][j]); } p[x][i] = 0; for(int j = 0;j<k;j++){ if(s[i][j]!=-1 && b[x][j]!=-1) p[x][i] = max(p[x][i], s[i][j] - b[x][j]); } } } /*for(int i =0 ;i<n;i++){ for(int j = 0;j<n;j++){ cout<<"distance from "<<i<<" to "<<j<<" is "<<mat[i][j]<<endl; } }*/ int l = 1; int u = 1000000001; int ans = 0; while(l<=u){ int r = mid(l, u); bool found = false; int adj[n][n]; for(int i =0 ;i<n;i++){ for(int j = 0;j<n;j++){ adj[i][j] = INF; adj[i][j] = min(adj[i][j], -(p[i][j] - r*mat[i][j])); } adj[i][i] = INF; } for(int x = 0;x<n;x++){ for(int i = 0;i<n;i++){ for(int j = 0;j<n;j++){ adj[i][j] = min(adj[i][j], adj[i][x] + adj[x][j]); } } } for(int i = 0;i<n;i++){ if((adj[i][i] + adj[i][i]) <= 0){ //cout<<i<<" "<<j<<" "<<adj[i][j]<<" "<<j<<" "<<i<<" "<<adj[j][i]<<endl; found = true; } } //cout<<r<<" "<<found<<endl; if(found){ ans = max(ans, r); l = r + 1; } else{ u = r-1; } } cout<<ans<<endl; } /* 4 5 2 10 9 5 2 6 4 20 15 9 7 10 9 -1 -1 16 11 1 2 3 2 3 3 1 4 1 4 3 1 3 1 1 */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...