# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
891078 |
2023-12-22T07:23:23 Z |
vjudge1 |
Jail (JOI22_jail) |
C++17 |
|
59 ms |
30392 KB |
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimize("Ofast,unroll-loops")
#define pii pair<int,int>
using namespace __gnu_pbds;
using namespace std;
#define pb push_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define int long long
#define f first
#define s second
#define pii pair<int,int>
template<class T>bool umax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<class T>bool umin(T &a,T b){if(b<a){a=b;return true;}return false;}
typedef tree<int, null_type, less_equal<int>, rb_tree_tag,
tree_order_statistics_node_update> ordered_set;
const int mod= 1e9 +7;
const int N=1e5*4;
int binpow (int a, int n) {
if (n == 0)
return 1;
if (n % 2 == 1)
return binpow (a, n-1) * a;
else {
int b = binpow (a, n/2);
return b * b;
}
}
vector<int>v[N],pred(N);
vector<int>col(N),vis(N);
void dfs(int x,int pr){
vis[x] = 1;
for(auto to:v[x]){
if(to==pr||col[to])continue;
dfs(to,x);
}
}
void solve(){
int n,m,k;
cin>>n;
for(int i = 1;i<=n;i++){
v[i].clear();
vis[i] = 0;
col[i] = 0;
}
for(int i = 1;i<n;i++){
int a,b;
cin>>a>>b;
v[a].pb(b);
v[b].pb(a);
}
cin>>m;
vector<pii>g;
for(int i = 0;i<m;i++){
int a,b;
cin>>a>>b;
g.pb({a,b});
}
if(m<=6){
vector<int>ind;
for(int i = 0;i<m;i++)ind.pb(i);
do
{
//~ cout<<1<<endl;
for(int i = 1;i<=n;i++)col[i] = 0;
for(auto to:g){
col[to.f] += 1;
}
//~ cout<<1<<endl;
bool flag = true;
for(auto to:ind){
//~ cout<<1<<endl;
int a = g[to].f;
int b = g[to].s;
//~ cout<<to<<endl;
col[a]--;
for(int i = 1;i<=n;i++)vis[i] = 0;
if(col[a]>=1){
//~ cout<<ind[0]<<"-\n";
flag = false;
break;
}
//~ if(ind[0]==2&&ind[1]==1)
//~ cout<<col[b]<<endl;
dfs(a,-1);
//~ cout<<to<<endl;
col[b] ++;
if(vis[b]==0){
//~ cout<<ind[0]<<"=\n";
flag = false;
break;
}
}
if(flag){
//~ for(auto to:ind)cout<<to<<" ";
cout<<"Yes\n";
return;
}
} while (next_permutation(all(ind)));
cout<<"No\n";
}
else{
sort(all(g));
set<int>st;
for(int i = m-1;i>=0;i--){
if(!st.empty()&&*st.begin()<g[i].s){
cout<<"No\n";
return;
}
st.insert(g[i].s);
}
cout<<"Yes\n";
}
}
signed main()
{
// freopen("seq.in", "r", stdin);
// freopen("seq.out", "w", stdout);
ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
int tt=1;cin>>tt;
while(tt--)solve();
}
Compilation message
jail.cpp: In function 'void solve()':
jail.cpp:47:11: warning: unused variable 'k' [-Wunused-variable]
47 | int n,m,k;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
19036 KB |
Output is correct |
2 |
Correct |
5 ms |
19188 KB |
Output is correct |
3 |
Correct |
5 ms |
19036 KB |
Output is correct |
4 |
Correct |
12 ms |
19268 KB |
Output is correct |
5 |
Correct |
19 ms |
19032 KB |
Output is correct |
6 |
Correct |
6 ms |
19036 KB |
Output is correct |
7 |
Correct |
15 ms |
19272 KB |
Output is correct |
8 |
Correct |
6 ms |
19036 KB |
Output is correct |
9 |
Correct |
20 ms |
19384 KB |
Output is correct |
10 |
Correct |
27 ms |
22876 KB |
Output is correct |
11 |
Correct |
12 ms |
19036 KB |
Output is correct |
12 |
Correct |
26 ms |
19288 KB |
Output is correct |
13 |
Correct |
40 ms |
25900 KB |
Output is correct |
14 |
Correct |
47 ms |
24012 KB |
Output is correct |
15 |
Correct |
36 ms |
23912 KB |
Output is correct |
16 |
Correct |
49 ms |
25072 KB |
Output is correct |
17 |
Correct |
42 ms |
26576 KB |
Output is correct |
18 |
Correct |
59 ms |
30392 KB |
Output is correct |
19 |
Correct |
42 ms |
26712 KB |
Output is correct |
20 |
Correct |
41 ms |
25812 KB |
Output is correct |
21 |
Correct |
40 ms |
24012 KB |
Output is correct |
22 |
Correct |
42 ms |
26748 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
19036 KB |
Output is correct |
2 |
Correct |
5 ms |
19036 KB |
Output is correct |
3 |
Correct |
7 ms |
19232 KB |
Output is correct |
4 |
Correct |
6 ms |
19036 KB |
Output is correct |
5 |
Correct |
7 ms |
19292 KB |
Output is correct |
6 |
Correct |
6 ms |
19292 KB |
Output is correct |
7 |
Correct |
6 ms |
19292 KB |
Output is correct |
8 |
Correct |
6 ms |
19292 KB |
Output is correct |
9 |
Correct |
6 ms |
19292 KB |
Output is correct |
10 |
Correct |
6 ms |
19320 KB |
Output is correct |
11 |
Correct |
6 ms |
19292 KB |
Output is correct |
12 |
Correct |
6 ms |
19036 KB |
Output is correct |
13 |
Correct |
6 ms |
19036 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
19036 KB |
Output is correct |
2 |
Correct |
5 ms |
19036 KB |
Output is correct |
3 |
Correct |
7 ms |
19232 KB |
Output is correct |
4 |
Correct |
6 ms |
19036 KB |
Output is correct |
5 |
Correct |
7 ms |
19292 KB |
Output is correct |
6 |
Correct |
6 ms |
19292 KB |
Output is correct |
7 |
Correct |
6 ms |
19292 KB |
Output is correct |
8 |
Correct |
6 ms |
19292 KB |
Output is correct |
9 |
Correct |
6 ms |
19292 KB |
Output is correct |
10 |
Correct |
6 ms |
19320 KB |
Output is correct |
11 |
Correct |
6 ms |
19292 KB |
Output is correct |
12 |
Correct |
6 ms |
19036 KB |
Output is correct |
13 |
Correct |
6 ms |
19036 KB |
Output is correct |
14 |
Correct |
5 ms |
19036 KB |
Output is correct |
15 |
Correct |
7 ms |
19292 KB |
Output is correct |
16 |
Correct |
15 ms |
19300 KB |
Output is correct |
17 |
Correct |
8 ms |
19292 KB |
Output is correct |
18 |
Correct |
19 ms |
19320 KB |
Output is correct |
19 |
Correct |
5 ms |
19036 KB |
Output is correct |
20 |
Correct |
16 ms |
19288 KB |
Output is correct |
21 |
Correct |
20 ms |
19288 KB |
Output is correct |
22 |
Correct |
14 ms |
19292 KB |
Output is correct |
23 |
Correct |
5 ms |
19036 KB |
Output is correct |
24 |
Correct |
6 ms |
19036 KB |
Output is correct |
25 |
Correct |
47 ms |
19292 KB |
Output is correct |
26 |
Correct |
10 ms |
19036 KB |
Output is correct |
27 |
Correct |
12 ms |
19292 KB |
Output is correct |
28 |
Correct |
10 ms |
19036 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
19036 KB |
Output is correct |
2 |
Correct |
5 ms |
19036 KB |
Output is correct |
3 |
Correct |
7 ms |
19232 KB |
Output is correct |
4 |
Correct |
6 ms |
19036 KB |
Output is correct |
5 |
Correct |
7 ms |
19292 KB |
Output is correct |
6 |
Correct |
6 ms |
19292 KB |
Output is correct |
7 |
Correct |
6 ms |
19292 KB |
Output is correct |
8 |
Correct |
6 ms |
19292 KB |
Output is correct |
9 |
Correct |
6 ms |
19292 KB |
Output is correct |
10 |
Correct |
6 ms |
19320 KB |
Output is correct |
11 |
Correct |
6 ms |
19292 KB |
Output is correct |
12 |
Correct |
6 ms |
19036 KB |
Output is correct |
13 |
Correct |
6 ms |
19036 KB |
Output is correct |
14 |
Correct |
5 ms |
19036 KB |
Output is correct |
15 |
Correct |
7 ms |
19292 KB |
Output is correct |
16 |
Correct |
15 ms |
19300 KB |
Output is correct |
17 |
Correct |
8 ms |
19292 KB |
Output is correct |
18 |
Correct |
19 ms |
19320 KB |
Output is correct |
19 |
Correct |
5 ms |
19036 KB |
Output is correct |
20 |
Correct |
16 ms |
19288 KB |
Output is correct |
21 |
Correct |
20 ms |
19288 KB |
Output is correct |
22 |
Correct |
14 ms |
19292 KB |
Output is correct |
23 |
Correct |
5 ms |
19036 KB |
Output is correct |
24 |
Correct |
6 ms |
19036 KB |
Output is correct |
25 |
Correct |
47 ms |
19292 KB |
Output is correct |
26 |
Correct |
10 ms |
19036 KB |
Output is correct |
27 |
Correct |
12 ms |
19292 KB |
Output is correct |
28 |
Correct |
10 ms |
19036 KB |
Output is correct |
29 |
Correct |
6 ms |
19280 KB |
Output is correct |
30 |
Incorrect |
6 ms |
19292 KB |
Output isn't correct |
31 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
19036 KB |
Output is correct |
2 |
Correct |
5 ms |
19036 KB |
Output is correct |
3 |
Correct |
7 ms |
19232 KB |
Output is correct |
4 |
Correct |
6 ms |
19036 KB |
Output is correct |
5 |
Correct |
7 ms |
19292 KB |
Output is correct |
6 |
Correct |
6 ms |
19292 KB |
Output is correct |
7 |
Correct |
6 ms |
19292 KB |
Output is correct |
8 |
Correct |
6 ms |
19292 KB |
Output is correct |
9 |
Correct |
6 ms |
19292 KB |
Output is correct |
10 |
Correct |
6 ms |
19320 KB |
Output is correct |
11 |
Correct |
6 ms |
19292 KB |
Output is correct |
12 |
Correct |
6 ms |
19036 KB |
Output is correct |
13 |
Correct |
6 ms |
19036 KB |
Output is correct |
14 |
Correct |
5 ms |
19036 KB |
Output is correct |
15 |
Correct |
7 ms |
19292 KB |
Output is correct |
16 |
Correct |
15 ms |
19300 KB |
Output is correct |
17 |
Correct |
8 ms |
19292 KB |
Output is correct |
18 |
Correct |
19 ms |
19320 KB |
Output is correct |
19 |
Correct |
5 ms |
19036 KB |
Output is correct |
20 |
Correct |
16 ms |
19288 KB |
Output is correct |
21 |
Correct |
20 ms |
19288 KB |
Output is correct |
22 |
Correct |
14 ms |
19292 KB |
Output is correct |
23 |
Correct |
5 ms |
19036 KB |
Output is correct |
24 |
Correct |
6 ms |
19036 KB |
Output is correct |
25 |
Correct |
47 ms |
19292 KB |
Output is correct |
26 |
Correct |
10 ms |
19036 KB |
Output is correct |
27 |
Correct |
12 ms |
19292 KB |
Output is correct |
28 |
Correct |
10 ms |
19036 KB |
Output is correct |
29 |
Correct |
6 ms |
19280 KB |
Output is correct |
30 |
Incorrect |
6 ms |
19292 KB |
Output isn't correct |
31 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
19036 KB |
Output is correct |
2 |
Correct |
5 ms |
19036 KB |
Output is correct |
3 |
Correct |
5 ms |
19036 KB |
Output is correct |
4 |
Correct |
6 ms |
19200 KB |
Output is correct |
5 |
Correct |
13 ms |
19268 KB |
Output is correct |
6 |
Correct |
6 ms |
19036 KB |
Output is correct |
7 |
Correct |
5 ms |
19036 KB |
Output is correct |
8 |
Correct |
6 ms |
19032 KB |
Output is correct |
9 |
Correct |
6 ms |
19036 KB |
Output is correct |
10 |
Correct |
6 ms |
19032 KB |
Output is correct |
11 |
Correct |
10 ms |
19032 KB |
Output is correct |
12 |
Incorrect |
6 ms |
19288 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
19036 KB |
Output is correct |
2 |
Correct |
5 ms |
19188 KB |
Output is correct |
3 |
Correct |
5 ms |
19036 KB |
Output is correct |
4 |
Correct |
12 ms |
19268 KB |
Output is correct |
5 |
Correct |
19 ms |
19032 KB |
Output is correct |
6 |
Correct |
6 ms |
19036 KB |
Output is correct |
7 |
Correct |
15 ms |
19272 KB |
Output is correct |
8 |
Correct |
6 ms |
19036 KB |
Output is correct |
9 |
Correct |
20 ms |
19384 KB |
Output is correct |
10 |
Correct |
27 ms |
22876 KB |
Output is correct |
11 |
Correct |
12 ms |
19036 KB |
Output is correct |
12 |
Correct |
26 ms |
19288 KB |
Output is correct |
13 |
Correct |
40 ms |
25900 KB |
Output is correct |
14 |
Correct |
47 ms |
24012 KB |
Output is correct |
15 |
Correct |
36 ms |
23912 KB |
Output is correct |
16 |
Correct |
49 ms |
25072 KB |
Output is correct |
17 |
Correct |
42 ms |
26576 KB |
Output is correct |
18 |
Correct |
59 ms |
30392 KB |
Output is correct |
19 |
Correct |
42 ms |
26712 KB |
Output is correct |
20 |
Correct |
41 ms |
25812 KB |
Output is correct |
21 |
Correct |
40 ms |
24012 KB |
Output is correct |
22 |
Correct |
42 ms |
26748 KB |
Output is correct |
23 |
Correct |
5 ms |
19036 KB |
Output is correct |
24 |
Correct |
5 ms |
19036 KB |
Output is correct |
25 |
Correct |
7 ms |
19232 KB |
Output is correct |
26 |
Correct |
6 ms |
19036 KB |
Output is correct |
27 |
Correct |
7 ms |
19292 KB |
Output is correct |
28 |
Correct |
6 ms |
19292 KB |
Output is correct |
29 |
Correct |
6 ms |
19292 KB |
Output is correct |
30 |
Correct |
6 ms |
19292 KB |
Output is correct |
31 |
Correct |
6 ms |
19292 KB |
Output is correct |
32 |
Correct |
6 ms |
19320 KB |
Output is correct |
33 |
Correct |
6 ms |
19292 KB |
Output is correct |
34 |
Correct |
6 ms |
19036 KB |
Output is correct |
35 |
Correct |
6 ms |
19036 KB |
Output is correct |
36 |
Correct |
5 ms |
19036 KB |
Output is correct |
37 |
Correct |
7 ms |
19292 KB |
Output is correct |
38 |
Correct |
15 ms |
19300 KB |
Output is correct |
39 |
Correct |
8 ms |
19292 KB |
Output is correct |
40 |
Correct |
19 ms |
19320 KB |
Output is correct |
41 |
Correct |
5 ms |
19036 KB |
Output is correct |
42 |
Correct |
16 ms |
19288 KB |
Output is correct |
43 |
Correct |
20 ms |
19288 KB |
Output is correct |
44 |
Correct |
14 ms |
19292 KB |
Output is correct |
45 |
Correct |
5 ms |
19036 KB |
Output is correct |
46 |
Correct |
6 ms |
19036 KB |
Output is correct |
47 |
Correct |
47 ms |
19292 KB |
Output is correct |
48 |
Correct |
10 ms |
19036 KB |
Output is correct |
49 |
Correct |
12 ms |
19292 KB |
Output is correct |
50 |
Correct |
10 ms |
19036 KB |
Output is correct |
51 |
Correct |
6 ms |
19280 KB |
Output is correct |
52 |
Incorrect |
6 ms |
19292 KB |
Output isn't correct |
53 |
Halted |
0 ms |
0 KB |
- |