# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
609671 |
2022-07-27T19:05:29 Z |
Mher |
Jail (JOI22_jail) |
C++14 |
|
5000 ms |
851420 KB |
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 7;
int n, m;
vector<vector<int>> g, p;
vector<int> tin, tout;
vector<int> s, f;
vector<int> col;
vector<int> parent;
vector<int> st, ft;
int cnt = 0;
void dfs(int v, int pr)
{
tin[v] = cnt++;
parent[v] = pr;
for (int to : g[v])
{
if (to == pr)
continue;
dfs(to, v);
}
tout[v] = cnt;
}
bool child(int a, int b)
{
return tin[a] <= tin[b] && tout[a] >= tout[b];
}
void build(int v)
{
//cout << v << endl;
int pnt = s[v];
while (!child(pnt, f[v]))
{
//cout << '-' << pnt << endl;
if (st[pnt] >= 0)
{
p[v].push_back(st[pnt]);
}
if (ft[pnt] >= 0)
{
p[ft[pnt]].push_back(v);
}
pnt = parent[pnt];
}
pnt = f[v];
while (!child(pnt, s[v]))
{
//cout << '-' << pnt << endl;
if (st[pnt] >= 0)
{
p[v].push_back(st[pnt]);
}
if (ft[pnt] >= 0)
{
p[ft[pnt]].push_back(v);
}
pnt = parent[pnt];
}
if (st[pnt] >= 0)
{
p[v].push_back(st[pnt]);
}
if (ft[pnt] >= 0)
{
p[ft[pnt]].push_back(v);
}
}
bool cicle(int v)
{
col[v] = 1;
bool ans = true;
for (int to : p[v])
{
if (to == v)
continue;
if (col[to] == 1)
return false;
if (col[to] == 0)
ans &= cicle(to);
}
col[v] = 2;
return ans;
}
void solve()
{
cin >> n;
g.resize(n + 1);
for (int i = 1; i < n; i++)
{
int a, b;
cin >> a >> b;
g[a].push_back(b);
g[b].push_back(a);
}
cin >> m;
p.resize(m);
s.resize(m);
f.resize(m);
st.resize(n + 1, -1);
ft.resize(n + 1, -1);
for (int i = 0; i < m; i++)
{
cin >> s[i] >> f[i];
st[s[i]] = i;
ft[f[i]] = i;
}
tin.resize(n + 1);
tout.resize(n + 1);
parent.resize(n + 1);
dfs(1, 0);
col.resize(m, 0);
for (int i = 0; i < m; i++)
{
build(i);
}
bool ans = true;
for (int i = 0; i < m; i++)
{
if (col[i] == 0)
ans &= cicle(i);
}
cout << (ans ? "Yes" : "No") << endl;
g.clear();
p.clear();
tin.clear();
tout.clear();
s.clear();
f.clear();
col.clear();
parent.clear();
st.clear();
ft.clear();
}
int main()
{
int q;
cin >> q;
while (q--)
solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
24 ms |
212 KB |
Output is correct |
5 |
Correct |
52 ms |
212 KB |
Output is correct |
6 |
Correct |
3 ms |
212 KB |
Output is correct |
7 |
Correct |
3 ms |
212 KB |
Output is correct |
8 |
Correct |
6 ms |
340 KB |
Output is correct |
9 |
Correct |
157 ms |
2320 KB |
Output is correct |
10 |
Correct |
260 ms |
16200 KB |
Output is correct |
11 |
Correct |
13 ms |
212 KB |
Output is correct |
12 |
Correct |
83 ms |
396 KB |
Output is correct |
13 |
Correct |
227 ms |
46816 KB |
Output is correct |
14 |
Correct |
221 ms |
60692 KB |
Output is correct |
15 |
Execution timed out |
5094 ms |
851420 KB |
Time limit exceeded |
16 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
3 ms |
212 KB |
Output is correct |
4 |
Correct |
3 ms |
212 KB |
Output is correct |
5 |
Correct |
3 ms |
212 KB |
Output is correct |
6 |
Correct |
3 ms |
212 KB |
Output is correct |
7 |
Correct |
2 ms |
212 KB |
Output is correct |
8 |
Correct |
3 ms |
212 KB |
Output is correct |
9 |
Correct |
2 ms |
212 KB |
Output is correct |
10 |
Correct |
3 ms |
212 KB |
Output is correct |
11 |
Correct |
3 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
2 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
3 ms |
212 KB |
Output is correct |
4 |
Correct |
3 ms |
212 KB |
Output is correct |
5 |
Correct |
3 ms |
212 KB |
Output is correct |
6 |
Correct |
3 ms |
212 KB |
Output is correct |
7 |
Correct |
2 ms |
212 KB |
Output is correct |
8 |
Correct |
3 ms |
212 KB |
Output is correct |
9 |
Correct |
2 ms |
212 KB |
Output is correct |
10 |
Correct |
3 ms |
212 KB |
Output is correct |
11 |
Correct |
3 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
2 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
3 ms |
212 KB |
Output is correct |
17 |
Correct |
3 ms |
212 KB |
Output is correct |
18 |
Correct |
3 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
4 ms |
212 KB |
Output is correct |
21 |
Correct |
3 ms |
212 KB |
Output is correct |
22 |
Correct |
4 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
3 ms |
212 KB |
Output is correct |
26 |
Correct |
1 ms |
212 KB |
Output is correct |
27 |
Correct |
2 ms |
212 KB |
Output is correct |
28 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
3 ms |
212 KB |
Output is correct |
4 |
Correct |
3 ms |
212 KB |
Output is correct |
5 |
Correct |
3 ms |
212 KB |
Output is correct |
6 |
Correct |
3 ms |
212 KB |
Output is correct |
7 |
Correct |
2 ms |
212 KB |
Output is correct |
8 |
Correct |
3 ms |
212 KB |
Output is correct |
9 |
Correct |
2 ms |
212 KB |
Output is correct |
10 |
Correct |
3 ms |
212 KB |
Output is correct |
11 |
Correct |
3 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
2 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
3 ms |
212 KB |
Output is correct |
17 |
Correct |
3 ms |
212 KB |
Output is correct |
18 |
Correct |
3 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
4 ms |
212 KB |
Output is correct |
21 |
Correct |
3 ms |
212 KB |
Output is correct |
22 |
Correct |
4 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
3 ms |
212 KB |
Output is correct |
26 |
Correct |
1 ms |
212 KB |
Output is correct |
27 |
Correct |
2 ms |
212 KB |
Output is correct |
28 |
Correct |
1 ms |
212 KB |
Output is correct |
29 |
Correct |
5 ms |
340 KB |
Output is correct |
30 |
Correct |
4 ms |
212 KB |
Output is correct |
31 |
Correct |
4 ms |
340 KB |
Output is correct |
32 |
Correct |
3 ms |
212 KB |
Output is correct |
33 |
Correct |
4 ms |
212 KB |
Output is correct |
34 |
Correct |
3 ms |
212 KB |
Output is correct |
35 |
Correct |
5 ms |
340 KB |
Output is correct |
36 |
Correct |
3 ms |
340 KB |
Output is correct |
37 |
Correct |
2 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
3 ms |
212 KB |
Output is correct |
4 |
Correct |
3 ms |
212 KB |
Output is correct |
5 |
Correct |
3 ms |
212 KB |
Output is correct |
6 |
Correct |
3 ms |
212 KB |
Output is correct |
7 |
Correct |
2 ms |
212 KB |
Output is correct |
8 |
Correct |
3 ms |
212 KB |
Output is correct |
9 |
Correct |
2 ms |
212 KB |
Output is correct |
10 |
Correct |
3 ms |
212 KB |
Output is correct |
11 |
Correct |
3 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
2 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
3 ms |
212 KB |
Output is correct |
17 |
Correct |
3 ms |
212 KB |
Output is correct |
18 |
Correct |
3 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
4 ms |
212 KB |
Output is correct |
21 |
Correct |
3 ms |
212 KB |
Output is correct |
22 |
Correct |
4 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
3 ms |
212 KB |
Output is correct |
26 |
Correct |
1 ms |
212 KB |
Output is correct |
27 |
Correct |
2 ms |
212 KB |
Output is correct |
28 |
Correct |
1 ms |
212 KB |
Output is correct |
29 |
Correct |
5 ms |
340 KB |
Output is correct |
30 |
Correct |
4 ms |
212 KB |
Output is correct |
31 |
Correct |
4 ms |
340 KB |
Output is correct |
32 |
Correct |
3 ms |
212 KB |
Output is correct |
33 |
Correct |
4 ms |
212 KB |
Output is correct |
34 |
Correct |
3 ms |
212 KB |
Output is correct |
35 |
Correct |
5 ms |
340 KB |
Output is correct |
36 |
Correct |
3 ms |
340 KB |
Output is correct |
37 |
Correct |
2 ms |
212 KB |
Output is correct |
38 |
Correct |
133 ms |
2364 KB |
Output is correct |
39 |
Correct |
260 ms |
16124 KB |
Output is correct |
40 |
Correct |
94 ms |
1348 KB |
Output is correct |
41 |
Correct |
68 ms |
724 KB |
Output is correct |
42 |
Correct |
86 ms |
1492 KB |
Output is correct |
43 |
Correct |
86 ms |
852 KB |
Output is correct |
44 |
Correct |
18 ms |
456 KB |
Output is correct |
45 |
Correct |
84 ms |
9208 KB |
Output is correct |
46 |
Correct |
88 ms |
9212 KB |
Output is correct |
47 |
Correct |
104 ms |
12176 KB |
Output is correct |
48 |
Correct |
118 ms |
11992 KB |
Output is correct |
49 |
Correct |
92 ms |
9400 KB |
Output is correct |
50 |
Correct |
86 ms |
9420 KB |
Output is correct |
51 |
Correct |
81 ms |
10100 KB |
Output is correct |
52 |
Correct |
80 ms |
10152 KB |
Output is correct |
53 |
Correct |
29 ms |
952 KB |
Output is correct |
54 |
Correct |
117 ms |
9212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
14 ms |
212 KB |
Output is correct |
6 |
Correct |
2 ms |
212 KB |
Output is correct |
7 |
Correct |
2 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
3 ms |
212 KB |
Output is correct |
13 |
Correct |
47 ms |
212 KB |
Output is correct |
14 |
Correct |
77 ms |
292 KB |
Output is correct |
15 |
Correct |
76 ms |
212 KB |
Output is correct |
16 |
Correct |
101 ms |
10140 KB |
Output is correct |
17 |
Correct |
180 ms |
17688 KB |
Output is correct |
18 |
Correct |
415 ms |
39636 KB |
Output is correct |
19 |
Correct |
114 ms |
10812 KB |
Output is correct |
20 |
Correct |
107 ms |
10700 KB |
Output is correct |
21 |
Correct |
105 ms |
10808 KB |
Output is correct |
22 |
Correct |
180 ms |
18288 KB |
Output is correct |
23 |
Correct |
152 ms |
18128 KB |
Output is correct |
24 |
Correct |
150 ms |
18316 KB |
Output is correct |
25 |
Correct |
149 ms |
18664 KB |
Output is correct |
26 |
Correct |
182 ms |
18592 KB |
Output is correct |
27 |
Correct |
211 ms |
21952 KB |
Output is correct |
28 |
Correct |
185 ms |
23220 KB |
Output is correct |
29 |
Correct |
186 ms |
20348 KB |
Output is correct |
30 |
Correct |
136 ms |
15768 KB |
Output is correct |
31 |
Correct |
164 ms |
16188 KB |
Output is correct |
32 |
Correct |
148 ms |
15572 KB |
Output is correct |
33 |
Correct |
137 ms |
16184 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
24 ms |
212 KB |
Output is correct |
5 |
Correct |
52 ms |
212 KB |
Output is correct |
6 |
Correct |
3 ms |
212 KB |
Output is correct |
7 |
Correct |
3 ms |
212 KB |
Output is correct |
8 |
Correct |
6 ms |
340 KB |
Output is correct |
9 |
Correct |
157 ms |
2320 KB |
Output is correct |
10 |
Correct |
260 ms |
16200 KB |
Output is correct |
11 |
Correct |
13 ms |
212 KB |
Output is correct |
12 |
Correct |
83 ms |
396 KB |
Output is correct |
13 |
Correct |
227 ms |
46816 KB |
Output is correct |
14 |
Correct |
221 ms |
60692 KB |
Output is correct |
15 |
Execution timed out |
5094 ms |
851420 KB |
Time limit exceeded |
16 |
Halted |
0 ms |
0 KB |
- |