이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define N 105
#define K 1005
#define M 10005
typedef long long ll;
using namespace std;
ll n,m,k;
ll u[M],v[M],w[M];
ll b[N][K],s[N][K];
ll dist[N][N],profit[N][N],adj[N][N];
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> m >> k;
for(ll i=1;i<=n;i++){
for(ll j=1;j<=k;j++){
cin >> b[i][j] >> s[i][j];
}
for(ll j=1;j<=n;j++){
dist[i][j]=1000000001;
}
}
for(ll i=1;i<=m;i++){
cin >> u[i] >> v[i] >> w[i];
dist[u[i]][v[i]]=w[i];
}
for(ll q=1;q<=n;q++){
for(ll i=1;i<=n;i++){
for(ll j=1;j<=n;j++){
dist[i][j]=min(dist[i][j],dist[i][q]+dist[q][j]);
}
}
}
for(ll q=1;q<=n;q++){
for(ll i=1;i<=n;i++){
if(dist[q][i]==1000000001) continue;
for(ll j=1;j<=k;j++){
if(b[q][j]!=-1 && s[i][j]!=-1){
profit[q][i]=max(profit[q][i],s[i][j]-b[q][j]);
}
}
}
}
ll l=0,r=1000000001;
while(l!=r){
ll mid=(l+r+1)>>1;
for(ll i=1;i<=n;i++){
for(ll j=1;j<=n;j++){
adj[i][j]=profit[i][j]-mid*dist[i][j];
}
}
for(ll q=1;q<=n;q++){
for(ll i=1;i<=n;i++){
for(ll j=1;j<=n;j++){
adj[i][j]=max(adj[i][j],adj[i][q]+adj[q][j]);
}
}
}
bool flag=0;
for(ll i=1;i<=n;i++){
if(adj[i][i]>=0) flag=1;
}
if(flag==1){
l=mid;
}
else r=mid-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... |