이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#pragma GCC optimize("O3,unroll-loops")
#define pb push_back
#define F first
#define S second
#define ld long double
#define int long long
#define all(a) a.begin(),a.end()
#define pii pair <int,int>
#define sz(v) (int)v.size()
#define rep(i , a , b) for(int i=a;i <= (b);i++)
#define per(i , a , b) for(int i=a;i >= (b);i--)
#define deb(x) cout <<#x << " : " << x << "\n" ;
using namespace std ;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int maxn = 202 + 10 , maxk = 1e4, sq = 1e5 , lg = 19, inf = 1e18+10 , mod = 998244353;
int b[maxn][maxk] , s[maxn][maxk] , d[maxn][maxn] , w[maxn][maxn] , sp[maxn] , n;
int dis[maxn][maxn] ;
bool ch(int x){
rep(i , 1, n)sp[i] = 0 ;
rep(i , 1 ,n+1){
rep(j , 1 ,n){
rep(k , 1 , n){
if(d[j][k] == inf)continue ;
sp[k] = min(sp[k] , sp[j] + (-w[j][k] + d[j][k]*x));
if(sp[k] < -(1e17))return 1 ;
}
}
}
rep(j , 1, n){
rep(k , 1, n){
if(d[j][k] == inf)continue ;
if(sp[k] > sp[j]+(-w[j][k]+d[j][k]*x))return 1 ;
}
}
rep(i , 1 , n){
rep(j , 1 , n){
dis[i][j] = inf ;
if(d[i][j] == inf)continue ;
dis[i][j] = (-w[i][j]+d[i][j]*x);
}
dis[i][i] =0 ;
}
rep(i , 1 ,n){
rep(j , 1 ,n){
rep(k, 1 , n){
dis[j][k] = min(dis[j][k] , dis[j][i] + dis[i][k]) ;
}
}
}
rep(i , 1, n){
rep(j , 1 , n){
if(dis[j][i] + (-w[i][j]+d[i][j]*x) == 0)return 1;
}
}
return 0 ;
}
signed main(){
ios_base::sync_with_stdio(false);cin.tie(0);
int m , k ;
cin >> n >> m >> k ;
rep(i , 1, n){
rep(j , 1, k){
cin >> b[i][j] >> s[i][j] ;
}
}
rep(i , 1, n){
rep(j , 1 , n){
w[i][j] = -inf ;
if(i == j)continue ;
w[i][j] = 0 ;
rep(z , 1 , k){
if(b[i][z] == -1 || s[j][z] == -1)continue ;
w[i][j] = max(w[i][j] , -b[i][z] + s[j][z]) ;
}
}
}
rep(i , 1, n){
rep(j , 1 ,n)d[i][j] = inf ;
d[i][i] = 0;
}
while(m--){
int v, u , w ;
cin >> v >> u >> w ;
d[v][u] = min(d[v][u] , w);
}
rep(i ,1 ,n){
rep(j , 1, n){
rep(z, 1 , n){
d[j][z] = min(d[j][z] , d[j][i] + d[i][z]) ;
}
}
}
int l = 0, r =1e9 ;
while(r-l>1){
int mid = (l+r)/2 ;
if(ch(mid) == 1)l=mid ;
else r = mid ;
}
cout << l << "\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... |