# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
878014 |
2023-11-24T02:30:06 Z |
Regulus |
Jail (JOI22_jail) |
C++17 |
|
5000 ms |
18772 KB |
#include <bits/stdc++.h> // pA
#define IO ios::sync_with_stdio(false);cin.tie(0);
#define debug(x) cerr << #x << " = " << (x) << ' '
#define endl cerr << '\n'
#define all(v) (v).begin(), (v).end()
#define SZ(v) (ll)(v).size()
#define lowbit(x) (x)&-(x)
#define pb emplace_back
#define F first
#define S second
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
const int N = 2e5+5;
//const int INF = 2e9;
int s[N], t[N], tin[2][N], timer, tout[2][N];
vector<int> g[N];
inline void dfs(int x, int pre, int lev)
{
tin[lev][x] = ++timer;
for (int v : g[x]) if (v != pre) dfs(v, x, lev);
tout[lev][x] = ++timer;
}
inline bool is_anc(int x, int y, int lev)
{ return tin[lev][x] <= tin[lev][y] && tout[lev][y] <= tout[lev][x]; }
int main(void)
{ IO
ll T, n, i, m, x, y, j;
bool bad;
cin >> T;
do {
cin >> n;
for (i=1; i <= n; ++i) g[i].clear();
for (i=0; i < n-1; ++i) cin >> x >> y, g[x].pb(y), g[y].pb(x);
cin >> m;
for (i=1; i <= m; ++i) cin >> s[i] >> t[i];
bad = 0;
for (i=1; i <= m; ++i)
{
for (int dd=0; dd < 2; ++dd)
for (j=1; j <= n; ++j) tin[dd][j] = tout[dd][j] = 0;
timer = 0;
dfs(s[i], 0, 0), dfs(t[i], 0, 1);
for (j=1; j <= m; ++j)
{
if (i == j) continue;
if (is_anc(t[j], t[i], 0) && is_anc(t[i], s[j], 0)) bad = 1;
if (is_anc(s[j], s[i], 1) && is_anc(s[i], t[j], 1)) bad = 1;
if (is_anc(s[j], t[i], 0) && is_anc(t[j], t[i], 0)) bad = 1;
}
if (bad) break;
}
if (bad) cout << "No\n";
else cout << "Yes\n";
} while (--T);
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
8796 KB |
Output is correct |
2 |
Correct |
2 ms |
8796 KB |
Output is correct |
3 |
Correct |
1 ms |
8792 KB |
Output is correct |
4 |
Correct |
8 ms |
8796 KB |
Output is correct |
5 |
Correct |
15 ms |
9368 KB |
Output is correct |
6 |
Correct |
2 ms |
8796 KB |
Output is correct |
7 |
Correct |
2 ms |
8904 KB |
Output is correct |
8 |
Correct |
5 ms |
8864 KB |
Output is correct |
9 |
Correct |
341 ms |
10364 KB |
Output is correct |
10 |
Correct |
948 ms |
18200 KB |
Output is correct |
11 |
Correct |
5 ms |
8792 KB |
Output is correct |
12 |
Correct |
36 ms |
9716 KB |
Output is correct |
13 |
Execution timed out |
5047 ms |
18772 KB |
Time limit exceeded |
14 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
8792 KB |
Output is correct |
2 |
Correct |
2 ms |
8796 KB |
Output is correct |
3 |
Correct |
2 ms |
8796 KB |
Output is correct |
4 |
Correct |
2 ms |
8864 KB |
Output is correct |
5 |
Correct |
3 ms |
8948 KB |
Output is correct |
6 |
Correct |
3 ms |
8796 KB |
Output is correct |
7 |
Correct |
2 ms |
8796 KB |
Output is correct |
8 |
Correct |
2 ms |
8796 KB |
Output is correct |
9 |
Correct |
2 ms |
8796 KB |
Output is correct |
10 |
Correct |
3 ms |
9112 KB |
Output is correct |
11 |
Correct |
2 ms |
8796 KB |
Output is correct |
12 |
Correct |
2 ms |
8796 KB |
Output is correct |
13 |
Correct |
2 ms |
8796 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
8792 KB |
Output is correct |
2 |
Correct |
2 ms |
8796 KB |
Output is correct |
3 |
Correct |
2 ms |
8796 KB |
Output is correct |
4 |
Correct |
2 ms |
8864 KB |
Output is correct |
5 |
Correct |
3 ms |
8948 KB |
Output is correct |
6 |
Correct |
3 ms |
8796 KB |
Output is correct |
7 |
Correct |
2 ms |
8796 KB |
Output is correct |
8 |
Correct |
2 ms |
8796 KB |
Output is correct |
9 |
Correct |
2 ms |
8796 KB |
Output is correct |
10 |
Correct |
3 ms |
9112 KB |
Output is correct |
11 |
Correct |
2 ms |
8796 KB |
Output is correct |
12 |
Correct |
2 ms |
8796 KB |
Output is correct |
13 |
Correct |
2 ms |
8796 KB |
Output is correct |
14 |
Incorrect |
2 ms |
8796 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
8792 KB |
Output is correct |
2 |
Correct |
2 ms |
8796 KB |
Output is correct |
3 |
Correct |
2 ms |
8796 KB |
Output is correct |
4 |
Correct |
2 ms |
8864 KB |
Output is correct |
5 |
Correct |
3 ms |
8948 KB |
Output is correct |
6 |
Correct |
3 ms |
8796 KB |
Output is correct |
7 |
Correct |
2 ms |
8796 KB |
Output is correct |
8 |
Correct |
2 ms |
8796 KB |
Output is correct |
9 |
Correct |
2 ms |
8796 KB |
Output is correct |
10 |
Correct |
3 ms |
9112 KB |
Output is correct |
11 |
Correct |
2 ms |
8796 KB |
Output is correct |
12 |
Correct |
2 ms |
8796 KB |
Output is correct |
13 |
Correct |
2 ms |
8796 KB |
Output is correct |
14 |
Incorrect |
2 ms |
8796 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
8792 KB |
Output is correct |
2 |
Correct |
2 ms |
8796 KB |
Output is correct |
3 |
Correct |
2 ms |
8796 KB |
Output is correct |
4 |
Correct |
2 ms |
8864 KB |
Output is correct |
5 |
Correct |
3 ms |
8948 KB |
Output is correct |
6 |
Correct |
3 ms |
8796 KB |
Output is correct |
7 |
Correct |
2 ms |
8796 KB |
Output is correct |
8 |
Correct |
2 ms |
8796 KB |
Output is correct |
9 |
Correct |
2 ms |
8796 KB |
Output is correct |
10 |
Correct |
3 ms |
9112 KB |
Output is correct |
11 |
Correct |
2 ms |
8796 KB |
Output is correct |
12 |
Correct |
2 ms |
8796 KB |
Output is correct |
13 |
Correct |
2 ms |
8796 KB |
Output is correct |
14 |
Incorrect |
2 ms |
8796 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
8796 KB |
Output is correct |
2 |
Incorrect |
1 ms |
8796 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
8796 KB |
Output is correct |
2 |
Correct |
2 ms |
8796 KB |
Output is correct |
3 |
Correct |
1 ms |
8792 KB |
Output is correct |
4 |
Correct |
8 ms |
8796 KB |
Output is correct |
5 |
Correct |
15 ms |
9368 KB |
Output is correct |
6 |
Correct |
2 ms |
8796 KB |
Output is correct |
7 |
Correct |
2 ms |
8904 KB |
Output is correct |
8 |
Correct |
5 ms |
8864 KB |
Output is correct |
9 |
Correct |
341 ms |
10364 KB |
Output is correct |
10 |
Correct |
948 ms |
18200 KB |
Output is correct |
11 |
Correct |
5 ms |
8792 KB |
Output is correct |
12 |
Correct |
36 ms |
9716 KB |
Output is correct |
13 |
Execution timed out |
5047 ms |
18772 KB |
Time limit exceeded |
14 |
Halted |
0 ms |
0 KB |
- |