답안 #977413

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
977413 2024-05-07T22:35:36 Z mariaclara Simurgh (IOI17_simurgh) C++17
0 / 100
68 ms 2356 KB
#include "simurgh.h"
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define mk make_pair
#define pb push_back
#define fr first
#define sc second

vector<int> pai, tam;

int find(int x) {
	if(pai[x] == x) return x;
	return pai[x] = find(pai[x]);
}

void join(int x, int y) {
	x = find(x);
	y = find(y);
	if(tam[x] < tam[y]) {
		pai[x] = pai[y];
		tam[y] += tam[x];
	}
	else {
		pai[y] = pai[x];
		tam[x] += tam[y];
	}
}
vector<int> find_roads(int n, vector<int> u, vector<int> v) {
	vector<vector<int>> mark(n);
	vector<int> ans;
	vector<bool> in_tree(n);

	for(int i = 0; i < n; i++) mark[i].resize(n, -1);
	for(int i = 0; i < sz(u); i++) mark[u[i]][v[i]] = mark[v[i]][u[i]] = i;

	pai.resize(n);
	tam.resize(n);
	for(int i = 0; i < n; i++) {
		// fixa o vertice que estamos olhando
		if(in_tree[i]) continue;
		for(int j = 0; j < n; j++) pai[j] = j, tam[j] = 1;

		vector<int> roads, pos(n);
		for(int j = 0; j < sz(u); j++){
			if(u[j] == i or v[j] == i) continue;
			if(find(u[j]) != find(v[j])) join(u[j], v[j]), roads.pb(j);
		}

		vector<vector<int>> comps(n);
		for(int j = 0; j < n; j++)
			if(mark[i][j] != -1) comps[find(j)].pb(j);

		for(int j = 0; j < n; j++) {
			if(comps[j].empty()) continue;
			pos[j] = roads.size();
			roads.pb(mark[i][comps[j][0]]);
		}

		// cout << "---------\nCASO " << i << "\n";
		// cout << "query:\n";
		// for(auto x : roads) cout << u[x] << " " << v[x] << "\n";
		int ini = count_common_roads(roads);
		//cout << "return: " << ini << "\n";

		for(int j = 0; j < n; j++) {
			if(comps[j].empty()) continue;
			
			int max_val = ini;
			vector<int> add = {comps[j][0]};

			for(int k = 1; k < sz(comps[j]); k++) {
				roads[pos[j]] = mark[i][comps[j][k]];
				// cout << "query:\n";
				// for(auto x : roads) cout << u[x] << " " << v[x] << "\n";
				int new_val = count_common_roads(roads);
				//cout << "return: " << new_val << "\n";
				if(new_val > max_val) { add.clear(), add.pb(comps[j][k]), max_val = new_val; }
				else if(new_val == max_val) add.pb(comps[j][k]);
 			}

			roads[pos[j]] = mark[i][comps[j][0]];
			// cout << "to add:\n";
			// for(auto a : add) cout << i <<" " << a << "\n";
			for(auto a : add)
				ans.pb(mark[i][a]), in_tree[a] = 1;//, cout << "add " << mark[i][a] << "\n";
		}
	}

	return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB correct
2 Incorrect 0 ms 348 KB WA in grader: NO
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB correct
2 Incorrect 0 ms 348 KB WA in grader: NO
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB correct
2 Incorrect 0 ms 348 KB WA in grader: NO
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB correct
2 Correct 1 ms 348 KB correct
3 Incorrect 68 ms 2356 KB WA in grader: NO
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB correct
2 Incorrect 0 ms 348 KB WA in grader: NO
3 Halted 0 ms 0 KB -