Submission #994265

# Submission time Handle Problem Language Result Execution time Memory
994265 2024-06-07T10:07:57 Z vjudge1 Jail (JOI22_jail) C++17
5 / 100
57 ms 18776 KB
#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > g, g2;
vector<int> vis;
bool dfs(int v, int go)
{

    vis[v] = 1;
    if(v == go)
    {//cout << v << endl;
        return 1;
    }

    for(auto x : g[v])
    {
        if(vis[x] == 0 && dfs(x, go)) return 1;
    }
    vis[v] = 2;
    return 0;
}
bool c(int v)
{

    vis[v] = 1;
    for(auto x : g2[v])
    {
        //cout << v << " " << x << endl;
        if(vis[x] == 1) return 1;
        if(vis[x] == 0) if(c(x)) return 1;
    }
    vis[v] = 2;
    return 0;
}
void solve()
{
    int n, m;
    cin >> n;
    g.assign(n + 1, {});
    vis.assign(n + 1, 0);
    vector<int> to(n + 2), re(n + 2);
    vector<vector<int> > r(n + 1);
    for(int i = 0; i < n - 1; i++)
    {
        int x, y;
        cin >> x >> y;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    cin >> m;
    g2.assign(m + 1, {});
    vector<int> a(m), b(m);
    int maxi = 0;
    for(int i = 0; i < m; i++) cin >> a[i] >> b[i];
    for(int i = 0; i < m; i++)
    {
        if(a[i] < b[i])
        {
            to[a[i]]++;
            to[b[i] + 1]--;
            r[a[i]] .push_back(b[i]);
        }
        else
        {
            //cout << a[i] << " " << b[i] << "\n";
            re[b[i]]++;
            re[a[i] + 1]--;
            r[b[i]].push_back(a[i]);
        }
    }
    int fi = 0, se = 0;
    for(int i = 1; i <= n; i++)
    {
        sort(r[i].rbegin(), r[i].rend());
        for(auto x : r[i])
        {
            if(x <= maxi)
            {
                cout << "No\n";
                return;
            }
            maxi = max(maxi, x);
        }
        fi += to[i];
        se += re[i];
        if(fi > 0 && se > 0)
        {
            cout << "No\n";
            return;
        }
    }
    /*for(int i = 0; i < m; i++)
    {
        fill(vis.begin(), vis.end(), 0);
        dfs(a[i], b[i]);
        for(int j = 0; j < m; j++)
        {
            if(i == j) continue;
            if(vis[a[j]] == 1)
            {
                g2[i].push_back(j);
            }
            if(vis[b[j]] == 1)
            {
                //cout << i << " " << j << endl;
                g2[j].push_back(i);
            }
        }
    }
    vis.assign(m + 1, 0);
    for(int i = 0; i < m; i++)
    {
        if(vis[i] == 0 && c(i))
        {
            cout << "No\n";
            return;
        }
    }
    */
    cout << "Yes\n";
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int q;
    cin >> q;
    while(q--) solve();
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 5 ms 348 KB Output is correct
5 Correct 10 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 23 ms 972 KB Output is correct
10 Correct 25 ms 11288 KB Output is correct
11 Correct 3 ms 348 KB Output is correct
12 Correct 16 ms 476 KB Output is correct
13 Correct 30 ms 14164 KB Output is correct
14 Correct 31 ms 14388 KB Output is correct
15 Correct 57 ms 14164 KB Output is correct
16 Correct 48 ms 17408 KB Output is correct
17 Correct 33 ms 14952 KB Output is correct
18 Correct 46 ms 18776 KB Output is correct
19 Correct 28 ms 14932 KB Output is correct
20 Correct 29 ms 14960 KB Output is correct
21 Correct 29 ms 14940 KB Output is correct
22 Correct 29 ms 14940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Incorrect 1 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Incorrect 1 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Incorrect 1 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Incorrect 1 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 3 ms 348 KB Output is correct
6 Incorrect 1 ms 348 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 5 ms 348 KB Output is correct
5 Correct 10 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 23 ms 972 KB Output is correct
10 Correct 25 ms 11288 KB Output is correct
11 Correct 3 ms 348 KB Output is correct
12 Correct 16 ms 476 KB Output is correct
13 Correct 30 ms 14164 KB Output is correct
14 Correct 31 ms 14388 KB Output is correct
15 Correct 57 ms 14164 KB Output is correct
16 Correct 48 ms 17408 KB Output is correct
17 Correct 33 ms 14952 KB Output is correct
18 Correct 46 ms 18776 KB Output is correct
19 Correct 28 ms 14932 KB Output is correct
20 Correct 29 ms 14960 KB Output is correct
21 Correct 29 ms 14940 KB Output is correct
22 Correct 29 ms 14940 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Incorrect 1 ms 348 KB Output isn't correct
27 Halted 0 ms 0 KB -