# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
572149 |
2022-06-03T19:12:04 Z |
MohammadAghil |
Jail (JOI22_jail) |
C++14 |
|
7 ms |
12080 KB |
#include <bits/stdc++.h>
// #pragma GCC optimize ("Ofast,unroll-loops")
// #pragma GCC target ("avx2")
using namespace std;
typedef long long ll;
typedef pair<int, int> pp;
#define er(args ...) cerr << __LINE__ << ": ", err(new istringstream(string(#args)), args), cerr << endl
#define per(i,r,l) for(int i = (r); i >= (l); i--)
#define rep(i,l,r) for(int i = (l); i < (r); i++)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define pb push_back
#define ss second
#define ff first
void err(istringstream *iss){}template<typename T,typename ...Args> void err(istringstream *iss,const T &_val, const Args&...args){string _name;*iss>>_name;if(_name.back()==',')_name.pop_back();cerr<<_name<<" = "<<_val<<", ",err(iss,args...);}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll mod = 1e9 + 7, maxn = 5e5 + 5, lg = 22, inf = ll(1e9) + 5;
ll pw(ll a,ll b,ll md=mod){if(!b)return 1;ll k=pw(a,b>>1ll);return k*k%md*(b&1ll?a:1)%md;}
vector<int> adj[maxn];
bool is[maxn];
bool dfs(int r, int g, int p = -1, int cr = 0){
cr += is[r];
if(r == g) return cr <= 1;
for(int c: adj[r]) if(c - p && !dfs(c, g, r, cr)) return false;
return true;
}
void solve(){
int n; cin >> n;
rep(i,0,n) adj[i].clear();
rep(i,1,n) {
int u, v; cin >> u >> v; u--, v--;
adj[u].pb(v), adj[v].pb(u);
}
int m; cin >> m;
vector<int> s(m), t(m);
rep(i,0,m) cin >> s[i] >> t[i];
vector<int> id(m); iota(all(id), 0);
do{
fill(is, is + n, false);
rep(i,0,m) is[s[i]] = true;
bool ok = true;
rep(i,0,m){
if(!dfs(s[id[i]], t[id[i]])){
ok = false;
break;
}
is[s[id[i]]] = false, is[t[id[i]]] = true;
}
if(ok){
cout << "Yes\n";
return;
}
}while(next_permutation(all(id)));
cout << "No\n";
}
int main(){
cin.tie(0) -> sync_with_stdio(0);
int t; cin >> t;
while(t--) solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
11988 KB |
Output is correct |
2 |
Correct |
6 ms |
12072 KB |
Output is correct |
3 |
Incorrect |
7 ms |
12036 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
11988 KB |
Output is correct |
2 |
Incorrect |
6 ms |
11988 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
11988 KB |
Output is correct |
2 |
Incorrect |
6 ms |
11988 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
11988 KB |
Output is correct |
2 |
Incorrect |
6 ms |
11988 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
11988 KB |
Output is correct |
2 |
Incorrect |
6 ms |
11988 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
12080 KB |
Output is correct |
2 |
Correct |
5 ms |
12068 KB |
Output is correct |
3 |
Correct |
6 ms |
11988 KB |
Output is correct |
4 |
Incorrect |
7 ms |
12076 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
11988 KB |
Output is correct |
2 |
Correct |
6 ms |
12072 KB |
Output is correct |
3 |
Incorrect |
7 ms |
12036 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |