제출 #1175728

#제출 시각아이디문제언어결과실행 시간메모리
1175728tkm_algorithms즐거운 행로 (APIO20_fun)C++20
0 / 100
0 ms328 KiB
#include "fun.h" #include <bits/stdc++.h> using namespace std; const int N = 501; int p[N][N]; vector<int> createFunTour(int n, int q) { vector<int> g[n+1]; for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j)p[i][j] = N; for (int i = 0; i < n; ++i) { p[i][i] = 0; for (int j = i+1; j < n; ++j) { int w = hoursRequired(i, j); if (w == 1) { g[i].push_back(j), g[j].push_back(i); p[i][j] = 1; p[j][i] = 1; } } } vector<pair<int, int>> m[n+1]; for (int k = 0; k < n; ++k) { for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) { p[i][j] = min(p[i][j], p[i][k] + p[j][k]); } } for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) m[i].push_back({p[i][j], j}); for (int i = 0; i < n; ++i)sort(m[i].rbegin(), m[i].rend()); vector<int> vis(n, 0); int last = 0, w = m[0][0].first; for (int i = 1; i < n; ++i) { if (m[i][0].first > w) { last = i, w = m[i][0].first; } } // for (int) vector<int> ans; ans.push_back(last); ans.push_back(m[last][0].second); vis[last] = 1, vis[m[last][0].second] = 1; int lastw = m[last][0].first; last = m[last][0].second; while (ans.size() < n) { for (auto i: m[last]) { if (vis[i.second] == 0 && i.first <= lastw) { ans.push_back(i.second); lastw = i.first, last = i.second; break; } } } 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...