Submission #951545

#TimeUsernameProblemLanguageResultExecution timeMemory
951545Nhoksocqt1Fun Tour (APIO20_fun)C++17
26 / 100
85 ms17240 KiB
#ifndef Nhoksocqt1 #include "fun.h" #endif // Nhoksocqt1 #include<bits/stdc++.h> using namespace std; #define inf 0x3f3f3f3f #define sz(x) int((x).size()) #define fi first #define se second typedef long long ll; typedef pair<int, int> ii; template<class X, class Y> inline bool maximize(X &x, const Y &y) {return (x < y ? x = y, 1 : 0);} template<class X, class Y> inline bool minimize(X &x, const Y &y) {return (x > y ? x = y, 1 : 0);} mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int Random(int l, int r) { return uniform_int_distribution<int>(l, r)(rng); } const int MAXN = 100005; #ifdef Nhoksocqt1 vector<int> adjp[MAXN]; int dist[5003][5003]; void bfs(int dist[], int y) { queue<int> qu; dist[y] = 1; qu.push(y); while(sz(qu)) { int x(qu.front()); qu.pop(); for (int it = 0; it < sz(adjp[x]); ++it) { int y(adjp[x][it]); if(dist[y] == 0) { dist[y] = dist[x] + 1; qu.push(y); } } } } int hoursRequired(int x, int y) { return dist[x][y] - 1; } #endif // Nhoksocqt1 vector<int> adj[MAXN]; int numNode, maxAsk; bool dx[MAXN]; int askHoursRequired(int x, int y) { return hoursRequired(x, y); } ii dfsFar(int u, int p) { ii res = {0, u}; for (int it = 0; it < sz(adj[u]); ++it) { int v(adj[u][it]); if(v != p && !dx[v]) { ii tmp = dfsFar(v, u); ++tmp.fi; res = max(res, tmp); } } return res; } vector<int> sub2(void) { for (int i = 0; i < numNode; ++i) { for (int j = i + 1; j < numNode; ++j) { if(askHoursRequired(i, j) == 1) { adj[i].push_back(j); adj[j].push_back(i); } } } vector<int> ans; int u = dfsFar(0, -1).se; ans.push_back(u); for (int i = 1; i < numNode; ++i) { int v = dfsFar(u, -1).se; dx[u] = 1; u = v; ans.push_back(v); } return ans; } vector<int> createFunTour(int _N, int _Q) { numNode = _N, maxAsk = _Q; if(numNode <= 500) return sub2(); } #ifdef Nhoksocqt1 int main(void) { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); #define TASK "fun" if(fopen(TASK".inp", "r")) { freopen(TASK".inp", "r", stdin); freopen(TASK".out", "w", stdout); } int _N, _Q = 400000; cin >> _N >> _Q; for (int i = 0; i + 1 < _N; ++i) { int u, v; cin >> u >> v; adjp[u].push_back(v); adjp[v].push_back(u); } for (int i = 0; i < _N; ++i) bfs(dist[i], i); vector<int> funTour = createFunTour(_N, _Q); cout << "ANSWER: "; for (int it = 0; it < _N; ++it) cout << funTour[it] << ' '; cout << '\n'; return 0; } #endif // Nhoksocqt1

Compilation message (stderr)

fun.cpp: In function 'std::vector<int> createFunTour(int, int)':
fun.cpp:106:1: warning: control reaches end of non-void function [-Wreturn-type]
  106 | }
      | ^
#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...