# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
727029 |
2023-04-19T20:42:55 Z |
dozer |
Jail (JOI22_jail) |
C++14 |
|
13 ms |
10124 KB |
#include <bits/stdc++.h>
using namespace std;
#define fastio() cin.tie(0), ios_base::sync_with_stdio(0)
#define sp " "
#define endl "\n"
#define pb push_back
#define pii pair<int, int>
#define st first
#define nd second
#define N 200005
#define LOGN 18
vector<int> adj[N], adj2[N];
int tin[N], tout[N], s[N], t[N], par[LOGN][N];
int cntr, dep[N], deg[N], ind[N];
void dfs(int node, int root, int d)
{
tin[node] = cntr++;
dep[node] = d;
par[0][node] = root;
for (auto i : adj[node])
if (i != root) dfs(i, node, d + 1);
tout[node] = cntr++;
}
bool ancestor(int a, int b)
{
return (tin[a] <= tin[b] && tout[a] >= tout[b]);
}
int lca(int a, int b)
{
for (int i = LOGN - 1; i >= 0; i--)
{
if ((1<<i) < dep[a] && !ancestor(par[i][a], b)) a = par[i][a];
}
if (!ancestor(a, b)) a = par[0][a];
return a;
}
bool intersects(int x, int a, int b)
{
int l = lca(a, b);
if (x == l) return 1;
return (ancestor(x, a) ^ ancestor(x, b));
}
int32_t main()
{
fastio();
int q;
cin>>q;
while(q--)
{
int n, m;
cin>>n;
for (int i = 1; i <= n; i++)
adj[i].clear();
for (int i = 1; i < n; i++)
{
int u, v;
cin>>u>>v;
adj[u].pb(v);
adj[v].pb(u);
}
cntr = 0;
dfs(1, 0, 0);
for (int i = 1; i < LOGN; i++)
{
for (int j = 1; j <= n; j++)
par[i][j] = par[i - 1][par[i - 1][j]];
}
vector<pii> v;
cin>>m;
for (int i = 1; i <= m; i++)
adj2[i].clear(), deg[i] = 0;
for (int i = 1; i <= m; i++)
{
cin>>s[i]>>t[i];
ind[s[i]] = i;
}
int flag = 0;
for (int i = 1; i <= m; i++)
{
for (int j = i + 1; j <= m; j++)
{
int a = 0, b = 0;
if (intersects(s[i], s[j], t[j]) || intersects(t[j], s[i], t[i])) a = 1;
if (intersects(t[i], s[j], t[j]) || intersects(s[j], s[i], t[i])) b = 1;
if (a && b) flag = 1;
}
}
for (int i = 1; i <= m; i++)
{
int to = ind[t[i]];
if (to != 0)
{
deg[i]++;
adj2[to].pb(i);
}
}
vector<int> done(m + 5, 0);
queue<int> q;
for (int i = 1; i <= m; i++)
if (deg[i] == 0) q.push(i);
while(!q.empty())
{
int top = q.front();
q.pop();
done[top] = 1;
for (auto i : adj2[top])
{
deg[i]--;
if (deg[i] == 0) q.push(i);
}
}
for (int i = 1; i <= m; i++)
flag |= 1 ^ done[i];
if (flag) cout<<"No\n";
else cout<<"Yes\n";
}
cerr<<"time taken : "<<(float)clock() / CLOCKS_PER_SEC<<" seconds\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9812 KB |
Output is correct |
2 |
Correct |
5 ms |
9812 KB |
Output is correct |
3 |
Correct |
5 ms |
9812 KB |
Output is correct |
4 |
Incorrect |
13 ms |
10124 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
9796 KB |
Output is correct |
2 |
Correct |
6 ms |
9812 KB |
Output is correct |
3 |
Incorrect |
6 ms |
9928 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
9796 KB |
Output is correct |
2 |
Correct |
6 ms |
9812 KB |
Output is correct |
3 |
Incorrect |
6 ms |
9928 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
9796 KB |
Output is correct |
2 |
Correct |
6 ms |
9812 KB |
Output is correct |
3 |
Incorrect |
6 ms |
9928 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
9796 KB |
Output is correct |
2 |
Correct |
6 ms |
9812 KB |
Output is correct |
3 |
Incorrect |
6 ms |
9928 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9812 KB |
Output is correct |
2 |
Correct |
6 ms |
9852 KB |
Output is correct |
3 |
Correct |
6 ms |
9812 KB |
Output is correct |
4 |
Correct |
5 ms |
9812 KB |
Output is correct |
5 |
Incorrect |
12 ms |
9940 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9812 KB |
Output is correct |
2 |
Correct |
5 ms |
9812 KB |
Output is correct |
3 |
Correct |
5 ms |
9812 KB |
Output is correct |
4 |
Incorrect |
13 ms |
10124 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |