이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;
typedef long long ll;
#include "werewolf.h"
std::vector<int> check_validity(int n, std::vector<int> x, std::vector<int> y, std::vector<int> s, std::vector<int> e, std::vector<int> l, std::vector<int> r) {
vector <vector <int>> g(n);
for (int i = 0; i < (int)x.size(); ++i) {
g[x[i]].push_back(y[i]);
g[y[i]].push_back(x[i]);
}
int q = s.size();
vector <int> ans(q);
for (int i = 0; i < q; ++i) {
vector <int> go_s(n), go_e(n);
queue <int> q;
if (s[i] >= l[i]) {
q.push(s[i]);
go_s[s[i]] = 1;
}
while (!q.empty()) {
int u = q.front();
q.pop();
for (auto v : g[u]) {
if (!go_s[v] && v >= l[i]) {
go_s[v] = 1;
q.push(v);
}
}
}
while (!q.empty()) q.pop();
if (e[i] <= r[i]) {
q.push(e[i]);
go_e[e[i]] = 1;
}
while (!q.empty()) {
int u = q.front();
q.pop();
for (auto v : g[u]) {
if (!go_e[v] && v <= r[i]) {
go_e[v] = 1;
q.push(v);
}
}
}
bool ok = false;
for (int i = 0; i < n; ++i) {
ok |= (go_s[i] && go_e[i]);
}
ans[i] = ok;
}
return ans;
}
#ifdef LOCAL
namespace {
int read_int() {
int x;
cin >> x;
return x;
}
} // namespace
int main() {
ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef LOCAL
freopen("input.txt", "r", stdin);
#endif
int N = read_int();
int M = read_int();
int Q = read_int();
std::vector<int> X(M), Y(M), S(Q), E(Q), L(Q), R(Q);
for (int j = 0; j < M; ++j) {
X[j] = read_int();
Y[j] = read_int();
}
for (int i = 0; i < Q; ++i) {
S[i] = read_int();
E[i] = read_int();
L[i] = read_int();
R[i] = read_int();
}
std::vector<int> A = check_validity(N, X, Y, S, E, L, R);
for (size_t i = 0; i < A.size(); ++i) {
printf("%d\n", A[i]);
}
}
#endif
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |