# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
890776 |
2023-12-22T02:56:04 Z |
vjudge1 |
Jail (JOI22_jail) |
C++17 |
|
5000 ms |
1116 KB |
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(), x.end()
#define ar array
#define pb push_back
#define ln '\n'
#define int long long
using i64 = long long;
template <class F, class _S>
bool chmin(F &u, const _S &v){
bool flag = false;
if ( u > v ){
u = v; flag |= true;
}
return flag;
}
template <class F, class _S>
bool chmax(F &u, const _S &v){
bool flag = false;
if ( u < v ){
u = v; flag |= true;
}
return flag;
}
void solve(){
int n; cin >> n;
vector <vector<int>> G(n);
for ( int i = 0; i + 1 < n; i++ ){
int u, v; cin >> u >> v;
--u, --v;
G[u].pb(v), G[v].pb(u);
}
int m; cin >> m;
vector <int> S(m), T(m);
for ( int i = 0; i < m; i++ ){
cin >> S[i] >> T[i];
--S[i], --T[i];
}
vector <int> tmp;
auto dfs = [&](auto dfs, int u, int p, int des) -> bool{
if ( u == des ){
return true;
}
for ( auto &v: G[u] ){
if ( v != p ){
if ( dfs(dfs, v, u, des) ){
tmp.pb(u);
return true;
}
}
}
return false;
};
vector <vector<int>> lst(m);
for ( int i = 0; i < m; i++ ){
tmp.clear();
dfs(dfs, S[i], -1, T[i]);
reverse(all(tmp));
tmp.pb(T[i]);
lst[i] = tmp;
}
vector <int> p(m);
iota(all(p), 0);
do{
vector <int> us(n);
for ( int i = 0; i < m; i++ ){
us[S[i]] = true;
}
bool good = true;
for ( int i = 0; i < m; i++ ){
auto &tmp = lst[p[i]];
int pre = S[p[i]];
for ( int j = 1; j < tmp.size(); j++ ){
if ( us[tmp[j]] ){
good = false;
} us[pre] = false;
us[pre = tmp[j]] = true;
}
}
if ( good ){
cout << "Yes\n";
return;
}
} while ( next_permutation(all(p)) );
cout << "No\n";
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int t; cin >> t;
while ( t-- ){
solve();
}
cout << '\n';
}
Compilation message
jail.cpp: In function 'void solve()':
jail.cpp:79:32: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
79 | for ( int j = 1; j < tmp.size(); j++ ){
| ~~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
452 KB |
Output is correct |
4 |
Correct |
10 ms |
848 KB |
Output is correct |
5 |
Correct |
22 ms |
1116 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
7 ms |
348 KB |
Output is correct |
8 |
Execution timed out |
5054 ms |
348 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
516 KB |
Output is correct |
4 |
Correct |
2 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
472 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
516 KB |
Output is correct |
9 |
Correct |
2 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
516 KB |
Output is correct |
4 |
Correct |
2 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
472 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
516 KB |
Output is correct |
9 |
Correct |
2 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
7 ms |
468 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
5 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
4 ms |
520 KB |
Output is correct |
21 |
Correct |
2 ms |
344 KB |
Output is correct |
22 |
Correct |
3 ms |
388 KB |
Output is correct |
23 |
Correct |
1 ms |
344 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
6 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
2 ms |
348 KB |
Output is correct |
28 |
Correct |
2 ms |
456 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
516 KB |
Output is correct |
4 |
Correct |
2 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
472 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
516 KB |
Output is correct |
9 |
Correct |
2 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
7 ms |
468 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
5 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
4 ms |
520 KB |
Output is correct |
21 |
Correct |
2 ms |
344 KB |
Output is correct |
22 |
Correct |
3 ms |
388 KB |
Output is correct |
23 |
Correct |
1 ms |
344 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
6 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
2 ms |
348 KB |
Output is correct |
28 |
Correct |
2 ms |
456 KB |
Output is correct |
29 |
Execution timed out |
5005 ms |
344 KB |
Time limit exceeded |
30 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
516 KB |
Output is correct |
4 |
Correct |
2 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
472 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
516 KB |
Output is correct |
9 |
Correct |
2 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
7 ms |
468 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
5 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
4 ms |
520 KB |
Output is correct |
21 |
Correct |
2 ms |
344 KB |
Output is correct |
22 |
Correct |
3 ms |
388 KB |
Output is correct |
23 |
Correct |
1 ms |
344 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
6 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
2 ms |
348 KB |
Output is correct |
28 |
Correct |
2 ms |
456 KB |
Output is correct |
29 |
Execution timed out |
5005 ms |
344 KB |
Time limit exceeded |
30 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Execution timed out |
5093 ms |
580 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
452 KB |
Output is correct |
4 |
Correct |
10 ms |
848 KB |
Output is correct |
5 |
Correct |
22 ms |
1116 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
7 ms |
348 KB |
Output is correct |
8 |
Execution timed out |
5054 ms |
348 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |