제출 #1170896

#제출 시각아이디문제언어결과실행 시간메모리
1170896aentrenusMeetings (JOI19_meetings)C++20
29 / 100
1533 ms7792 KiB
#include "meetings.h" #include<bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; using vi = vector<int>; using vl = vector<ll>; using vb = vector<bool>; using pii = pair<int, int>; using pll = pair<ll, ll>; using str = string; #define all(a) a.begin(), a.end() #define print(a) for (auto elem:a) cout<<elem<<' '; cout<<'\n' #define segprep(b) resize(1<<((int)ceil(log2(b.size()))+1)) #define FOR(a) for (int _ = 0; _ < a; _++) const int SEED = 2; void srt(int &a, int &b, int &c){ vi tmp = {a, b, c}; sort(all(tmp)); a = tmp.front(); b = tmp.at(1); c = tmp.back(); } int randint(const int l, const int r){ int res = rand()%(r-l)+l; assert(l <= res && res < r); return res; } struct query{ int u, v, w; }; bool operator<(const query &a, const query&b){ return (vi{a.u, a.v, a.w} < vi{b.u, b.v, b.w}); } map<query, int> asked; int ask_query(int u, int v, int w){ srt(u, v, w); query quest{u, v, w}; if (asked.find(quest) != asked.end()){ return asked.at(quest); } int ans = Query(u, v, w); asked.insert({quest, ans}); return ans; // return Query(u, v, w); } int n; vector<vi> graph; void solve_set(vi verts){ // print(verts); if (verts.size() == 1) return; if (verts.size() == 2){ int first = verts.front(), second = verts.back(); if (first > second) swap(first, second); Bridge(first, second); graph.at(first).push_back(second); graph.at(second).push_back(first); return; } int root_ind = randint(0, (int)verts.size()); int second_ind = randint(0, (int)verts.size()-1); if (second_ind >= root_ind) second_ind++; int root = verts.at(root_ind), second = verts.at(second_ind); vi subtr = {second}; vi left_nodes = {root}; vb in_path_to_second(n, false); queue<int> to_chk; for (auto &i:verts){ if (i != root && i != second){ int ans = ask_query(root, second, i); if (ans == root){ left_nodes.push_back(i); continue; } subtr.push_back(i); if (ans == i){ in_path_to_second.at(i) = true;; } } } solve_set(subtr); solve_set(left_nodes); // znalezc polaczenie int vert = second, parent = second; bool moved; // cout<<"przed petla: "; // print(verts); do{ // cout<<"hi\n"; moved = false; for (const auto &son:graph.at(vert)){ if (son != parent && in_path_to_second.at(son)){ parent = vert; vert = son; moved = true; break; } } } while(moved); if (vert > root) swap(vert, root); Bridge(vert, root); graph.at(vert).push_back(root); graph.at(root).push_back(vert); } void Solve(int N){ n = N; srand(SEED); graph.resize(n); vi nodes(n); for (int i = 0; i < n; i++) nodes.at(i) = i; solve_set(nodes); } /* const int MAX_N = 2000; const int MAX_CALLS = 100000; void WrongAnswer(int code) { printf("Wrong Answer [%d]\n", code); exit(0); } int N, num_calls; std::vector<int> graph_[MAX_N]; std::set<std::pair<int, int>> edges, edges_reported; int weight[MAX_N]; bool Visit(int p, int e, int rt = -1) { if (p == e) { ++weight[p]; return true; } for (int q : graph_[p]) { if (q != rt) { if (Visit(q, e, p)) { ++weight[p]; return true; } } } return false; } int Query(int u, int v, int w) { if (!(0 <= u && u <= N - 1 && 0 <= v && v <= N - 1 && 0 <= w && w <= N - 1 && u != v && u != w && v != w)) { WrongAnswer(1); } if (++num_calls > MAX_CALLS) { WrongAnswer(2); } std::fill(weight, weight + N, 0); Visit(u, v); Visit(u, w); Visit(v, w); for (int x = 0; x < N; ++x) { if (weight[x] == 3) { return x; } } printf("Error: the input may be invalid\n"); exit(0); } void Bridge(int u, int v) { if (!(0 <= u && u < v && v <= N - 1)) { printf("u: %d, v: %d\n", u, v); WrongAnswer(3); } if (!(edges.count(std::make_pair(u, v)) >= 1)) { WrongAnswer(4); } if (!(edges_reported.count(std::make_pair(u, v)) == 0)) { WrongAnswer(5); } edges_reported.insert(std::make_pair(u, v)); } int main() { if (scanf("%d", &N) != 1) { fprintf(stderr, "Error while reading input\n"); exit(1); } for (int i = 0; i < N - 1; ++i) { int u, v; if (scanf("%d%d", &u, &v) != 2) { fprintf(stderr, "Error while reading input\n"); exit(1); } graph_[u].push_back(v); graph_[v].push_back(u); edges.insert(std::make_pair(u, v)); } num_calls = 0; Solve(N); if (edges_reported.size() != static_cast<size_t>(N - 1)) { WrongAnswer(6); } printf("Accepted: %d\n", num_calls); return 0; } */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...