# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
721111 |
2023-04-10T10:17:40 Z |
saayan007 |
Jail (JOI22_jail) |
C++17 |
|
10 ms |
3520 KB |
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define fr first
#define sc second
#define eb emplace_back
#define nl "\n"
/* const int logn = 20; */
/* int anc[N][logn + 1], depth[N]; */
/* void dfs(int cur = 1, int par = 0) { */
/* depth[cur] = depth[par] + 1; */
/* anc[cur][0] = par; */
/* for(auto u : adj[cur]) { */
/* if(u == par) continue; */
/* dfs(u, cur); */
/* } */
/* } */
/* void precompute() { */
/* dfs(); */
/* for(int i = 1; i <= logn; ++i) { */
/* for(int j = 1; j <= n; ++j) { */
/* if(depth[j] <= (1LL << i)) */
/* anc[i][j] = 0; */
/* else */
/* anc[i][j] = anc[anc[i][j - 1]][j - 1]; */
/* } */
/* } */
/* } */
/* int lca(int a, int b) { */
/* if(a == b) return a; */
/* if(depth[a] > depth[b]) swap(a, b); */
/* for(int j = logn; j >= 0; --j) { */
/* if(anc[b][j] != 0 && depth[anc[b][j]] >= depth[a]) */
/* b = anc[b][j]; */
/* } */
/* if(a == b) return a; */
/* for(int j = logn; j >= 0; --j) { */
/* if(anc[a][j] != 0 && and[a][j] != anc[b][j]) { */
/* a = anc[a][j]; */
/* b = anc[b][j]; */
/* } */
/* } */
/* return anc[a][0]; */
/* } */
/* void mod(int a, int b) { */
/* int l = lca(a, b); */
/* } */
const int N = 120001;
int n, m;
vector<int> adj[N];
int s[N], t[N];
int from[N];
int use[N];
void dfs(int cur, int par) {
from[cur] = par;
for(auto u : adj[cur]) {
if(u != par)
dfs(u, cur);
}
}
void mod(int a, int b, int v = 1) {
dfs(a, 0);
while(b != 0) {
use[b] += v;
b = from[b];
}
}
void solve() {
cin >> n;
for(int i = 1; i <= n; ++i) {
use[i] = 0;
adj[i].clear();
}
for(int i = 1; i < n; ++i) {
int a, b; cin >> a >> b;
adj[a].eb(b); adj[b].eb(a);
}
cin >> m;
for(int i = 1; i <= m; ++i) {
cin >> s[i] >> t[i];
}
for(int i = 1; i <= m; ++i) {
mod(s[i], t[i]);
}
set<pair<int, int>> st;
for(int i = 1; i <= m; ++i) {
st.insert({use[t[i]], i});
}
while(!st.empty()) {
int a = (*st.begin()).sc;
if(use[t[a]] > 1) {
cout << "No" << nl;
return;
}
mod(s[a], t[a], -1);
st.erase(st.begin());
}
cout << "Yes" << nl;
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
int t = 1;
cin >> t;
for(int i = 1; i <= t; ++i) {
/* cout << "Case #" << i << nl; */
solve();
/* cout << nl; */
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3156 KB |
Output is correct |
2 |
Correct |
2 ms |
3152 KB |
Output is correct |
3 |
Correct |
2 ms |
3156 KB |
Output is correct |
4 |
Incorrect |
10 ms |
3520 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3156 KB |
Output is correct |
2 |
Correct |
2 ms |
3156 KB |
Output is correct |
3 |
Incorrect |
2 ms |
3156 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3156 KB |
Output is correct |
2 |
Correct |
2 ms |
3156 KB |
Output is correct |
3 |
Incorrect |
2 ms |
3156 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3156 KB |
Output is correct |
2 |
Correct |
2 ms |
3156 KB |
Output is correct |
3 |
Incorrect |
2 ms |
3156 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3156 KB |
Output is correct |
2 |
Correct |
2 ms |
3156 KB |
Output is correct |
3 |
Incorrect |
2 ms |
3156 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3156 KB |
Output is correct |
2 |
Correct |
2 ms |
3156 KB |
Output is correct |
3 |
Correct |
2 ms |
3148 KB |
Output is correct |
4 |
Correct |
3 ms |
3156 KB |
Output is correct |
5 |
Incorrect |
10 ms |
3312 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3156 KB |
Output is correct |
2 |
Correct |
2 ms |
3152 KB |
Output is correct |
3 |
Correct |
2 ms |
3156 KB |
Output is correct |
4 |
Incorrect |
10 ms |
3520 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |