Submission #706547

# Submission time Handle Problem Language Result Execution time Memory
706547 2023-03-07T01:58:20 Z pcc Jail (JOI22_jail) C++14
26 / 100
61 ms 9732 KB
#include <bits/stdc++.h>
using namespace std;

const int mxn =255;
const int mxn2 = 2e5+10;
int pre[mxn];
vector<int> tree[mxn2];
vector<int> dir[mxn];
bitset<255> used;
int m;
int n;

void dfs(int now,int par){
    pre[now] = par;
    for(auto nxt:tree[now]){
        if(nxt == par)continue;
        dfs(nxt,now);
    }
    return;
}
bool f(int arr[]){
    bitset<255> tmp;
    for(int i = 1;i<=n;i++)tmp[i] = used[i];
    bool flag = true;
    // for(int i = 0;i<m;i++)cout<<arr[i]<<',';cout<<endl;
    for(int i = 0;i<m;i++){
        int now = arr[i];
        for(auto &j:dir[now])if(j != dir[now].back()&&tmp[j])flag = false;
        tmp[dir[now].back()] = false;
        tmp[dir[now][0]] = true;
        // for(int j = 1;j<=n;j++)cout<<tmp[j];cout<<endl;
    }
    if(flag)return true;
    else return false;
}
void solve1(){
    pair<int,int> arr[m];
    for(auto &i:arr)cin>>i.first>>i.second;
    sort(arr,arr+m);
    int maxR = 0,minL = 0;
    bool flag = true;
    for(auto &i:arr){
        if(i.first>i.second){
            if(minL>i.second)flag = false;
            if(maxR>i.second)flag = false;
            minL = max(minL,i.second);
        }
        else{
            if(maxR>i.second)flag = false;
            maxR = max(maxR,i.second);
        }
    }
    for(int i = 0;i<=n;i++)tree[i].clear();
    if(flag)cout<<"Yes\n";
    else cout<<"No\n";
    return;
}
 

void solve(){
    cin>>n;
    for(int i = 0;i<n-1;i++){
        int a,b;
        cin>>a>>b;
        tree[a].push_back(b);
        tree[b].push_back(a);
    }
    cin>>m;
    if(m>6||n>250){
        solve1();
        return;
    }
    for(int i = 0;i<m;i++){
        int s,e;
        cin>>s>>e;
        used[s] = true;
        dfs(s,s);
        int tmp = e;
        dir[i].push_back(e);
        while(tmp != s){
            dir[i].push_back(tmp=pre[tmp]);
        }
        // for(int j = 1;j<=n;j++)cout<<pre[j]<<',';cout<<endl;
        // for(auto &j:dir[i])cout<<j<<',';cout<<endl;
    }
    int choice[m];
    for(int i = 0;i<m;i++)choice[i] = i;
    bool flag = false;
    if(f(choice))flag = true;
    while(next_permutation(choice,choice+m))if(f(choice))flag = true;
    if(flag)cout<<"Yes\n";
    else cout<<"No\n";
    for(int i = 0;i<=n;i++){
        tree[i].clear();
    }
    for(int i =0;i<m;i++)dir[i].clear();
    used.reset();
    return;
}

int main(){
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t;
    cin>>t;
    while(t--)solve();
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 11 ms 5032 KB Output is correct
5 Correct 22 ms 5036 KB Output is correct
6 Correct 3 ms 5036 KB Output is correct
7 Correct 26 ms 5044 KB Output is correct
8 Correct 4 ms 4948 KB Output is correct
9 Correct 25 ms 5204 KB Output is correct
10 Correct 33 ms 8736 KB Output is correct
11 Correct 20 ms 5032 KB Output is correct
12 Correct 30 ms 5028 KB Output is correct
13 Correct 35 ms 9124 KB Output is correct
14 Correct 42 ms 9144 KB Output is correct
15 Correct 39 ms 9152 KB Output is correct
16 Correct 61 ms 9580 KB Output is correct
17 Correct 41 ms 9160 KB Output is correct
18 Correct 44 ms 9732 KB Output is correct
19 Correct 37 ms 9164 KB Output is correct
20 Correct 37 ms 9236 KB Output is correct
21 Correct 43 ms 9148 KB Output is correct
22 Correct 37 ms 9220 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 4 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 4 ms 4948 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 4 ms 4948 KB Output is correct
8 Correct 4 ms 4948 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 3 ms 5036 KB Output is correct
12 Correct 3 ms 4948 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 4 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 4 ms 4948 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 4 ms 4948 KB Output is correct
8 Correct 4 ms 4948 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 3 ms 5036 KB Output is correct
12 Correct 3 ms 4948 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 3 ms 4948 KB Output is correct
15 Correct 3 ms 4932 KB Output is correct
16 Correct 23 ms 4948 KB Output is correct
17 Correct 9 ms 4948 KB Output is correct
18 Correct 21 ms 5040 KB Output is correct
19 Correct 3 ms 5024 KB Output is correct
20 Correct 18 ms 5040 KB Output is correct
21 Correct 19 ms 5032 KB Output is correct
22 Correct 17 ms 4948 KB Output is correct
23 Correct 4 ms 4948 KB Output is correct
24 Correct 4 ms 4948 KB Output is correct
25 Correct 21 ms 4976 KB Output is correct
26 Correct 7 ms 4948 KB Output is correct
27 Correct 16 ms 4948 KB Output is correct
28 Correct 5 ms 4948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 4 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 4 ms 4948 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 4 ms 4948 KB Output is correct
8 Correct 4 ms 4948 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 3 ms 5036 KB Output is correct
12 Correct 3 ms 4948 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 3 ms 4948 KB Output is correct
15 Correct 3 ms 4932 KB Output is correct
16 Correct 23 ms 4948 KB Output is correct
17 Correct 9 ms 4948 KB Output is correct
18 Correct 21 ms 5040 KB Output is correct
19 Correct 3 ms 5024 KB Output is correct
20 Correct 18 ms 5040 KB Output is correct
21 Correct 19 ms 5032 KB Output is correct
22 Correct 17 ms 4948 KB Output is correct
23 Correct 4 ms 4948 KB Output is correct
24 Correct 4 ms 4948 KB Output is correct
25 Correct 21 ms 4976 KB Output is correct
26 Correct 7 ms 4948 KB Output is correct
27 Correct 16 ms 4948 KB Output is correct
28 Correct 5 ms 4948 KB Output is correct
29 Correct 4 ms 4948 KB Output is correct
30 Incorrect 5 ms 4948 KB Output isn't correct
31 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 4 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 4 ms 4948 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 4 ms 4948 KB Output is correct
8 Correct 4 ms 4948 KB Output is correct
9 Correct 3 ms 4948 KB Output is correct
10 Correct 3 ms 4948 KB Output is correct
11 Correct 3 ms 5036 KB Output is correct
12 Correct 3 ms 4948 KB Output is correct
13 Correct 3 ms 4948 KB Output is correct
14 Correct 3 ms 4948 KB Output is correct
15 Correct 3 ms 4932 KB Output is correct
16 Correct 23 ms 4948 KB Output is correct
17 Correct 9 ms 4948 KB Output is correct
18 Correct 21 ms 5040 KB Output is correct
19 Correct 3 ms 5024 KB Output is correct
20 Correct 18 ms 5040 KB Output is correct
21 Correct 19 ms 5032 KB Output is correct
22 Correct 17 ms 4948 KB Output is correct
23 Correct 4 ms 4948 KB Output is correct
24 Correct 4 ms 4948 KB Output is correct
25 Correct 21 ms 4976 KB Output is correct
26 Correct 7 ms 4948 KB Output is correct
27 Correct 16 ms 4948 KB Output is correct
28 Correct 5 ms 4948 KB Output is correct
29 Correct 4 ms 4948 KB Output is correct
30 Incorrect 5 ms 4948 KB Output isn't correct
31 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 4 ms 4948 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 21 ms 5036 KB Output is correct
6 Correct 3 ms 4948 KB Output is correct
7 Correct 3 ms 4948 KB Output is correct
8 Correct 2 ms 4948 KB Output is correct
9 Correct 6 ms 4948 KB Output is correct
10 Correct 4 ms 4948 KB Output is correct
11 Correct 5 ms 5028 KB Output is correct
12 Incorrect 5 ms 4948 KB Output isn't correct
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Correct 3 ms 4948 KB Output is correct
4 Correct 11 ms 5032 KB Output is correct
5 Correct 22 ms 5036 KB Output is correct
6 Correct 3 ms 5036 KB Output is correct
7 Correct 26 ms 5044 KB Output is correct
8 Correct 4 ms 4948 KB Output is correct
9 Correct 25 ms 5204 KB Output is correct
10 Correct 33 ms 8736 KB Output is correct
11 Correct 20 ms 5032 KB Output is correct
12 Correct 30 ms 5028 KB Output is correct
13 Correct 35 ms 9124 KB Output is correct
14 Correct 42 ms 9144 KB Output is correct
15 Correct 39 ms 9152 KB Output is correct
16 Correct 61 ms 9580 KB Output is correct
17 Correct 41 ms 9160 KB Output is correct
18 Correct 44 ms 9732 KB Output is correct
19 Correct 37 ms 9164 KB Output is correct
20 Correct 37 ms 9236 KB Output is correct
21 Correct 43 ms 9148 KB Output is correct
22 Correct 37 ms 9220 KB Output is correct
23 Correct 3 ms 4948 KB Output is correct
24 Correct 4 ms 4948 KB Output is correct
25 Correct 3 ms 4948 KB Output is correct
26 Correct 3 ms 4948 KB Output is correct
27 Correct 4 ms 4948 KB Output is correct
28 Correct 3 ms 4948 KB Output is correct
29 Correct 4 ms 4948 KB Output is correct
30 Correct 4 ms 4948 KB Output is correct
31 Correct 3 ms 4948 KB Output is correct
32 Correct 3 ms 4948 KB Output is correct
33 Correct 3 ms 5036 KB Output is correct
34 Correct 3 ms 4948 KB Output is correct
35 Correct 3 ms 4948 KB Output is correct
36 Correct 3 ms 4948 KB Output is correct
37 Correct 3 ms 4932 KB Output is correct
38 Correct 23 ms 4948 KB Output is correct
39 Correct 9 ms 4948 KB Output is correct
40 Correct 21 ms 5040 KB Output is correct
41 Correct 3 ms 5024 KB Output is correct
42 Correct 18 ms 5040 KB Output is correct
43 Correct 19 ms 5032 KB Output is correct
44 Correct 17 ms 4948 KB Output is correct
45 Correct 4 ms 4948 KB Output is correct
46 Correct 4 ms 4948 KB Output is correct
47 Correct 21 ms 4976 KB Output is correct
48 Correct 7 ms 4948 KB Output is correct
49 Correct 16 ms 4948 KB Output is correct
50 Correct 5 ms 4948 KB Output is correct
51 Correct 4 ms 4948 KB Output is correct
52 Incorrect 5 ms 4948 KB Output isn't correct
53 Halted 0 ms 0 KB -