이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define debug(x) cout<<#x<<" = "<<x<<"\n";
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> pii;
int mod = 1e9+7;
ll inf = 1e9+5;
ll linf = 1ll*inf*inf;
const int maxn = 105;
ll sel[maxn][maxn*10],buy[maxn][maxn*10],dist[maxn][maxn],bnf[maxn][maxn];
int n,m,k;
inline bool check(ll x){
ll d[maxn][maxn];
for(int i=0;i<maxn;i++){
for(int j=0;j<maxn;j++){
d[i][j] = linf;
}
}
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
if(dist[i][j] == linf)continue;
d[i][j] = dist[i][j]*x-bnf[i][j];
}
}
for(int z=1;z<=n;z++){
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
d[i][j] = min(d[i][j],d[i][z]+d[z][j]);
}
}
}
for(int i=1;i<=n;i++){
if(d[i][i] <= 0){
return true;
}
}
return false;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
//cout<<"Hello, World!";
//return 0;
int l=0,r=inf;
cin>>n>>m>>k;
for(int i=1;i<=n;i++){
for(int j=1;j<=k;j++){
cin>>buy[i][j]>>sel[i][j];
}
}
for(int i=0;i<maxn;i++){
for(int j=0;j<maxn;j++){
dist[i][j] = linf;
}
}
for(int i=0;i<m;i++){
ll u,v,w;
cin>>u>>v>>w;
dist[u][v] = min(dist[u][v],w);
}
for(int z=1;z<=n;z++){
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
dist[i][j] = min(dist[i][j],dist[i][z]+dist[z][j]);
}
}
}
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
for(int z=1;z<=k;z++){
if(buy[i][z] != -1 && sel[j][z] != -1){
bnf[i][j] = max(bnf[i][j],sel[j][z]-buy[i][z]);
}
}
}
}
while(r-l>1){
int mid = (l+r)>>1;
if(check(mid)){
l = mid;
}else{
r = mid;
}
}
cout<<l;
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... |