Submission #875741

# Submission time Handle Problem Language Result Execution time Memory
875741 2023-11-20T12:22:24 Z dimashhh Jail (JOI22_jail) C++17
0 / 100
14 ms 20060 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5 + 10, MOD = 998244353;

vector<int> g[N], x[N], gt[N];
int timer = 0, tin[N], tout[N], n, m, s[N], t[N], pp[N], val[N], used[N];
void dfs(int v, int pr = 1)
{
    tin[v] = ++timer;
    pp[v] = pr;
    for (int to : g[v])
    {
        if (to == pr)
            continue;
        dfs(to, v);
    }
    tout[v] = ++timer;
}
bool is(int v, int u)
{
    return (tin[v] <= tin[u] && tout[v] >= tout[u]);
}
vector<int> path(int v,int u){
    vector<int> p(1,v);
    while(!is(v,u)){
        v = pp[v];
        p.push_back(v);
    }
    while(!is(u,v)){
        p.push_back(u);
        u = pp[u];
    }
    return p;
}
bool res = 1;
void dfs1(int v){
    used[v] = 1;
    for(int to:gt[v]){
        if(used[to] == 1){
            // cout << v << ' ' << to << '\n';
            res =0 ;
        }
        if(!used[to]){
            dfs1(to);
        }
    }
    used[v] = 2;
}
void test()
{
    res = 1;
    timer = 0;
    cin >> n;
    for (int i = 1; i <= n; i++)
        g[i].clear();
    for (int i = 1; i <= n - 1; i++)
    {
        int x, y;
        cin >> x >> y;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    dfs(1);
    cin >> m;
    for(int i = 1;i <= m;i++){
        val[i] = 0;
    }
    for (int i = 1; i <= m; ++i)
    {
        cin >> s[i] >> t[i];
        gt[i].clear();
        used[i] = 0;
        val[s[i]] = i;
    }
    for(int i = 1;i <= m;i++){
        for(int j:path(s[i],t[i])){
            int x = val[j];
            if(x && x != i){
                gt[x].push_back(i);
                // cout << x << ' ' << i << '\n';
            }
        }
    }
    for(int i = 1;i <= m;i++){
        if(!used[i] && res){
            dfs1(i);
        }
    }
    cout << (res ? "Yes\n" : "No\n");
}
main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int T = 1;
    cin >> T;
    for (int i = 1; i <= T; i++)
    {
        test();
    }
}

Compilation message

jail.cpp:92:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   92 | main()
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 19804 KB Output is correct
2 Correct 4 ms 19808 KB Output is correct
3 Correct 4 ms 19804 KB Output is correct
4 Incorrect 14 ms 20060 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 19804 KB Output is correct
2 Correct 5 ms 19804 KB Output is correct
3 Incorrect 6 ms 19832 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 19804 KB Output is correct
2 Correct 5 ms 19804 KB Output is correct
3 Incorrect 6 ms 19832 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 19804 KB Output is correct
2 Correct 5 ms 19804 KB Output is correct
3 Incorrect 6 ms 19832 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 19804 KB Output is correct
2 Correct 5 ms 19804 KB Output is correct
3 Incorrect 6 ms 19832 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 19804 KB Output is correct
2 Correct 4 ms 19804 KB Output is correct
3 Correct 4 ms 19848 KB Output is correct
4 Correct 4 ms 19804 KB Output is correct
5 Incorrect 8 ms 19800 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 19804 KB Output is correct
2 Correct 4 ms 19808 KB Output is correct
3 Correct 4 ms 19804 KB Output is correct
4 Incorrect 14 ms 20060 KB Output isn't correct
5 Halted 0 ms 0 KB -