제출 #307948

#제출 시각아이디문제언어결과실행 시간메모리
307948arnold518즐거운 행로 (APIO20_fun)C++14
26 / 100
303 ms41840 KiB
#include "fun.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int MAXN = 1e5; int N, Q; vector<int> adj[MAXN+10]; map<pii, int> memo1; int query1(int u, int v) { if(u>v) swap(u, v); if(u==v) return 0; if(memo1.find({u, v})!=memo1.end()) return memo1[{u, v}]; return memo1[{u, v}]=hoursRequired(u-1, v-1); } map<pii, int> memo2; int query2(int u, int v) { if(u==v) return N; if(memo2.find({u, v})!=memo2.end()) return memo2[{u, v}]; return memo2[{u, v}]=attractionsBehind(u-1, v-1); } bool vis[MAXN+10]; int D[MAXN+10]; void dfs(int now, int bef, int d) { D[now]=d; for(int nxt : adj[now]) { if(nxt==bef) continue; if(vis[nxt]) continue; dfs(nxt, now, d+1); } } vector<int> createFunTour(int _N, int _Q) { N=_N; Q=_Q; vector<int> ans; for(int i=1; i<=N; i++) for(int j=i+1; j<=N; j++) { if(query1(i, j)==1) { adj[i].push_back(j); adj[j].push_back(i); } } int u=1; dfs(1, 1, 1); for(int i=1; i<=N; i++) if(D[u]<D[i]) u=i; ans.push_back(u); vis[u]=true; for(int i=2; i<=N; i++) { dfs(u, u, 1); for(int i=1; i<=N; i++) if(D[u]<D[i]) u=i; ans.push_back(u); vis[u]=true; } for(auto &it : ans) it--; 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...