이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
vector<vector<pair<int,int>>> items;
vector<vector<pair<int,int>>> lst;
vector<int> visited;
vector<pair<vector<int>,int>> ans;
vector<vector<int>> dist;
int n;
void dfs(int nodo, vector<int> cur, int d){
visited[nodo] += 1;
for(auto vecino:lst[nodo]){
if(vecino.first==0){
d += vecino.second;
ans.push_back({cur,d});
//for(auto a:cur) cout << a << " ";
//cout << endl;
//cout << "d: " << d << endl;
return;
}
if(visited[vecino.first]>n-1) continue;
cur.push_back(vecino.first);
dfs(vecino.first, cur, d+vecino.second);
cur.pop_back();
}
}
void fw(){
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
for(int k=0;k<n;k++){
if(dist[i][j] > dist[i][k]+dist[k][j] and dist[i][k]!=1e9 and dist[k][j]!=1e9){
dist[i][j] = dist[i][k]+dist[k][j];
}
}
}
}
}
int main(){
int m,k,v,w,t;
cin >> n >> m >> k;
// items --> vector[market][item][0-->buy / 1-->sell]
items = vector<vector<pair<int,int>>>(n,vector<pair<int,int>>(k));
lst = vector<vector<pair<int,int>>>(m,vector<pair<int,int>>());
dist = vector<vector<int>>(n,vector<int>(n,1e9));
for(int i=0;i<n;i++) dist[i][i]=0;
for(int i=0;i<n;i++){
for(int j=0;j<k;j++){
cin >> items[i][j].first >> items[i][j].second;
}
}
for(int i=0;i<m;i++){
cin >> v >> w >> t;
lst[v-1].push_back({w-1,t});
dist[v-1][w-1]=t;
}
// busco cíclos
fw();
int res = 0;
for(int i=1;i<n;i++){
for(int j=0;j<k;j++){
if(items[0][j].first==-1) continue;
if(items[i][j].second==-1) continue;
res = max(res, (items[i][j].second-items[0][j].first)/(dist[0][i]+dist[i][0]));
}
}
cout << res << 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... |