이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=110, K=1010, inf=1e18;
int n, m, _k;
int b[N][K], s[N][K];
vector<pair<pair<int, int>, int>> e;
int d[N][N];
int g[N][N];
int f[N][N];
bool check(int mid){
for (int i=1; i<=n; ++i) for (int j=1; j<=n; ++j){
f[i][j]=inf;
if (d[i][j]!=inf && d[i][j]<inf/mid) f[i][j]=mid*d[i][j]-g[i][j];
}
for (int k=1; k<=n; ++k){
for (int i=1; i<=n; ++i) for (int j=1; j<=n; ++j){
f[i][j]=min(f[i][j], f[i][k]+f[k][j]);
}
}
for (int i=1; i<=n; ++i) if (f[i][i]<=0) return true;
return false;
}
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
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];
e.resize(m);
for (int i=1; i<=n; ++i) for (int j=1; j<=n; ++j) d[i][j]=inf;
for (auto &i:e){
cin >> i.first.first >> i.first.second >> i.second;
d[i.first.first][i.first.second]=min(d[i.first.first][i.first.second], i.second);
}
for (int k=1; k<=n; ++k) for (int i=1; i<=n; ++i) for (int j=1; j<=n; ++j){
if (d[i][k]!=inf && d[k][j]!=inf) d[i][j]=min(d[i][j], d[i][k]+d[k][j]);
}
for (int i=1; i<=_k; ++i){
for (int u=1; u<=n; ++u) for (int v=1; v<=n; ++v) if (b[u][i]!=-1 && s[v][i]!=-1 && b[u][i]<s[v][i]){
g[u][v]=max(g[u][v], s[v][i]-b[u][i]);
}
}
int l=1, r=1e9;
while (l<=r){
int mid=(l+r)>>1;
if (check(mid)) l=mid+1;
else r=mid-1;
}
cout << r << '\n';
return 0;
}
# | 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... |