이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define F first
#define S second
#define pb push_back
#define endl '\n'
#define Mp make_pair
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " = " << x << endl
#define set_dec(x) cout << fixed << setprecision(x);
#define fast_io ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io freopen("in.txt" , "r+" , stdin) ; freopen("out.txt" , "w+" , stdout);
#define int ll
const int N = 123;
const ll INF=INT_MAX;
const int M=1e9+23;
ll dist[N][N];
ll prof[N][N];
ll b[N][N], s[N][N];
ll temp[N][N];
int n , m, x ;
bool check(int k){
for (int i=1; i<=n; i++) {
for (int j=1; j<=n; j++){
temp[i][j]= k*min( dist[i][j] , INF/k)- prof[i][j];
}
}
for (int k=1; k<=n; k++){
for(int i=1; i<=n; i++){
for (int j=1; j<=n; j++){
temp[i][j]= min(temp[i][j], temp[i][k]+ temp[k][j]);
}
}
}
for (int i=1; i<=n; i++) if(temp[i][i]<=0) return 1;
return 0;
}
int32_t main()
{
cin>>n>>m>>x;
for (int i=1; i<=n; i++){
for (int j=1; j<=n; j++) dist[i][j]=INT_MAX;
for (int j=1; j<=x; j++) cin>>b[i][j]>>s[i][j];
}
for (int i=0; i<m; i++){
ll v, u, w; cin>>v>>u>>w;
dist[v][u]=w;
}
for (int i=1; i<=n; i++){
for (int j=1; j<=n; j++){
for (int kk=1; kk<=x; kk++){
if(b[i][kk]!=-1 && s[j][kk]!=-1)prof[i][j]=max(prof[i][j], s[j][kk]-b[i][kk]);
}
}
}
for (int k=1; k<=n; k++){
for (int i=1; i<=n; i++){
for (int j=1; j<=n; j++){
dist[i][j]=min(dist[i][j], dist[i][k]+ dist[k][j]);
}
}
}
int l=0, r= 1e9+1;
while(r-l>1) {
int mid=(r+l)>>1;
if(check(mid)) l=mid;
else r=mid;
}
cout<<l<<endl;
}
# | 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... |