# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
735368 | keisuke6 | Fun Tour (APIO20_fun) | C++14 | 90 ms | 16720 KiB |
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 "fun.h"
#include <iostream>
#include <queue>
#include <vector>
#include <set>
using namespace std;
std::vector<int> createFunTour(int N, int Q) {
vector<vector<int>> G(N);
for(int i=0;i<N;i++)for(int j=0;j<N;j++){
int a_ = hoursRequired(i, j);
if(a_ == 1) G[i].push_back(j);
}
queue<int> q;
q.push(0);
vector<int> dist(N,1e9);
dist[0] = 0;
while(!q.empty()){
int pos = q.front();
q.pop();
for(int x:G[pos]){
if(dist[x] != 1e9) continue;
q.push(x);
dist[x] = dist[pos] + 1;
}
}
int now = 0, best = 0;
for(int i=0;i<N;i++)if(best < dist[i]){
best = dist[i];
now = i;
}
vector<int> A = {};
set<int> s;
while(A.size() != N){
for(int i=0;i<N;i++) dist[i] = 1e9;
A.push_back(now);
s.insert(now);
q.push(now);
dist[now] = 0;
while(!q.empty()){
int pos = q.front();
q.pop();
for(int x:G[pos]){
if(dist[x] != 1e9) continue;
q.push(x);
dist[x] = dist[pos] + 1;
}
}
best = 0;
for(int i=0;i<N;i++)if(best < dist[i] && !s.count(i)){
best = dist[i];
now = i;
}
}
return A;
}
Compilation message (stderr)
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |