답안 #876849

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
876849 2023-11-22T12:35:53 Z Ivkosqn Jail (JOI22_jail) C++14
0 / 100
16 ms 7284 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], g[maxn];

void read(){
    cin >> n;
    for(int i = 1;i <= n;i++){
        v[i].clear();
        g[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];
    }
}


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

bool cycle = 0;

void DFS(int ver){
    used[ver] = 1;
    for(int nb : g[ver]){
        if(!used[nb])
            DFS(nb);
        else if(used[nb] == 1)
            cycle = 1;
    }
    used[ver] = 2;
}

void solve(){
    read();
    for(int i = 1;i <= m;i++){
        for(int j = 1;j <= m;j++){
            if(i == j)
                continue;
            for(int k = 1;k <= n;k++)
                used[k] = 0;
            used[f[i]] = 1;
            if(used[s[j]] == 1){
                g[j].push_back(i);
                //cout << j << " " << i << endl;
                continue;
            }
            dfs(s[j]);
            if(!used[f[j]]){
                g[j].push_back(i);
                //cout << j << " " << i << endl;
            }
        }
    }
    cycle = 0;
    memset(used, 0, sizeof(used));
    for(int i = 1;i <= n;i++){
        if(!used[i]){
            DFS(i);
        }
    }
    if(cycle)
        cout << "No\n";
    else
        cout << "Yes\n";
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t;
    cin >> t;
    while(t--){
        solve();
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 7260 KB Output is correct
2 Correct 2 ms 7260 KB Output is correct
3 Correct 2 ms 7260 KB Output is correct
4 Incorrect 10 ms 7260 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 7260 KB Output is correct
2 Correct 1 ms 7260 KB Output is correct
3 Incorrect 2 ms 7260 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 7260 KB Output is correct
2 Correct 1 ms 7260 KB Output is correct
3 Incorrect 2 ms 7260 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 7260 KB Output is correct
2 Correct 1 ms 7260 KB Output is correct
3 Incorrect 2 ms 7260 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 7260 KB Output is correct
2 Correct 1 ms 7260 KB Output is correct
3 Incorrect 2 ms 7260 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 7256 KB Output is correct
2 Correct 1 ms 7260 KB Output is correct
3 Correct 2 ms 7260 KB Output is correct
4 Correct 2 ms 7284 KB Output is correct
5 Incorrect 16 ms 7260 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 7260 KB Output is correct
2 Correct 2 ms 7260 KB Output is correct
3 Correct 2 ms 7260 KB Output is correct
4 Incorrect 10 ms 7260 KB Output isn't correct
5 Halted 0 ms 0 KB -