이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define int long long
#define x first
#define y second
#define pb push_back
using namespace std;
using pii=pair <int,int>;
int n,m,k;
int buy[101][1001],sell[101][1001];
vector <pii> g[101];
int p[101][101],d[101][101],nw[101][101];
signed main(){
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++){
int u,v,w;
cin>>u>>v>>w;
g[u].pb({v,w});
}
for (int i=1; i<=n; i++){
for (int j=1; j<=n; j++){
p[i][j]=0;
for (int l=1; l<=k; l++){
if (buy[i][l]!=-1&&sell[j][l]!=-1) p[i][j]=max(p[i][j],-buy[i][l]+sell[j][l]);
}
}
}
for (int i=1; i<=n; i++){
for (int j=1; j<=n; j++) d[i][j]=1e18;
d[i][i]=0;
}
for (int i=1; i<=n; i++){
for (auto j:g[i]) d[i][j.x]=min(d[i][j.x],j.y);
}
for (int l=1; l<=n; l++){
for (int i=1; i<=n; i++){
for (int j=1; j<=n; j++) d[i][j]=min(d[i][j],d[i][l]+d[l][j]);
}
}
int l=0,r=2e9;
while (l<r){
int mid=(l+r+1)/2;
for (int i=1; i<=n; i++){
for (int j=1; j<=n; j++){
if (i==j) nw[i][j]=-1e13;
else if (d[i][j]!=1e18) nw[i][j]=p[i][j]-mid*d[i][j];
else nw[i][j]=-1e13;
}
}
for (int l=1; l<=n; l++){
for (int i=1; i<=n; i++){
for (int j=1; j<=n; j++) nw[i][j]=max(nw[i][j],nw[i][l]+nw[l][j]);
}
}
bool found=0;
for (int i=1; i<=n; i++){
if (nw[i][i]>=0) found=1;
}
if (found) l=mid;
else r=mid-1;
}
cout<<l<<'\n';
}
# | 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... |