# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
631409 |
2022-08-18T05:47:21 Z |
LittleCube |
Jail (JOI22_jail) |
C++14 |
|
5000 ms |
832252 KB |
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define F first
#define S second
using namespace std;
int T, N, M, pre[1200005], dis[1200005], s[1200005], e[1200005], deg[1200005], fr[1200005], to[1200005];
vector<int> E[1200005], topo[1200005];
void dfs(int u)
{
for(int v : E[u])
if(pre[u] != v)
{
pre[v] = u;
dis[v] = dis[u] + 1;
dfs(v);
}
}
void addedge(int pos, int i)
{
if(s[pos] && s[pos] != i)
topo[s[pos]].emplace_back(i);
if(e[pos] && e[pos] != i)
topo[i].emplace_back(e[pos]);
}
void solve()
{
cin >> N;
for(int i = 1; i <= N; i++)
{
pre[i] = dis[i] = s[i] = e[i] = 0;
E[i].clear();
}
for(int i = 1; i < N; i++)
{
int u, v;
cin >> u >> v;
E[u].emplace_back(v);
E[v].emplace_back(u);
}
cin >> M;
for(int i = 1; i <= M; i++)
{
deg[i] = 0;
topo[i].clear();
}
dfs(1);
for(int i = 1; i <= M; i++)
{
cin >> fr[i] >> to[i];
s[fr[i]] = i;
e[to[i]] = i;
}
for(int i = 1; i <= M; i++)
{
addedge(fr[i], i);
addedge(to[i], i);
while(fr[i] != to[i])
{
if(dis[fr[i]] < dis[to[i]])
swap(fr[i], to[i]);
fr[i] = pre[fr[i]];
addedge(fr[i], i);
}
}
for(int i = 1; i <= M; i++)
for(int j : topo[i])
deg[j]++;
queue<int> q;
for(int i = 1; i <= M; i++)
if(deg[i] == 0)
q.emplace(i);
for(int t = 1; t <= M; t++)
{
if(q.empty())
{
cout << "No\n";
return;
}
int u = q.front();
q.pop();
for(int v : topo[u])
{
deg[v]--;
if(deg[v] == 0)
q.emplace(v);
}
}
cout << "Yes\n";
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
cin >> T;
while(T--)
{
solve();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
28 ms |
56732 KB |
Output is correct |
2 |
Correct |
27 ms |
56680 KB |
Output is correct |
3 |
Correct |
28 ms |
56660 KB |
Output is correct |
4 |
Correct |
35 ms |
56720 KB |
Output is correct |
5 |
Correct |
42 ms |
56676 KB |
Output is correct |
6 |
Correct |
29 ms |
56656 KB |
Output is correct |
7 |
Correct |
28 ms |
56720 KB |
Output is correct |
8 |
Correct |
40 ms |
56824 KB |
Output is correct |
9 |
Correct |
149 ms |
59308 KB |
Output is correct |
10 |
Correct |
329 ms |
71184 KB |
Output is correct |
11 |
Correct |
33 ms |
56728 KB |
Output is correct |
12 |
Correct |
62 ms |
56744 KB |
Output is correct |
13 |
Correct |
203 ms |
100172 KB |
Output is correct |
14 |
Correct |
217 ms |
113936 KB |
Output is correct |
15 |
Execution timed out |
5087 ms |
832252 KB |
Time limit exceeded |
16 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
34 ms |
56660 KB |
Output is correct |
2 |
Correct |
31 ms |
56728 KB |
Output is correct |
3 |
Correct |
30 ms |
56688 KB |
Output is correct |
4 |
Correct |
31 ms |
56696 KB |
Output is correct |
5 |
Correct |
29 ms |
56724 KB |
Output is correct |
6 |
Correct |
28 ms |
56632 KB |
Output is correct |
7 |
Correct |
29 ms |
56632 KB |
Output is correct |
8 |
Correct |
35 ms |
56716 KB |
Output is correct |
9 |
Correct |
31 ms |
56744 KB |
Output is correct |
10 |
Correct |
29 ms |
56668 KB |
Output is correct |
11 |
Correct |
31 ms |
56660 KB |
Output is correct |
12 |
Correct |
34 ms |
56660 KB |
Output is correct |
13 |
Correct |
29 ms |
56656 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
34 ms |
56660 KB |
Output is correct |
2 |
Correct |
31 ms |
56728 KB |
Output is correct |
3 |
Correct |
30 ms |
56688 KB |
Output is correct |
4 |
Correct |
31 ms |
56696 KB |
Output is correct |
5 |
Correct |
29 ms |
56724 KB |
Output is correct |
6 |
Correct |
28 ms |
56632 KB |
Output is correct |
7 |
Correct |
29 ms |
56632 KB |
Output is correct |
8 |
Correct |
35 ms |
56716 KB |
Output is correct |
9 |
Correct |
31 ms |
56744 KB |
Output is correct |
10 |
Correct |
29 ms |
56668 KB |
Output is correct |
11 |
Correct |
31 ms |
56660 KB |
Output is correct |
12 |
Correct |
34 ms |
56660 KB |
Output is correct |
13 |
Correct |
29 ms |
56656 KB |
Output is correct |
14 |
Correct |
35 ms |
56732 KB |
Output is correct |
15 |
Correct |
28 ms |
56660 KB |
Output is correct |
16 |
Correct |
28 ms |
56748 KB |
Output is correct |
17 |
Correct |
31 ms |
56660 KB |
Output is correct |
18 |
Correct |
33 ms |
56652 KB |
Output is correct |
19 |
Correct |
31 ms |
56812 KB |
Output is correct |
20 |
Correct |
29 ms |
56644 KB |
Output is correct |
21 |
Correct |
29 ms |
56724 KB |
Output is correct |
22 |
Correct |
29 ms |
56684 KB |
Output is correct |
23 |
Correct |
28 ms |
56700 KB |
Output is correct |
24 |
Correct |
29 ms |
56696 KB |
Output is correct |
25 |
Correct |
36 ms |
56620 KB |
Output is correct |
26 |
Correct |
35 ms |
56704 KB |
Output is correct |
27 |
Correct |
32 ms |
56660 KB |
Output is correct |
28 |
Correct |
29 ms |
56612 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
34 ms |
56660 KB |
Output is correct |
2 |
Correct |
31 ms |
56728 KB |
Output is correct |
3 |
Correct |
30 ms |
56688 KB |
Output is correct |
4 |
Correct |
31 ms |
56696 KB |
Output is correct |
5 |
Correct |
29 ms |
56724 KB |
Output is correct |
6 |
Correct |
28 ms |
56632 KB |
Output is correct |
7 |
Correct |
29 ms |
56632 KB |
Output is correct |
8 |
Correct |
35 ms |
56716 KB |
Output is correct |
9 |
Correct |
31 ms |
56744 KB |
Output is correct |
10 |
Correct |
29 ms |
56668 KB |
Output is correct |
11 |
Correct |
31 ms |
56660 KB |
Output is correct |
12 |
Correct |
34 ms |
56660 KB |
Output is correct |
13 |
Correct |
29 ms |
56656 KB |
Output is correct |
14 |
Correct |
35 ms |
56732 KB |
Output is correct |
15 |
Correct |
28 ms |
56660 KB |
Output is correct |
16 |
Correct |
28 ms |
56748 KB |
Output is correct |
17 |
Correct |
31 ms |
56660 KB |
Output is correct |
18 |
Correct |
33 ms |
56652 KB |
Output is correct |
19 |
Correct |
31 ms |
56812 KB |
Output is correct |
20 |
Correct |
29 ms |
56644 KB |
Output is correct |
21 |
Correct |
29 ms |
56724 KB |
Output is correct |
22 |
Correct |
29 ms |
56684 KB |
Output is correct |
23 |
Correct |
28 ms |
56700 KB |
Output is correct |
24 |
Correct |
29 ms |
56696 KB |
Output is correct |
25 |
Correct |
36 ms |
56620 KB |
Output is correct |
26 |
Correct |
35 ms |
56704 KB |
Output is correct |
27 |
Correct |
32 ms |
56660 KB |
Output is correct |
28 |
Correct |
29 ms |
56612 KB |
Output is correct |
29 |
Correct |
30 ms |
56780 KB |
Output is correct |
30 |
Correct |
29 ms |
56768 KB |
Output is correct |
31 |
Correct |
30 ms |
56696 KB |
Output is correct |
32 |
Correct |
30 ms |
56660 KB |
Output is correct |
33 |
Correct |
28 ms |
56744 KB |
Output is correct |
34 |
Correct |
29 ms |
56720 KB |
Output is correct |
35 |
Correct |
30 ms |
56812 KB |
Output is correct |
36 |
Correct |
29 ms |
56696 KB |
Output is correct |
37 |
Correct |
28 ms |
56708 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
34 ms |
56660 KB |
Output is correct |
2 |
Correct |
31 ms |
56728 KB |
Output is correct |
3 |
Correct |
30 ms |
56688 KB |
Output is correct |
4 |
Correct |
31 ms |
56696 KB |
Output is correct |
5 |
Correct |
29 ms |
56724 KB |
Output is correct |
6 |
Correct |
28 ms |
56632 KB |
Output is correct |
7 |
Correct |
29 ms |
56632 KB |
Output is correct |
8 |
Correct |
35 ms |
56716 KB |
Output is correct |
9 |
Correct |
31 ms |
56744 KB |
Output is correct |
10 |
Correct |
29 ms |
56668 KB |
Output is correct |
11 |
Correct |
31 ms |
56660 KB |
Output is correct |
12 |
Correct |
34 ms |
56660 KB |
Output is correct |
13 |
Correct |
29 ms |
56656 KB |
Output is correct |
14 |
Correct |
35 ms |
56732 KB |
Output is correct |
15 |
Correct |
28 ms |
56660 KB |
Output is correct |
16 |
Correct |
28 ms |
56748 KB |
Output is correct |
17 |
Correct |
31 ms |
56660 KB |
Output is correct |
18 |
Correct |
33 ms |
56652 KB |
Output is correct |
19 |
Correct |
31 ms |
56812 KB |
Output is correct |
20 |
Correct |
29 ms |
56644 KB |
Output is correct |
21 |
Correct |
29 ms |
56724 KB |
Output is correct |
22 |
Correct |
29 ms |
56684 KB |
Output is correct |
23 |
Correct |
28 ms |
56700 KB |
Output is correct |
24 |
Correct |
29 ms |
56696 KB |
Output is correct |
25 |
Correct |
36 ms |
56620 KB |
Output is correct |
26 |
Correct |
35 ms |
56704 KB |
Output is correct |
27 |
Correct |
32 ms |
56660 KB |
Output is correct |
28 |
Correct |
29 ms |
56612 KB |
Output is correct |
29 |
Correct |
30 ms |
56780 KB |
Output is correct |
30 |
Correct |
29 ms |
56768 KB |
Output is correct |
31 |
Correct |
30 ms |
56696 KB |
Output is correct |
32 |
Correct |
30 ms |
56660 KB |
Output is correct |
33 |
Correct |
28 ms |
56744 KB |
Output is correct |
34 |
Correct |
29 ms |
56720 KB |
Output is correct |
35 |
Correct |
30 ms |
56812 KB |
Output is correct |
36 |
Correct |
29 ms |
56696 KB |
Output is correct |
37 |
Correct |
28 ms |
56708 KB |
Output is correct |
38 |
Correct |
139 ms |
59280 KB |
Output is correct |
39 |
Correct |
332 ms |
71132 KB |
Output is correct |
40 |
Correct |
83 ms |
58176 KB |
Output is correct |
41 |
Correct |
51 ms |
57108 KB |
Output is correct |
42 |
Correct |
77 ms |
58444 KB |
Output is correct |
43 |
Correct |
58 ms |
57160 KB |
Output is correct |
44 |
Correct |
39 ms |
56804 KB |
Output is correct |
45 |
Correct |
74 ms |
62416 KB |
Output is correct |
46 |
Correct |
66 ms |
62412 KB |
Output is correct |
47 |
Correct |
99 ms |
66008 KB |
Output is correct |
48 |
Correct |
125 ms |
66076 KB |
Output is correct |
49 |
Correct |
68 ms |
62456 KB |
Output is correct |
50 |
Correct |
67 ms |
62536 KB |
Output is correct |
51 |
Correct |
60 ms |
63632 KB |
Output is correct |
52 |
Correct |
61 ms |
63532 KB |
Output is correct |
53 |
Correct |
36 ms |
57128 KB |
Output is correct |
54 |
Correct |
73 ms |
62252 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
37 ms |
56688 KB |
Output is correct |
2 |
Correct |
31 ms |
56712 KB |
Output is correct |
3 |
Correct |
30 ms |
56696 KB |
Output is correct |
4 |
Correct |
30 ms |
56660 KB |
Output is correct |
5 |
Correct |
34 ms |
56652 KB |
Output is correct |
6 |
Correct |
31 ms |
56712 KB |
Output is correct |
7 |
Correct |
30 ms |
56660 KB |
Output is correct |
8 |
Correct |
32 ms |
56732 KB |
Output is correct |
9 |
Correct |
34 ms |
56712 KB |
Output is correct |
10 |
Correct |
31 ms |
56672 KB |
Output is correct |
11 |
Correct |
31 ms |
56656 KB |
Output is correct |
12 |
Correct |
31 ms |
56660 KB |
Output is correct |
13 |
Correct |
44 ms |
56720 KB |
Output is correct |
14 |
Correct |
50 ms |
56736 KB |
Output is correct |
15 |
Correct |
51 ms |
56652 KB |
Output is correct |
16 |
Correct |
74 ms |
62932 KB |
Output is correct |
17 |
Correct |
145 ms |
68544 KB |
Output is correct |
18 |
Correct |
342 ms |
89084 KB |
Output is correct |
19 |
Correct |
85 ms |
63036 KB |
Output is correct |
20 |
Correct |
78 ms |
63064 KB |
Output is correct |
21 |
Correct |
75 ms |
63000 KB |
Output is correct |
22 |
Correct |
120 ms |
69272 KB |
Output is correct |
23 |
Correct |
126 ms |
69812 KB |
Output is correct |
24 |
Correct |
110 ms |
69304 KB |
Output is correct |
25 |
Correct |
109 ms |
69444 KB |
Output is correct |
26 |
Correct |
110 ms |
69448 KB |
Output is correct |
27 |
Correct |
114 ms |
67908 KB |
Output is correct |
28 |
Correct |
117 ms |
67908 KB |
Output is correct |
29 |
Correct |
107 ms |
68008 KB |
Output is correct |
30 |
Correct |
84 ms |
65184 KB |
Output is correct |
31 |
Correct |
81 ms |
65096 KB |
Output is correct |
32 |
Correct |
99 ms |
65096 KB |
Output is correct |
33 |
Correct |
95 ms |
65180 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
28 ms |
56732 KB |
Output is correct |
2 |
Correct |
27 ms |
56680 KB |
Output is correct |
3 |
Correct |
28 ms |
56660 KB |
Output is correct |
4 |
Correct |
35 ms |
56720 KB |
Output is correct |
5 |
Correct |
42 ms |
56676 KB |
Output is correct |
6 |
Correct |
29 ms |
56656 KB |
Output is correct |
7 |
Correct |
28 ms |
56720 KB |
Output is correct |
8 |
Correct |
40 ms |
56824 KB |
Output is correct |
9 |
Correct |
149 ms |
59308 KB |
Output is correct |
10 |
Correct |
329 ms |
71184 KB |
Output is correct |
11 |
Correct |
33 ms |
56728 KB |
Output is correct |
12 |
Correct |
62 ms |
56744 KB |
Output is correct |
13 |
Correct |
203 ms |
100172 KB |
Output is correct |
14 |
Correct |
217 ms |
113936 KB |
Output is correct |
15 |
Execution timed out |
5087 ms |
832252 KB |
Time limit exceeded |
16 |
Halted |
0 ms |
0 KB |
- |