Submission #901298

#TimeUsernameProblemLanguageResultExecution timeMemory
901298LittleFlowers__Meetings (JOI19_meetings)C++17
100 / 100
887 ms1128 KiB
#include "meetings.h" #include<bits/stdc++.h> using namespace std; struct Runner { static const int N = 2e3 + 10; bool dd[N]; int sz[N]; vector<int> adj[N]; int n; void add_edge (int u, int v) { adj[u].push_back(v); adj[v].push_back(u); } void del_edge (int u, int v) { for(int i = 0; i < adj[u].size(); i++) if (adj[u][i] == v) { adj[u].erase(adj[u].begin() + i); } for(int i = 0; i < adj[v].size(); i++) if (adj[v][i] == u) { adj[v].erase(adj[v].begin() + i); } } int calc (int u, int p) { sz[u] = 1; for(int &v : adj[u]) if (v != p && !dd[v]) sz[u] += calc(v, u); return sz[u]; } int getcentr (int u, int p, int cnt) { for(int &v : adj[u]) if (v != p && !dd[v] && sz[v] * 2 > cnt) return getcentr(v, u, cnt); return u; } void middle (int a, int b, int c) { del_edge(a, b); int x = Query(a, b, c); add_edge(a, x); add_edge(b, x); if (c != x) add_edge(c, x); } void centroid (int u, int idx) { int node = getcentr(u, u, calc(u, u)); dd[node] = 1; sort(adj[node].begin(), adj[node].end(), [&] (const int &x, const int &y) { return sz[x] > sz[y]; }); // cout << node << endl; for(int i = 0; i + 1 < adj[node].size(); i += 2) { int a = adj[node][i]; int b = adj[node][i + 1]; if (Query(a, b, idx) != node) { int v = b; // cout << v << endl; if (Query(a, node, idx) != node) v = a; if (dd[v]) middle(node, v, idx); else centroid(v, idx); return; } } if (adj[node].size() % 2) { int v = adj[node].back(); if (Query(v, node, idx) != node) { if (dd[v]) middle(node, v, idx); else centroid(v, idx); return; } } add_edge(node, idx); } void Solve(int N) { n = N; add_edge(0, 1); for(int cur = 2; cur < n; cur++) if (adj[cur].empty()) { centroid(0, cur); for(int i = 0; i < n; i++) dd[i] = 0; } // // for(int i = 0; i < n; i++) for(int &j : adj[i]) if (i < j) { // cout << i << " " << j << endl; // } for(int i = 0; i < n; i++) for(int &j : adj[i]) if (i < j) { Bridge(i, j); } } }; Runner runner; void Solve(int N) { Runner newRunner; swap(runner, newRunner); runner.Solve(N); }

Compilation message (stderr)

meetings.cpp: In member function 'void Runner::del_edge(int, int)':
meetings.cpp:22:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |   for(int i = 0; i < adj[u].size(); i++) if (adj[u][i] == v) {
      |                  ~~^~~~~~~~~~~~~~~
meetings.cpp:25:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |   for(int i = 0; i < adj[v].size(); i++) if (adj[v][i] == u) {
      |                  ~~^~~~~~~~~~~~~~~
meetings.cpp: In member function 'void Runner::centroid(int, int)':
meetings.cpp:61:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |   for(int i = 0; i + 1 < adj[node].size(); i += 2) {
      |                  ~~~~~~^~~~~~~~~~~~~~~~~~
meetings.cpp: In function 'void Solve(int)':
meetings.cpp:5:8: warning: 'newRunner.Runner::n' is used uninitialized in this function [-Wuninitialized]
    5 | struct Runner {
      |        ^~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...