제출 #471696

#제출 시각아이디문제언어결과실행 시간메모리
471696RainbowbunnyMeetings (JOI19_meetings)C++17
100 / 100
853 ms1084 KiB
#include "meetings.h" #include <bits/stdc++.h> using namespace std; static int tmp; const int MAXN = 2005; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int random(int l, int r) { return rng() % (r - l + 1) + l; } vector <int> Com[MAXN]; void DFS(vector <int> V) { if((int)V.size() < 2) { return; } if((int)V.size() == 2) { Bridge(min(V[0], V[1]), max(V[0], V[1])); return; } int root = V[0], ran = V[random(1, (int)V.size() - 1)]; for(auto x : V) { Com[x].clear(); } for(auto x : V) { if(x != root and x != ran) { Com[Query(root, ran, x)].push_back(x); } } vector <int> Path; for(auto x : V) { if(!Com[x].empty() and x != root and x != ran) { Path.push_back(x); } } tmp = root; sort(Path.begin(), Path.end(), [](int x, int y) { return Query(tmp, x, y) == x; }); if(!Path.empty()) { Bridge(min(root, Path[0]), max(root, Path[0])); Bridge(min(Path.back(), ran), max(Path.back(), ran)); } else { Bridge(min(root, ran), max(root, ran)); } for(int i = 0; i < (int)Path.size(); i++) { if(i + 1 < (int)Path.size()) { Bridge(min(Path[i], Path[i + 1]), max(Path[i], Path[i + 1])); } DFS(Com[Path[i]]); } Com[root].push_back(root); Com[ran].push_back(ran); DFS(Com[root]); DFS(Com[ran]); } void Solve(int N) { vector <int> V; for(int i = 0; i < N; i++) { V.push_back(i); } DFS(V); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...