제출 #921840

#제출 시각아이디문제언어결과실행 시간메모리
921840boris_mihovMeetings (JOI19_meetings)C++17
29 / 100
1743 ms1164 KiB
#include "meetings.h" #include <algorithm> #include <iostream> #include <numeric> #include <cassert> #include <random> #include <vector> typedef long long llong; const int MAXN = 2000 + 10; const int INF = 1e9; int n; int sz[MAXN]; bool bl[MAXN]; int perm[MAXN]; std::vector <int> g[MAXN]; std::vector <int> g2[MAXN]; std::vector <int> c[MAXN]; std::vector <int> real[MAXN]; std::mt19937 rng(69420); void removeEdge(int u, int v) { // std::cout << "remove edge: " << u << ' ' << v << '\n'; if (u == -1 || v == -1) { return; } for (int &x : g2[u]) { if (x == v) { std::swap(x, g2[u].back()); g2[u].pop_back(); break; } } for (int &x : g2[v]) { if (x == u) { std::swap(x, g2[v].back()); g2[v].pop_back(); break; } } } void addEdge(int u, int v) { // std::cout << "add edge: " << u << ' ' << v << '\n'; if (u == -1 || v == -1) { return; } g2[u].push_back(v); g2[v].push_back(u); } void calcSize(int node, int par) { sz[node] = 1; for (const int &u : g[node]) { if (u == par || bl[u]) { continue; } calcSize(u, node); sz[node] += sz[u]; } } int findCentroid(int node, int par, int compSz) { for (const int &u : g[node]) { if (!bl[u] && u != par && sz[u] > compSz / 2) { return findCentroid(u, node, compSz); } } return node; } int decompose(int node) { calcSize(node, -1); int cntr = findCentroid(node, -1, sz[node]); bl[cntr] = true; for (const int &u : g[cntr]) { if (bl[u]) { continue; } c[cntr].push_back(decompose(u)); real[cntr].push_back(u); } return cntr; } void search(int node, int par, int added) { // std::cout << "call: " << node << '\n'; bool addedEdge = false; for (int i = 0 ; i < g[node].size() ; i++) { if (par == g[node][i]) { continue; } // std::cout << " query res: " << node << ' ' << g[node][i] << ' ' << added << " = " << "?" << '\n'; int res = Query(node, g[node][i], added); // std::cout << " query res: " << node << ' ' << g[node][i] << ' ' << added << " = " << res << '\n'; if (res == node) { continue; } if (res == added) { if (!addedEdge) { addEdge(node, added); addedEdge = true; } removeEdge(node, g[node][i]); addEdge(added, g[node][i]); continue; } if (res == g[node][i]) { search(g[node][i], node, added); return; } } if (!addedEdge) { addEdge(node, added); } } void Solve(int N) { n = N; std::iota(perm, perm + n, 0); std::shuffle(perm, perm + n, rng); // std::cout << "order\n"; // for (int i = 0 ; i < n ; ++i) // { // std::cout << perm[i] << ' '; // } // std::cout << '\n'; g[perm[0]].push_back(perm[1]); g[perm[1]].push_back(perm[0]); // std::cout << "first: " << perm[0] << '\n'; // std::cout << "second: " << perm[1] << '\n'; for (int i = 2 ; i < n ; ++i) { // std::cout << "here: " << perm[i] << '\n'; for (int j = 0 ; j < n ; ++j) { c[j].clear(); real[j].clear(); std::shuffle(g[j].begin(), g[j].end(), rng); } std::fill(bl, bl + n, false); int root = decompose(perm[0]); // for (int j = 0 ; j < n ; ++j) // { // std::shuffle(c[j].begin(), c[j].end(), rng); // } for (int i = 0 ; i < n ; ++i) { g2[i].clear(); for (const int &x : g[i]) { g2[i].push_back(x); } } search(perm[0], -1, perm[i]); for (int i = 0 ; i < n ; ++i) { g[i].clear(); for (const int &x : g2[i]) { g[i].push_back(x); } } // std::cout << "after adding\n"; // for (int i = 0 ; i < n ; ++i) // { // for (const int &u : g[i]) // { // if (i <= u) // { // std::cout << i << ' ' << u << '\n'; // } // } // } } for (int i = 0 ; i < n ; ++i) { for (const int &u : g[i]) { if (i < u) { Bridge(i, u); } } } }

컴파일 시 표준 에러 (stderr) 메시지

meetings.cpp: In function 'void search(int, int, int)':
meetings.cpp:116:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  116 |     for (int i = 0 ; i < g[node].size() ; i++)
      |                      ~~^~~~~~~~~~~~~~~~
meetings.cpp: In function 'void Solve(int)':
meetings.cpp:187:13: warning: unused variable 'root' [-Wunused-variable]
  187 |         int root = decompose(perm[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...