제출 #414307

#제출 시각아이디문제언어결과실행 시간메모리
414307ACmachine즐거운 행로 (APIO20_fun)C++17
0 / 100
1 ms332 KiB
#include "fun.h" #include <bits/stdc++.h> using namespace std; #define FOR(i, j, k, l) for(int i = (j); i < (k); i += (l)) #define FORD(i, j, k, l) for(int i = (j); i>=(k); i -= (l)) #define REP(i, n) FOR(i, 0, n, 1) #define REPD(i, n) FORD(i, n, 0, 1) #define pb push_back typedef long long ll; const int INF = (int)1e9; const ll INFF = (ll)1e18; std::vector<int> createFunTour(int n, int Q) { vector<vector<int>> mat(n, vector<int>(n)); REP(i, n){ REP(j, i + 1){ mat[i][j] = mat[j][i] = hoursRequired(i, j); } } vector<int> ans; vector<vector<int>> g; vector<bool> used(n, false); REP(i, n){ REP(j, n){ if(mat[i][j] == 1) g[i].pb(j); } } vector<int> dist(n, -1); function<void(int, int)> dfs = [&](int v, int p){ if(used[v]) return; dist[v] = (p == -1 ? 0 : dist[p] + 1); for(int x : g[v]){ if(x == p) continue; dfs(x, v); } }; dfs(0, -1); int f = max_element(dist.begin(), dist.end()) - dist.begin(); REP(i, n){ ans.pb(f); used[f] = true; fill(dist.begin(), dist.end(), -1); dfs(f, -1); f = max_element(dist.begin(), dist.end()) - dist.begin(); } return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...