Submission #375226

# Submission time Handle Problem Language Result Execution time Memory
375226 2021-03-09T04:45:55 Z 8e7 Meetings (JOI19_meetings) C++14
100 / 100
1384 ms 1260 KB
//Challenge: Accepted
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <random>
#include "meetings.h"
#define ll long long
#define maxn 3005
#define pii pair<int, int>
#define ff first
#define ss second
#define io ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;

int tot;
vector<pii> ans;

vector<int> adj[maxn], sub[maxn];
bool found[maxn];
void dfs(int n, vector<int> &add) {
	found[n] = 1;
	add.push_back(n);
	for (int v:adj[n]) {
		if (!found[v]) {
			dfs(v, add);
		}
	}
}

int getcon(int root, vector<int> v) {
	if (v.size() == 1) return v[0];
	int ret = Query(root, v[0], v[1]);
	for (int i = 2;i < v.size();i++) {
		if (ret != v[i]) ret = Query(root, ret, v[i]);
	}
	return ret;
}

int curroot;
inline bool cmp(int x, int y) {
	return Query(curroot, x, y) == x;
}

void solve(int root, vector<int> v) {
	if (v.size() == 0) return;
	if (v.size() == 1) {
		ans.push_back(make_pair(root, v[0]));
		return;
	}
	random_shuffle(v.begin(), v.end());
	for (int i = 0;i < v.size();i++) found[v[i]] = 0;
	sub[root].clear();
	vector<int> path;
	path.push_back(v[0]);
	found[root] = found[v[0]] = 1;
	int x = v[0];
	sub[x].clear();
	for (int i = 1;i < v.size();i++) {
		int val = Query(root, x, v[i]);
		if (val == x) {
			if (!found[v[i]]) {
				path.push_back(v[i]);
				found[v[i]] = 1;
				sub[v[i]].clear();
			}
			x = v[i];
		} else {
			if (!found[val]) {
				path.push_back(val);
				found[val] = 1;
				sub[val].clear();
			}
			if (val != v[i]) {
				sub[val].push_back(v[i]);
			}
		}
	}
	//finds a path from root to leaf and splits other nodes (vs - 1 queries)
	curroot = root;
	sort(path.begin(), path.end(), cmp);
	for (int i = 0;i < path.size();i++) {

		ans.push_back(i ? make_pair(path[i], path[i - 1]) : make_pair(path[i], root));
	}
	//cout << endl;
	path.push_back(root);
	for (int i = 0;i < path.size();i++) {
		solve(path[i], sub[path[i]]);
	}
}

void Solve(int N) {
	srand(time(NULL));
	ans.clear();
	tot = N;
	vector<int> v;
	for (int i = 1;i < tot;i++) v.push_back(i);
	solve(0, v);
	for (auto i:ans) {
		if (i.ff > i.ss) swap(i.ff, i.ss);
		//cout << i.ff << "  " << i.ss << endl;
		Bridge(i.ff, i.ss);
	}
}
/*
5
0 1
0 2
1 3
1 4

 */

Compilation message

