이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define show(x,y) cout << y << " " << #x << endl;
#define show2(x,y,i,j) cout << y << " " << #x << " " << j << " " << #i << endl;
#define show3(x,y,i,j,p,q) cout << y << " " << #x << " " << j << " " << #i << " " << q << " " << #p << endl;
#define show4(x,y) for(auto it:y) cout << it << " "; cout << #x << endl;
typedef pair<long long,int>pii;
//typedef pair<pii,pii>pi2;
typedef array<int,6>pi2;
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
void solve(){
int n,m,k;
cin >> n >> m >> k;
int arr[n+5][k][2]; //buy sell
for(int x=1;x<=n;x++){
for(int y=0;y<k;y++){
cin >> arr[x][y][0] >> arr[x][y][1];
}
}
int adj[n+5][n+5];
memset(adj,-1,sizeof(adj));
for(int x=1;x<=n;x++) adj[x][x]=0;
int temp,temp2,temp3;
for(int x=0;x<m;x++){
cin >> temp >> temp2 >> temp3;
if(adj[temp][temp2]==-1)adj[temp][temp2]=temp3;
else adj[temp][temp2]=min(adj[temp][temp2],temp3);
}
for(int i=1;i<=n;i++){
for(int x=1;x<=n;x++){
for(int y=1;y<=n;y++){
if(adj[x][i]==-1||adj[i][y]==-1) continue;
if(adj[x][y]!=-1&&adj[x][y]<=adj[x][i]+adj[i][y]) continue;
adj[x][y]=adj[x][i]+adj[i][y];
}
}
}
//for(int x=1;x<=n;x++){
//for(int y=1;y<=n;y++){
//cout << adj[x][y] << " ";
//}
//cout << endl;
//}
int add[n+5][n+5];
memset(add,0,sizeof(add));
for(int x=1;x<=n;x++){
for(int y=1;y<=n;y++){
for(int i=0;i<k;i++){
if(arr[y][i][1]==-1||arr[x][i][0]==-1) continue;
add[x][y]=max(add[x][y],arr[y][i][1]-arr[x][i][0]);
}
//show3(x,x,y,y,add[x][y],add[x][y]);
}
}
int l=0;
int r=1e13;
int mid;
int best=0;
while(l<=r){
mid=(l+r)/2;
int adj2[n+5][n+5];
for(int x=1;x<=n;x++){
for(int y=1;y<=n;y++){
if(x==y||adj[x][y]==-1) adj2[x][y]=-1e15;
else{
adj2[x][y]=add[x][y]-mid*adj[x][y];
}
}
}
for(int i=1;i<=n;i++){
for(int x=1;x<=n;x++){
for(int y=1;y<=n;y++){
if(adj2[x][i]==-1||adj2[i][y]==-1) continue;
if(adj2[x][y]!=-1&&adj2[x][y]>=adj2[x][i]+adj2[i][y]) continue;
adj2[x][y]=adj2[x][i]+adj2[i][y];
}
}
}
bool amos=false;
for(int x=1;x<=n;x++){
if(adj2[x][x]>=0) amos=true;
}
if(amos){
best=mid;
l=mid+1;
}
else r=mid-1;
}
cout << best;
}
int32_t main(){
ios::sync_with_stdio(0);
cin.tie(0);
int t=1;
//cin >> t;
while(t--){
solve();
}
}
# | 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... |