Submission #706540

# Submission time Handle Problem Language Result Execution time Memory
706540 2023-03-07T01:49:51 Z pcc Jail (JOI22_jail) C++14
0 / 100
10 ms 340 KB
#include <bits/stdc++.h>
using namespace std;

const int mxn =255;
int pre[mxn];
vector<int> tree[mxn];
vector<int> dir[mxn];
bitset<mxn> 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<mxn> 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 solve(){
    cin>>n;
    if(n>mxn)exit(0);
    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)exit(0);
    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();
    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 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Incorrect 10 ms 340 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 1 ms 340 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 1 ms 340 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 1 ms 340 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 1 ms 340 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Incorrect 1 ms 212 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Incorrect 10 ms 340 KB Output isn't correct
5 Halted 0 ms 0 KB -