답안 #51902

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
51902 2018-06-22T14:15:04 Z aome Simurgh (IOI17_simurgh) C++17
0 / 100
3 ms 840 KB
#include <bits/stdc++.h>
#include "simurgh.h"

using namespace std;

const int N = 510;

int n, m;
int deg[N];
int label[N][N];
bool tree_edge[N][N];
vector<int> res;

vector<int> find_roads(int _n, vector<int> u, vector<int> v) {
	n = _n;
	for (int i = 0; i < n * (n - 1) / 2; ++i) {
		label[u[i]][v[i]] = label[v[i]][u[i]] = i;
	}
	for (int i = 0; i < n; ++i) {
		vector<int> ask;
		for (int j = 0; j < n; ++j) {
			if (i == j) continue;
			ask.push_back(label[i][j]);
		}
		deg[i] = count_common_roads(ask);
	}
	queue<int> qu;
	for (int i = 0; i < n; ++i) {
		if (deg[i] == 1) qu.push(i);
	}
	int leaf1 = qu.front(); qu.pop();
	int leaf2 = qu.front();
	for (int i = 0; i < n; ++i) {
		if (i == leaf1 || i == leaf2) continue;
		vector<int> ask;
		for (int j = 0; j < n; ++j) {
			if (j == leaf1 || j == leaf2) continue;
			ask.push_back(label[leaf2][j]);
		}
		ask.push_back(label[leaf1][i]);
		int tmp = count_common_roads(ask);
		if (tmp == 2) {
			res.push_back(label[leaf1][i]);
			tree_edge[leaf1][i] = tree_edge[i][leaf1] = 1;
			deg[i]--;
			if (deg[i] == 1) qu.push(i);
		}
	}
	while (qu.size()) {
		int u = qu.front(); qu.pop();
		if (deg[u] != 1) continue; 
		vector<int> vec;
		for (int i = 0; i < n; ++i) {
			if (i == leaf1 || i == u) continue;
			vec.push_back(i);
		}
		int l = 0, r = n - 3;
		while (l < r) {
			int mid = (l + r) >> 1;
			vector<int> ask;
			int cnt = 0;
			for (int i = l; i <= mid; ++i) {
				ask.push_back(label[u][vec[i]]);
				cnt += tree_edge[u][vec[i]];
			}
			ask.push_back(label[u][leaf1]);
			cnt += tree_edge[u][leaf1];
			for (int i = 0; i < l; ++i) {
				ask.push_back(label[leaf1][vec[i]]);
				cnt += tree_edge[leaf1][vec[i]];
			}
			for (int i = mid + 1; i < n - 2; ++i) {
				ask.push_back(label[leaf1][vec[i]]);
				cnt += tree_edge[leaf1][vec[i]];
			}
			int tmp = count_common_roads(ask);
			if (tmp == cnt + 1) r = mid;
			else l = mid + 1;
		}
		res.push_back(label[u][vec[l]]);
		tree_edge[u][vec[l]] = tree_edge[vec[l]][u] = 1;
		deg[vec[l]]--;
		if (deg[vec[l]] == 1) qu.push(vec[l]);
	}
	return res;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB correct
2 Correct 2 ms 484 KB correct
3 Correct 2 ms 484 KB correct
4 Runtime error 2 ms 716 KB Execution killed with signal 11 (could be triggered by violating memory limits)
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB correct
2 Correct 2 ms 484 KB correct
3 Correct 2 ms 484 KB correct
4 Runtime error 2 ms 716 KB Execution killed with signal 11 (could be triggered by violating memory limits)
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB correct
2 Correct 2 ms 484 KB correct
3 Correct 2 ms 484 KB correct
4 Runtime error 2 ms 716 KB Execution killed with signal 11 (could be triggered by violating memory limits)
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 3 ms 840 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB correct
2 Correct 2 ms 484 KB correct
3 Correct 2 ms 484 KB correct
4 Runtime error 2 ms 716 KB Execution killed with signal 11 (could be triggered by violating memory limits)
5 Halted 0 ms 0 KB -