이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#ifdef Home
#define _GLIBCXX_DEBUG
#endif // Home
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const int N = 5555;
bool can[N][N];
int corr[N], have[N], T;
vector < int > V[N];
main() {
#ifdef Home
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif // Home
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, q, a, b;
cin >> n;
for(int i = 1; i < n; ++ i) {
cin >> corr[i];
}
for(int k, i = 1; i <= n; ++ i) {
cin >> k;
V[i].resize(k);
for(auto &j : V[i]) {
cin >> j;
}
}
for(int i = 1; i <= n; ++ i) {
++ T;
int l = i - 1, r = i;
for(auto &j : V[i]) {
have[j] = T;
}
bool L = true, R = true;
for(; L|R;) {
L = R = false;
for(; l && have[corr[l]] == T; -- l, L = true) {
can[i][l] = true;
for(auto &j : V[l]) {
have[j] = T;
}
}
for(; r < n && have[corr[r]] == T; R = true) {
++ r;
can[i][r] = true;
for(auto &j : V[r]) {
have[j] = T;
}
}
}
}
for(cin >> q; q --> 0;) {
cin >> a >> b;
cout << (can[a][b] ? "YES" : "NO") << '\n';
}
}
컴파일 시 표준 에러 (stderr) 메시지
long_mansion.cpp:21:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
21 | main() {
| ^~~~
# | 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... |