meetings.cpp: In function 'int getcon(int, std::vector<int>)':
meetings.cpp:34:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |  for (int i = 2;i < v.size();i++) {
      |                 ~~^~~~~~~~~~
meetings.cpp: In function 'void solve(int, std::vector<int>)':
meetings.cpp:52:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |  for (int i = 0;i < v.size();i++) found[v[i]] = 0;
      |                 ~~^~~~~~~~~~
meetings.cpp:59:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |  for (int i = 1;i < v.size();i++) {
      |                 ~~^~~~~~~~~~
meetings.cpp:82:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   82 |  for (int i = 0;i < path.size();i++) {
      |                 ~~^~~~~~~~~~~~~
meetings.cpp:88:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   88 |  for (int i = 0;i < path.size();i++) {
      |                 ~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 512 KB Output is correct
3 Correct 1 ms 504 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 1 ms 512 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 1 ms 492 KB Output is correct
12 Correct 1 ms 492 KB Output is correct
13 Correct 1 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 512 KB Output is correct
3 Correct 1 ms 504 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 1 ms 512 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 1 ms 492 KB Output is correct
12 Correct 1 ms 492 KB Output is correct
13 Correct 1 ms 492 KB Output is correct
14 Correct 1 ms 492 KB Output is correct
15 Correct 1 ms 492 KB Output is correct
16 Correct 1 ms 492 KB Output is correct
17 Correct 1 ms 492 KB Output is correct
18 Correct 1 ms 492 KB Output is correct
19 Correct 1 ms 492 KB Output is correct
20 Correct 1 ms 492 KB Output is correct
21 Correct 1 ms 492 KB Output is correct
22 Correct 1 ms 492 KB Output is correct
23 Correct 1 ms 492 KB Output is correct
24 Correct 1 ms 492 KB Output is correct
25 Correct 1 ms 492 KB Output is correct
26 Correct 1 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 512 KB Output is correct
3 Correct 1 ms 504 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 1 ms 512 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 1 ms 492 KB Output is correct
12 Correct 1 ms 492 KB Output is correct
13 Correct 1 ms 492 KB Output is correct
14 Correct 1 ms 492 KB Output is correct
15 Correct 1 ms 492 KB Output is correct
16 Correct 1 ms 492 KB Output is correct
17 Correct 1 ms 492 KB Output is correct
18 Correct 1 ms 492 KB Output is correct
19 Correct 1 ms 492 KB Output is correct
20 Correct 1 ms 492 KB Output is correct
21 Correct 1 ms 492 KB Output is correct
22 Correct 1 ms 492 KB Output is correct
23 Correct 1 ms 492 KB Output is correct
24 Correct 1 ms 492 KB Output is correct
25 Correct 1 ms 492 KB Output is correct
26 Correct 1 ms 492 KB Output is correct
27 Correct 7 ms 620 KB Output is correct
28 Correct 7 ms 620 KB Output is correct
29 Correct 10 ms 620 KB Output is correct
30 Correct 7 ms 620 KB Output is correct
31 Correct 6 ms 620 KB Output is correct
32 Correct 8 ms 620 KB Output is correct
33 Correct 16 ms 620 KB Output is correct
34 Correct 17 ms 620 KB Output is correct
35 Correct 16 ms 620 KB Output is correct
36 Correct 7 ms 512 KB Output is correct
37 Correct 17 ms 620 KB Output is correct
38 Correct 18 ms 620 KB Output is correct
39 Correct 17 ms 620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 500 ms 1004 KB Output is correct
2 Correct 538 ms 1004 KB Output is correct
3 Correct 544 ms 1004 KB Output is correct
4 Correct 619 ms 1008 KB Output is correct
5 Correct 404 ms 876 KB Output is correct
6 Correct 513 ms 1048 KB Output is correct
7 Correct 736 ms 1260 KB Output is correct
8 Correct 864 ms 900 KB Output is correct
9 Correct 835 ms 1132 KB Output is correct
10 Correct 861 ms 876 KB Output is correct
11 Correct 960 ms 1132 KB Output is correct
12 Correct 469 ms 1004 KB Output is correct
13 Correct 299 ms 876 KB Output is correct
14 Correct 559 ms 876 KB Output is correct
15 Correct 467 ms 876 KB Output is correct
16 Correct 569 ms 876 KB Output is correct
17 Correct 830 ms 1028 KB Output is correct
18 Correct 419 ms 876 KB Output is correct
19 Correct 456 ms 876 KB Output is correct
20 Correct 666 ms 876 KB Output is correct
21 Correct 612 ms 1132 KB Output is correct
22 Correct 635 ms 1004 KB Output is correct
23 Correct 642 ms 876 KB Output is correct
24 Correct 620 ms 912 KB Output is correct
25 Correct 534 ms 876 KB Output is correct
26 Correct 509 ms 876 KB Output is correct
27 Correct 572 ms 1016 KB Output is correct
28 Correct 993 ms 1004 KB Output is correct
29 Correct 830 ms 1004 KB Output is correct
30 Correct 801 ms 1132 KB Output is correct
31 Correct 883 ms 876 KB Output is correct
32 Correct 1384 ms 1132 KB Output is correct
33 Correct 1129 ms 884 KB Output is correct
34 Correct 7 ms 620 KB Output is correct
35 Correct 7 ms 620 KB Output is correct
36 Correct 6 ms 620 KB Output is correct
37 Correct 6 ms 620 KB Output is correct
38 Correct 6 ms 620 KB Output is correct
39 Correct 8 ms 620 KB Output is correct
40 Correct 14 ms 620 KB Output is correct
41 Correct 18 ms 620 KB Output is correct
42 Correct 16 ms 620 KB Output is correct
43 Correct 6 ms 620 KB Output is correct
44 Correct 17 ms 620 KB Output is correct
45 Correct 17 ms 620 KB Output is correct
46 Correct 17 ms 620 KB Output is correct
47 Correct 1 ms 492 KB Output is correct
48 Correct 1 ms 492 KB Output is correct
49 Correct 1 ms 492 KB Output is correct
50 Correct 1 ms 492 KB Output is correct
51 Correct 1 ms 492 KB Output is correct
52 Correct 1 ms 492 KB Output is correct
53 Correct 1 ms 492 KB Output is correct
54 Correct 1 ms 492 KB Output is correct
55 Correct 1 ms 492 KB Output is correct
56 Correct 1 ms 492 KB Output is correct
57 Correct 1 ms 492 KB Output is correct
58 Correct 1 ms 492 KB Output is correct
59 Correct 1 ms 492 KB Output is correct
60 Correct 1 ms 492 KB Output is correct
61 Correct 1 ms 492 KB Output is correct
62 Correct 1 ms 492 KB Output is correct
63 Correct 1 ms 492 KB Output is correct
64 Correct 1 ms 492 KB Output is correct
65 Correct 1 ms 492 KB Output is correct
66 Correct 1 ms 492 KB Output is correct
67 Correct 1 ms 492 KB Output is correct
68 Correct 1 ms 492 KB Output is correct
69 Correct 1 ms 492 KB Output is correct
70 Correct 1 ms 492 KB Output is correct
71 Correct 1 ms 492 KB Output is correct
72 Correct 1 ms 492 KB Output is correct