제출 #825471

#제출 시각아이디문제언어결과실행 시간메모리
825471thimote75늑대인간 (IOI18_werewolf)C++14
0 / 100
4058 ms46952 KiB
#include "werewolf.h" #include <bits/stdc++.h> using namespace std; using idata = vector<int>; struct Road { int x, y; Road (int _x, int _y) { x = min(_x, _y); y = max(_x, _y); } int next (int a) { return x == a ? y : x; } bool operator< (const Road &other) { if (y == other.y) return x > other.x; return y < other.y; } }; struct UFD { idata parents; UFD (int size) { parents.resize(size); iota(parents.begin(), parents.end(), 0); } int boss (int x) { if (parents[x] != x) parents[x] = boss(parents[x]); return parents[x]; } bool merge (int a, int b) { a = boss(a); b = boss(b); if (a == b) return false; parents[a] = b; return true; } }; using t_Roads = vector<Road>; using t_Graph = vector<t_Roads>; t_Graph roads; int dfs (int source, int target, int parent, int left, int vdepth) { if (source == target) return vdepth; int res = 0; for (Road &road : roads[source]) { int next = road.next(source); if (next == parent) continue ; int cost = (road.x >= left ? 0 : road.y); res = max( res, dfs(next, target, source, left, max(vdepth, cost)) ); } return res; } idata check_validity(int N, idata X, idata Y, idata S, idata E, idata L, idata R) { int M = X.size(); int Q = S.size(); t_Roads road_array; for (int i = 0; i < M; i ++) road_array.push_back(Road(X[i], Y[i])); sort(road_array.begin(), road_array.end()); roads.resize(N); UFD ufd(N); for (Road &road : road_array) { if (!ufd.merge(road.x, road.y)) continue ; roads[road.x].push_back(road); roads[road.y].push_back(road); } idata A(Q); //return A; for (int i = 0; i < Q; i ++) A[i] = dfs(S[i], E[i], -1, L[i], 0) <= R[i] ? 1 : 0; return A; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...