이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define ppb pop_back
#define ep insert
#define endl '\n'
#define elif else if
#define pow pwr
#define sqrt sqrtt
#define int long long
#define y1 YONE
typedef unsigned long long ull;
using namespace std;
const int N=105,KK=1005;
int n,m,K,dis[N][N],b[N][KK],s[N][KK];
bool vis[N];
pair<int,int> eff[N][N];
vector<pair<int,int>> adj[N];
void dijkstra(int s){
for (int i=1;i<=n;i++) vis[i]=0,dis[s][i]=-1;
dis[s][s]=0;
priority_queue<pair<int,int>> pq;
pq.push({0,s});
while (!pq.empty()){
int x=pq.top().S;
pq.pop();
if (vis[x]) continue;
vis[x]=1;
for (auto u:adj[x]){
if (dis[s][u.F]==-1 || dis[s][u.F]>dis[s][x]+u.S){
dis[s][u.F]=dis[s][x]+u.S;
pq.push({-dis[s][u.F],u.F});
}
}
}return;
}
int32_t main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
cin>>n>>m>>K;
for (int i=1;i<=n;i++) for (int j=1;j<=K;j++) cin>>b[i][j]>>s[i][j];
for (int i=1;i<=m;i++){
int x,y,w;
cin>>x>>y>>w;
adj[x].pb({y,w});
}
for (int i=1;i<=n;i++) dijkstra(i);
for (int i=1;i<=n;i++){
for (int j=1;j<=n;j++){
if (dis[i][j]==-1) eff[i][j]={-1,-1};
else{
int mx=0;
for (int k=1;k<=K;k++){
if (b[i][k]==-1 || s[j][k]==-1) continue;
mx=max(mx,s[j][k]-b[i][k]);
}
eff[i][j]={mx,dis[i][j]};
}
//cout<<eff[i][j].F<<' '<<eff[i][j].S<<" ";
}//cout<<endl;
}
for (int t=1;t<=50;t++){
for (int i=1;i<=n;i++){
for (int j=i;j<=n;j++){
if (i==j || eff[i][j].F==-1) continue;
for (int k=1;k<=n;k++){
if (eff[i][k].F==-1 || eff[k][j].F==-1) continue;
pair<int,int> x={eff[i][k].F+eff[k][j].S,eff[i][k].S+eff[k][j].S};
if (eff[i][j].F*x.S<eff[i][j].S*x.F) eff[i][j]=x;
//cout<<eff[i][j].F<<' '<<eff[i][j].S<<endl;
}
}
}}
/*for (int t=1;t<=50;t++){
for (int k=1;k<=n;k++){
for (int i=1;i<=n;i++){
if (eff[i][k].F==-1) continue;
for (int j=1;j<=n;j++){
if (j==i || eff[k][j].F==-1 || eff[i][j].F==-1) continue;
pair<int,int> x={eff[i][k].F+eff[k][j].S,eff[i][k].S+eff[k][j].S};
if (eff[i][j].F*x.S<eff[i][j].S*x.F) eff[i][j]=x;
}
}
}}*/
pair<int,int> ans={0,1};
for (int i=1;i<=n;i++){
for (int j=1;j<=n;j++){
if (i==j || eff[i][j].F==-1) continue;
pair<int,int> x={eff[i][j].F,eff[i][j].S+dis[j][i]};
if (ans.F*x.S<ans.S*x.F) ans=x;
}
}cout<<ans.F/ans.S<<endl;
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... |