Submission #876808

# Submission time Handle Problem Language Result Execution time Memory
876808 2023-11-22T11:15:58 Z Ivkosqn Jail (JOI22_jail) C++14
0 / 100
2 ms 6748 KB
#include <bits/stdc++.h>
#define endl '\n'

using namespace std;

const int maxn = 120010;
int n, m, s[maxn], f[maxn], used[maxn], bef[maxn], p[maxn];
vector<int> v[maxn], paths[maxn];

void dfs(int ver){
    used[ver] = 1;
    for(int nb : v[ver]){
        if(used[nb])
            continue;
        bef[nb] = ver;
        dfs(nb);
    }
}

void read(){
    cin >> n;
    for(int i = 1;i <= n;i++)
        v[i].clear();
    for(int i = 1;i <= n - 1;i++){
        int x, y;
        cin >> x >> y;
        v[x].push_back(y);
        v[y].push_back(x);
    }
    cin >> m;
    for(int i = 1;i <= m;i++){
        cin >> s[i] >> f[i];
        for(int j = 1;j <= n;j++)
            used[j] = 0;
        dfs(s[i]);
        int x = f[i];
        paths[i].clear();
        paths[i].push_back(x);
        while(x != s[i]){
            x = bef[x];
            paths[i].push_back(x);
        }
        reverse(paths[i].begin(), paths[i].end());
    }
}

void solve(){
    read();
    for(int i = 0;i < n;i++){
        bool flag = false;
        for(int k = 1;k <= m;k++){
            if(paths[k].size() > i){
                p[paths[k][i]]++;
                if(p[paths[k][i]] > 1)
                    flag = true;
            }
        }        
        for(int k = 1;k <= m;k++){
            if(paths[k].size() > i)
            p[paths[k][i]] = 0;
        }
        if(flag){
            cout << "No\n";
            return;
        }

    }
    cout << "Yes\n";
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t;
    cin >> t;
    while(t--){
        solve();
    }
    return 0;
}

Compilation message

jail.cpp: In function 'void solve()':
jail.cpp:52:32: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   52 |             if(paths[k].size() > i){
      |                ~~~~~~~~~~~~~~~~^~~
jail.cpp:59:32: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   59 |             if(paths[k].size() > i)
      |                ~~~~~~~~~~~~~~~~^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6748 KB Output is correct
2 Correct 2 ms 6748 KB Output is correct
3 Incorrect 1 ms 6748 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6748 KB Output is correct
2 Incorrect 1 ms 6748 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6748 KB Output is correct
2 Incorrect 1 ms 6748 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6748 KB Output is correct
2 Incorrect 1 ms 6748 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6748 KB Output is correct
2 Incorrect 1 ms 6748 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6748 KB Output is correct
2 Correct 1 ms 6584 KB Output is correct
3 Correct 1 ms 6748 KB Output is correct
4 Incorrect 1 ms 6748 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6748 KB Output is correct
2 Correct 2 ms 6748 KB Output is correct
3 Incorrect 1 ms 6748 KB Output isn't correct
4 Halted 0 ms 0 KB -