이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#include<stdint.h>
using namespace std;
#define IOS {cin.tie(0);ios_base::sync_with_stdio(false);}
#define int int64_t
#define N 105
#define K 1005
const int INF = 1e17;
int bb[N][K],ss[N][K];
int w[N][N],dis[N][N];
double dp[N][N];
bitset<N> vis;
vector<pair<int,int> > v[N];
int32_t main()
{
IOS;
int n,m,k,a,b,t;
cin >> n >> m >> k;
for(int i=1;i<=n;i++) for(int j=1;j<=k;j++) cin >> bb[i][j] >> ss[i][j];
for(int i=0;i<m;i++){
cin >> a >> b >> t;
v[a].push_back({b,t});
}
for(int i=1;i<=n;i++){
int *dd = dis[i];
fill(dd+1,dd+n+1,INF);
vis.reset(); queue<int> q;
dd[i] = 0; q.push(i); vis[i] = 1;
while(!q.empty()){
int x = q.front(); q.pop();
vis[x] = 0;
for(auto i : v[x]) if(dd[i.first] > dd[x] + i.second){
dd[i.first] = dd[x] + i.second;
if(!vis[i.first]) vis[i.first]=1,q.push(i.first);
}
}
for(int j=1;j<=n;j++){
if(j != i && dd[j] != INF) {
for(int x=1;x<=k;x++) if(ss[j][x] >= 0 && bb[i][x] >= 0) w[i][j] = max(w[i][j],ss[j][x] - bb[i][x]);
}
else w[i][j] = 0;
}
}
double l=0,r = 1e14;
for(int cnt=0;cnt<80;cnt++){
double mm = (l+r)*0.5;
for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) {
dp[i][j] = mm*dis[i][j] - w[i][j];
}
for(int x=1;x<=n;x++) for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) {
dp[i][j] = min(dp[i][j],dp[i][x] + dp[x][j]);
}
bool gg = false;
for(int i=1;i<=n;i++) if(dp[i][i] < 0) gg = true;
if(gg) l = mm;
else r = mm;
}
cout << (int)(round(l)+0.5) << '\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... |