답안 #1039200

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1039200 2024-07-30T14:28:45 Z Andrey Jail (JOI22_jail) C++14
0 / 100
7 ms 11440 KB
#include<bits/stdc++.h>
using namespace std;

vector<int> haha[200001];
vector<int> wow(200001);
vector<int> wut(200001);
vector<int> topo[200001];

bool dfs(int a, int t, int x, int p) {
    if(a == x) {
        if(wow[a] != -1 && wow[a] != p) {
            topo[wow[a]].push_back(p);
        }
        if(wut[a] != -1 && wut[a] != p) {
            topo[p].push_back(wut[a]);
        }
        return true;
    }
    for(int v: haha[a]) {
        if(v != t) {
            if(dfs(v,a,x,p)) {
                if(wow[a] != -1 && wow[a] != p) {
                    topo[wow[a]].push_back(p);
                }
                if(wut[a] != -1 && wut[a] != p) {
                    topo[p].push_back(wut[a]);
                }
                return true;
            }
        }
    }
    return false;
}

void solve() {
    int n,m,a,b;
    cin >> n;
    topo[0].clear();
    vector<pair<int,int>> idk(0);
    for(int i = 1; i <= n; i++) {
        haha[i].clear();
        topo[i].clear();
        wow[i] = -1;
        wut[i] = -1;
    }
    for(int i = 0; i < n-1; i++) {
        cin >> a >> b;
        haha[a].push_back(b);
        haha[b].push_back(a);
    }
    cin >> m;
    for(int i = 0; i < m; i++) {
        cin >> a >> b;
        wow[a] = i;
        wut[b] = i;
        idk.push_back({a,b});
    }
    for(int i = 0; i < m; i++) {
        dfs(idk[i].first,-1,idk[i].second,i);
    }
    vector<int> br(m);
    vector<int> ans(0);
    for(int i = 0; i < m; i++) {
        if(br[i] == 0) {
            ans.push_back(i);
        }
    }
    for(int i = 0; i < ans.size(); i++) {
        for(int v: topo[ans[i]]) {
            br[v]--;
            if(br[v] == 0) {
                ans.push_back(v);
            }
        }
    }
    if(ans.size() == m) {
        cout << "Yes\n";
    }
    else {
        cout << "No\n";
    }
}

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

Compilation message

jail.cpp: In function 'void solve()':
jail.cpp:68:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |     for(int i = 0; i < ans.size(); i++) {
      |                    ~~^~~~~~~~~~~~
jail.cpp:76:19: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   76 |     if(ans.size() == m) {
      |        ~~~~~~~~~~~^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 11356 KB Output is correct
2 Incorrect 4 ms 11356 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 11440 KB Output is correct
2 Incorrect 5 ms 11352 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 11440 KB Output is correct
2 Incorrect 5 ms 11352 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 11440 KB Output is correct
2 Incorrect 5 ms 11352 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 11440 KB Output is correct
2 Incorrect 5 ms 11352 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 11356 KB Output is correct
2 Incorrect 5 ms 11396 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 11356 KB Output is correct
2 Incorrect 4 ms 11356 KB Output isn't correct
3 Halted 0 ms 0 KB -