Submission #532005

# Submission time Handle Problem Language Result Execution time Memory
532005 2022-03-02T03:24:17 Z fhvirus Meetings (JOI19_meetings) C++17
0 / 100
112 ms 32584 KB
#include "meetings.h"
#include <bits/stdc++.h>
using namespace std;
typedef int64_t ll; typedef pair<int, int> pii;
#define pb emplace_back
#define AI(x) begin(x),end(x)
#define ff first
#define ss second
#ifdef OWO
#define debug(args...) LKJ("\033[1;32m[ " + string(#args) + " ]\033[0m", args)
template <class I> void LKJ(I&&x) { cerr << x << endl; }
template <class I, class...T> void LKJ(I&&x, T&&...t) { cerr << x << ", "; LKJ(t...); }
template <class I> void OI(I a, I b) { while (a != b) cerr << *a << " \n"[(a = next(a)) == b]; }
#else
#define debug(...) 0
#define OI(...) 0
#endif

namespace {

random_device rd;
mt19937 mt(rd());

const int kN = 2002;
int N, root, mem[kN][kN];

int queryLCA(int u, int v) {
	assert(u != v);
	if (mem[u][v] != -1) return mem[u][v];
	return (mem[u][v] = Query(root, u, v));
}
void addEdge(int u, int v) {
	if (u > v) swap(u, v);
	debug("Add edge", u, v);
	Bridge(u, v);
}

bool cmp(int u, int v) {
	return queryLCA(u, v) == u;
}

void init(int N) {
	::N = N;
	for (int i = 0; i < N; ++i)
		for (int j = 0; j < N; ++j)
			mem[i][j] = -1;
}

void solve(int rt, vector<int> ids) {
	debug(rt);
	OI(AI(ids));
	if (ids.empty()) return;
	if (ids.size() == 1) {
		addEdge(rt, ids[0]);
		return;
	}

	int u = ids.back(); ids.pop_back();
	map<int, vector<int>> mp;
	vector<int> ps;
	for (const int& v: ids) {
		int lca = queryLCA(u, v);
		if (lca == v and lca != u) ps.pb(lca);
		else mp[lca].pb(v);
	}

	debug(u);
	for (auto &[nrt, nids]: mp) {
		debug(nrt);
		OI(AI(nids));
	}

	sort(AI(ps));
	ps.erase(unique(AI(ps)), end(ps));
	sort(AI(ps), cmp);
	debug("ps");
	OI(AI(ps));

	addEdge(rt, ps[0]);
	addEdge(ps.back(), u);
	for (int i = 1; i < ps.size(); ++i)
		addEdge(ps[i - 1], ps[i]);

	for (auto &[nrt, nids]: mp) {
		//shuffle(AI(nids), mt);
		solve(nrt, nids);
	}
}

} // namespace

void Solve(int N) {
	init(N);

	vector<int> ids(N);
	iota(AI(ids), 0);
	//shuffle(AI(ids), mt);

	root = ids.back();
	ids.pop_back();

	debug(root);
	OI(AI(ids));
	solve(root, ids);

	/*
  for (int u = 0; u < N - 1; ++u)
    Bridge(u, u + 1);
	*/
}

Compilation message

meetings.cpp: In function 'void {anonymous}::addEdge(int, int)':
meetings.cpp:15:20: warning: statement has no effect [-Wunused-value]
   15 | #define debug(...) 0
      |                    ^
meetings.cpp:34:2: note: in expansion of macro 'debug'
   34 |  debug("Add edge", u, v);
      |  ^~~~~
meetings.cpp: In function 'void {anonymous}::solve(int, std::vector<int>)':
meetings.cpp:15:20: warning: statement has no effect [-Wunused-value]
   15 | #define debug(...) 0
      |                    ^
meetings.cpp:50:2: note: in expansion of macro 'debug'
   50 |  debug(rt);
      |  ^~~~~
meetings.cpp:16:17: warning: statement has no effect [-Wunused-value]
   16 | #define OI(...) 0
      |                 ^
meetings.cpp:51:2: note: in expansion of macro 'OI'
   51 |  OI(AI(ids));
      |  ^~
meetings.cpp:15:20: warning: statement has no effect [-Wunused-value]
   15 | #define debug(...) 0
      |                    ^
meetings.cpp:67:2: note: in expansion of macro 'debug'
   67 |  debug(u);
      |  ^~~~~
meetings.cpp:15:20: warning: statement has no effect [-Wunused-value]
   15 | #define debug(...) 0
      |                    ^
meetings.cpp:69:3: note: in expansion of macro 'debug'
   69 |   debug(nrt);
      |   ^~~~~
meetings.cpp:16:17: warning: statement has no effect [-Wunused-value]
   16 | #define OI(...) 0
      |                 ^
meetings.cpp:70:3: note: in expansion of macro 'OI'
   70 |   OI(AI(nids));
      |   ^~
meetings.cpp:68:13: warning: unused structured binding declaration [-Wunused-variable]
   68 |  for (auto &[nrt, nids]: mp) {
      |             ^~~~~~~~~~~
meetings.cpp:15:20: warning: statement has no effect [-Wunused-value]
   15 | #define debug(...) 0
      |                    ^
meetings.cpp:76:2: note: in expansion of macro 'debug'
   76 |  debug("ps");
      |  ^~~~~
meetings.cpp:16:17: warning: statement has no effect [-Wunused-value]
   16 | #define OI(...) 0
      |                 ^
meetings.cpp:77:2: note: in expansion of macro 'OI'
   77 |  OI(AI(ps));
      |  ^~
meetings.cpp:81:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   81 |  for (int i = 1; i < ps.size(); ++i)
      |                  ~~^~~~~~~~~~~
meetings.cpp: In function 'void Solve(int)':
meetings.cpp:15:20: warning: statement has no effect [-Wunused-value]
   15 | #define debug(...) 0
      |                    ^
meetings.cpp:102:2: note: in expansion of macro 'debug'
  102 |  debug(root);
      |  ^~~~~
meetings.cpp:16:17: warning: statement has no effect [-Wunused-value]
   16 | #define OI(...) 0
      |                 ^
meetings.cpp:103:2: note: in expansion of macro 'OI'
  103 |  OI(AI(ids));
      |  ^~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 328 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Runtime error 1 ms 456 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 328 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Runtime error 1 ms 456 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 328 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Runtime error 1 ms 456 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 112 ms 32584 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -