#include <iostream>
#include <set>
#include <vector>
using namespace std;
int main()
{
int N;
cin >> N;
int C[N+1];
for(int i = 1; i < N; i++) cin >> C[i];
set<int> keys[N+1];
for(int i = 1; i <= N; i++)
{
int B;
cin >> B;
for(int j = 1; j <= B; j++)
{
int A;
cin >> A;
keys[i].insert(A);
}
}
vector<int> left_reach(1+N), right_reach(1+N);
for(int i = 1; i <= N; i++)
{
left_reach[i] = right_reach[i] = i;
set<int> curr_keys;
for(int k: keys[i]) curr_keys.insert(k);
while(1)
{
if(left_reach[i] != 1 && curr_keys.find( C[ left_reach[i]-1 ]) != curr_keys.end() )
{
left_reach[i]--;
for(int k: keys[ left_reach[i] ]) curr_keys.insert(k);
}
else if(right_reach[i] != N && curr_keys.find( C[ right_reach[i] ] ) != curr_keys.end())
{
right_reach[i]++;
for(int k: keys[ right_reach[i] ]) curr_keys.insert(k);
}
else break;
}
}
int Q;
cin >> Q;
for(int q = 1; q <= Q; q++)
{
int x, y;
cin >> x >> y;
if(left_reach[x] <= y && y <= right_reach[x])
{
cout << "YES\n";
}
else cout << "NO\n";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
588 KB |
Output is correct |
2 |
Correct |
155 ms |
716 KB |
Output is correct |
3 |
Correct |
383 ms |
876 KB |
Output is correct |
4 |
Correct |
32 ms |
680 KB |
Output is correct |
5 |
Correct |
436 ms |
636 KB |
Output is correct |
6 |
Correct |
153 ms |
664 KB |
Output is correct |
7 |
Correct |
128 ms |
668 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
588 KB |
Output is correct |
2 |
Correct |
155 ms |
716 KB |
Output is correct |
3 |
Correct |
383 ms |
876 KB |
Output is correct |
4 |
Correct |
32 ms |
680 KB |
Output is correct |
5 |
Correct |
436 ms |
636 KB |
Output is correct |
6 |
Correct |
153 ms |
664 KB |
Output is correct |
7 |
Correct |
128 ms |
668 KB |
Output is correct |
8 |
Correct |
1102 ms |
6488 KB |
Output is correct |
9 |
Correct |
1076 ms |
6608 KB |
Output is correct |
10 |
Correct |
1235 ms |
6932 KB |
Output is correct |
11 |
Correct |
1452 ms |
7452 KB |
Output is correct |
12 |
Correct |
1114 ms |
6276 KB |
Output is correct |
13 |
Correct |
1061 ms |
6760 KB |
Output is correct |
14 |
Correct |
1093 ms |
6848 KB |
Output is correct |
15 |
Correct |
1273 ms |
6616 KB |
Output is correct |
16 |
Correct |
1467 ms |
6540 KB |
Output is correct |
17 |
Correct |
1067 ms |
6704 KB |
Output is correct |
18 |
Correct |
1129 ms |
6740 KB |
Output is correct |
19 |
Correct |
1131 ms |
6708 KB |
Output is correct |
20 |
Correct |
1456 ms |
6860 KB |
Output is correct |
21 |
Correct |
1478 ms |
6676 KB |
Output is correct |
22 |
Correct |
1420 ms |
6688 KB |
Output is correct |
23 |
Correct |
1230 ms |
6476 KB |
Output is correct |
24 |
Correct |
1222 ms |
6720 KB |
Output is correct |
25 |
Correct |
1177 ms |
6572 KB |
Output is correct |
26 |
Correct |
1113 ms |
6544 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3076 ms |
26948 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
588 KB |
Output is correct |
2 |
Correct |
155 ms |
716 KB |
Output is correct |
3 |
Correct |
383 ms |
876 KB |
Output is correct |
4 |
Correct |
32 ms |
680 KB |
Output is correct |
5 |
Correct |
436 ms |
636 KB |
Output is correct |
6 |
Correct |
153 ms |
664 KB |
Output is correct |
7 |
Correct |
128 ms |
668 KB |
Output is correct |
8 |
Correct |
1102 ms |
6488 KB |
Output is correct |
9 |
Correct |
1076 ms |
6608 KB |
Output is correct |
10 |
Correct |
1235 ms |
6932 KB |
Output is correct |
11 |
Correct |
1452 ms |
7452 KB |
Output is correct |
12 |
Correct |
1114 ms |
6276 KB |
Output is correct |
13 |
Correct |
1061 ms |
6760 KB |
Output is correct |
14 |
Correct |
1093 ms |
6848 KB |
Output is correct |
15 |
Correct |
1273 ms |
6616 KB |
Output is correct |
16 |
Correct |
1467 ms |
6540 KB |
Output is correct |
17 |
Correct |
1067 ms |
6704 KB |
Output is correct |
18 |
Correct |
1129 ms |
6740 KB |
Output is correct |
19 |
Correct |
1131 ms |
6708 KB |
Output is correct |
20 |
Correct |
1456 ms |
6860 KB |
Output is correct |
21 |
Correct |
1478 ms |
6676 KB |
Output is correct |
22 |
Correct |
1420 ms |
6688 KB |
Output is correct |
23 |
Correct |
1230 ms |
6476 KB |
Output is correct |
24 |
Correct |
1222 ms |
6720 KB |
Output is correct |
25 |
Correct |
1177 ms |
6572 KB |
Output is correct |
26 |
Correct |
1113 ms |
6544 KB |
Output is correct |
27 |
Execution timed out |
3076 ms |
26948 KB |
Time limit exceeded |
28 |
Halted |
0 ms |
0 KB |
- |