이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef int64_t llo;
#define mp make_pair
#define pb push_back
#define a first
#define b second
//#define endl '\n'
llo n,m,k;
llo dist[101][101];
llo dist2[101][101];
llo min2(llo aa,llo bb){
if(aa==-1){
return bb;
}
else if(bb==-1){
return aa;
}
return min(aa,bb);
}
llo cost[101][1000][2];
vector<pair<pair<llo,llo>,llo>> ed;
vector<pair<pair<llo,llo>,llo>> ed2;
llo vis[101][101];
bool check(llo mid){
if(mid==0){
return true;
}
for(llo i=0;i<n;i++){
/* for(llo j=0;j<n;j++){
//vis[i][j]=0;
dist2[i][j]=1e18;
}*/
// vis[i][i]=1;
dist2[i][i]=0;
}
for(auto j:ed){
vis[j.a.a][j.a.b]=1;
dist2[j.a.a][j.a.b]=min(((llo)(2e18))/mid,dist[j.a.a][j.a.b])*mid-j.b;
}
/*for(auto j:ed2){
if(dist2[j.a.a][j.a.b]==1e8){
dist2[j.a.a][j.a.b]=mid*j.b;
}
}*/
for(llo kk=0;kk<n;kk++){
for(llo i=0;i<n;i++){
for(llo j=0;j<n;j++){
/*if(vis[i][kk]==0 or vis[kk][j]==0){
continue;
}*/
dist2[i][j]=min(dist2[i][j],dist2[i][kk]+dist2[kk][j]);
}
}
}
/* for(llo i=0;i<n;i++){
if(dist2[i][i]<0){
return true;
}
}*/
for(llo i=0;i<n;i++){
/*if(dist[i][i]<0){
return true;
}*/
for(llo j=0;j<n;j++){
if(i==j){
if(dist[i][i]<0){
return true;
}
continue;
}
/* if(vis[i][j]==0){
continue;
}*/
if(dist2[i][j]+dist2[j][i]<=0){
return true;
}
}
}
return false;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin>>n>>m>>k;
for(llo i=0;i<n;i++){
for(llo j=0;j<n;j++){
dist[i][j]=1e18;
}
dist[i][i]=0;
}
for(llo i=0;i<n;i++){
for(llo j=0;j<k;j++){
cin>>cost[i][j][0]>>cost[i][j][1];
}
}
for(llo i=0;i<m;i++){
llo aa,bb,cc;
cin>>aa>>bb>>cc;
ed2.pb({{aa-1,bb-1},cc});
dist[aa-1][bb-1]=min(dist[aa-1][bb-1],cc);
}
for(llo kk=0;kk<n;kk++){
for(llo i=0;i<n;i++){
for(llo j=0;j<n;j++){
dist[i][j]=min(dist[i][j],dist[i][kk]+dist[kk][j]);
}
}
}
/* for(llo i=0;i<n;i++){
for(llo j=0;j<n;j++){
cout<<dist[i][j]<<",";
}
cout<<endl;
}
*/
for(llo i=0;i<n;i++){
for(llo j=0;j<n;j++){
if(i==j){
continue;
}
llo xx=0;
for(llo kk=0;kk<k;kk++){
if(cost[i][kk][0]==-1 or cost[j][kk][1]==-1){
continue;
}
xx=max(xx,-cost[i][kk][0]+cost[j][kk][1]);
}
// if(dist[i][j]!=-1){
ed.pb({{i,j},xx});
// cout<<i<<","<<j<<","<<xx<<endl;
// }
}
}
llo low=0;
llo high=1e9;
while(low<high-1){
llo mid=(low+high)/2;
if(check(mid)){
low=mid;
}
else{
high=mid;
}
}
for(llo i=high;i>=low;i--){
if(check(i)){
cout<<i<<endl;
return 0;
}
}
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... |