답안 #769198

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
769198 2023-06-29T09:48:29 Z khshg 늑대인간 (IOI18_werewolf) C++14
0 / 100
218 ms 29300 KB
#include "werewolf.h"
#include<bits/stdc++.h>
using namespace std;

int N;
vector<vector<int>> adj;
vector<int> D;
vector<pair<int, int>> range;

void init(int N) {
	D = vector<int>(N, -1);
	range.resize(N);
	for(int i = 0; i < N; ++i) {
		range[i] = {i, i};
	}
}

int parent(int x) {
	return (D[x] < 0 ? x : D[x] = parent(D[x]));
}

pair<int, int> range_of_ind(int i) {
	return range[parent(i)];
}

void unite(int x, int y) {
	x = parent(x); y = parent(y);
	if(x == y) return;
	if(D[x] > D[y]) swap(x, y);
	range[x].first = min(range[x].first, range[y].first);
	range[x].second = max(range[x].second, range[y].second);
	D[x] += D[y];
	D[y] = x;
}
 
vector<int> check_validity(int _N, vector<int> X, vector<int> Y, vector<int> S, vector<int> E, vector<int> L, vector<int> R) {
	N = _N;
	adj.resize(N);
	int M = (int)X.size();
	for(int i = 0; i < M; ++i) {
		adj[X[i]].push_back(Y[i]);
		adj[Y[i]].push_back(X[i]);
	}
	vector<int> flat(N), pos(N);
	{
		int root;
		for(int i = 0; i < N; ++i) if((int)adj[i].size() == 1) { root = i; break; }
		int cur = root, prev = -1;
		for(int i = 0; i < N; ++i) {
			flat[i] = cur;
			pos[cur] = i;
			if(i == N - 1) continue;
			bool f = (adj[cur][0] == prev);
			prev = cur;
			cur = adj[cur][f];
		}
	}
	int Q = (int)L.size();
	vector<int> sind(Q);
	iota(begin(sind), end(sind), 0);
	sort(begin(sind), end(sind), [&](const int i, const int j) { return L[i] < L[j]; });
	int do_now = N - 1;
	init(N);
	vector<int> SL(Q), SR(Q), EL(Q), ER(Q);
	for(int i = Q - 1; i >= 0; --i) {
		int ind = sind[i];
		while(do_now >= L[ind]) {
			for(auto& u : adj[do_now]) {
				if(u >= do_now) unite(u, do_now);
			}
			--do_now;
		}
		tie(SL[ind], SR[ind]) = range_of_ind(S[ind]);
	}
	init(N);
	sort(begin(sind), end(sind), [&](const int i, const int j) { return R[i] < R[j]; });
	do_now = 0;
	for(int i = 0; i < Q; ++i) {
		int ind = sind[i];
		while(do_now <= R[ind]) {
			for(auto& u : adj[do_now]) {
				if(u <= do_now) unite(u, do_now);
			}
			++do_now;
		}
		tie(EL[ind], ER[ind]) = range_of_ind(E[ind]);
	}
	vector<int> ans(Q);
	for(int i = 0; i < Q; ++i) {
		ans[i] = !((EL[i] > SR[i]) || (SL[i] > ER[i]));
	}
	return ans;
}

Compilation message

werewolf.cpp: In function 'std::vector<int> check_validity(int, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
werewolf.cpp:51:11: warning: 'cur' may be used uninitialized in this function [-Wmaybe-uninitialized]
   51 |    pos[cur] = i;
      |           ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 218 ms 29300 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -