답안 #994257

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
994257 2024-06-07T10:00:11 Z vjudge1 Jail (JOI22_jail) C++17
0 / 100
4 ms 348 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);
    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);
    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]--;
        }
        else
        {
            //cout << a[i] << " " << b[i] << "\n";
            re[b[i]]++;
            re[a[i] + 1]--;
        }
    }
    int fi = 0, se = 0;
    for(int i = 1; i <= n; i++)
    {
        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();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 4 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 1 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 1 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 1 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 1 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 0 ms 348 KB Output is correct
5 Incorrect 2 ms 348 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 4 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -