이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int nx=105, kx=1005;
ll n, m, k, dp[nx][nx], p[nx][nx], b[nx][kx], s[nx][kx], ds[nx][nx], u, v, w, l=0, r=1e9;
bool check(ll x)
{
for (int i=1; i<=n; i++) for (int j=1; j<=n; j++) dp[i][j]=(ds[i][j]>1e9)?-1e18:p[i][j]-x*ds[i][j];
for (int i=1; i<=n; i++) dp[i][i]=-1e18;
for (int m=1; m<=n; m++) for (int i=1; i<=n; i++) for (int j=1; j<=n; j++) dp[i][j]=max(dp[i][j], dp[i][m]+dp[m][j]);
for (int i=1; i<=n; i++) if (dp[i][i]>=0) return 1;
return 0;
}
int main()
{
cin.tie(NULL)->sync_with_stdio(false);
cin>>n>>m>>k;
for (int i=1; i<=n; i++) for (int j=1; j<=k; j++) cin>>b[i][j]>>s[i][j];
for (int i=1; i<=n; i++) for (int j=1; j<=n; j++) ds[i][j]=1e15;
for (int i=1; i<=n; i++) ds[i][i]=0;
for (int i=1; i<=m; i++)
{
cin>>u>>v>>w;
ds[u][v]=w;
}
for (int m=1; m<=n; m++) for (int i=1; i<=n; i++) for (int j=1; j<=n; j++) ds[i][j]=min(ds[i][j], ds[i][m]+ds[m][j]);
for (int i=1; i<=n; i++) for (int j=1; j<=n; j++) for (int g=1; g<=k; g++) if (s[j][g]!=-1&&b[i][g]!=-1&&i!=j) p[i][j]=max(p[i][j], s[j][g]-b[i][g]);
while (l<r)
{
ll md=(l+r+1)/2;
if (check(md)) l=md;
else r=md-1;
}
cout<<l;
}
# | 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... |