This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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);
const int N = 123;
const ll INF=1e18;
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, k ;
bool check(int k){
for (int i=1; i<=n; i++) {
for (int j=1; j<=n; j++){
temp[i][j]= min( k*dist[i][j] , INF)- 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;
}
int main()
{
cin>>n>>m>>k;
for (int i=1; i<=n; i++){
for (int j=1; j<=n; j++) dist[i][j]=INF;
for (int j=1; j<=k; 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]=min(dist[v][u], w);
}
for (int i=1; i<=n; i++){
for (int j=1; j<=n; j++){
for (int kk=1; kk<=k; 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=1, r= M;
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... |