제출 #769177

#제출 시각아이디문제언어결과실행 시간메모리
769177khshg늑대인간 (IOI18_werewolf)C++14
0 / 100
216 ms37620 KiB
#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(S[ind]); } vector<int> ans(Q); for(int i = 0; i < Q; ++i) { ans[i] = SL[i] <= ER[i] || EL[i] <= SR[i]; } return ans; }

컴파일 시 표준 에러 (stderr) 메시지

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;
      |           ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...