답안 #876773

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
876773 2023-11-22T10:15:14 Z Ivkosqn Jail (JOI22_jail) C++14
0 / 100
2 ms 3416 KB
#include <bits/stdc++.h>
#define endl '\n'

using namespace std;

const int maxn = 120010;
int n, m, s[maxn], f[maxn], used[maxn];
vector<int> v[maxn];

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

void newFill(){
    for(int i = 1;i <= n;i++)
        used[i] = 0;
    for(int i = 1;i <= m;i++)
        used[s[i]]++;
}

void solve(){
    read();
    for(int i = 1;i <= m;i++){
        for(int j = 1;j <= m;j++){
            if(i == j)
                continue;
            int ready = 0;
            newFill();

            dfs(s[i]);
            if(used[f[i]] == -1){
                newFill();
                used[s[i]]--;
                used[f[i]]++;
                dfs(s[j]);
                if(used[f[j]] == -1)
                    ready = 1;
            }
            else{
                newFill();
                dfs(s[j]);
                if(used[f[j]] == -1){
                    newFill();
                    used[s[j]]--;
                    used[f[j]]++;
                    dfs(s[i]);
                    if(used[f[i]] == -1)
                        ready = 1;
                }
            }
            if(ready == 0){
                cout << "No\n";
                return;
            }
        }
    }
    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 1 ms 3416 KB Output is correct
2 Incorrect 1 ms 3164 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 3164 KB Output is correct
2 Correct 1 ms 3208 KB Output is correct
3 Correct 1 ms 3164 KB Output is correct
4 Correct 2 ms 3160 KB Output is correct
5 Correct 2 ms 3164 KB Output is correct
6 Correct 2 ms 3164 KB Output is correct
7 Incorrect 2 ms 3164 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 3164 KB Output is correct
2 Correct 1 ms 3208 KB Output is correct
3 Correct 1 ms 3164 KB Output is correct
4 Correct 2 ms 3160 KB Output is correct
5 Correct 2 ms 3164 KB Output is correct
6 Correct 2 ms 3164 KB Output is correct
7 Incorrect 2 ms 3164 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 3164 KB Output is correct
2 Correct 1 ms 3208 KB Output is correct
3 Correct 1 ms 3164 KB Output is correct
4 Correct 2 ms 3160 KB Output is correct
5 Correct 2 ms 3164 KB Output is correct
6 Correct 2 ms 3164 KB Output is correct
7 Incorrect 2 ms 3164 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 3164 KB Output is correct
2 Correct 1 ms 3208 KB Output is correct
3 Correct 1 ms 3164 KB Output is correct
4 Correct 2 ms 3160 KB Output is correct
5 Correct 2 ms 3164 KB Output is correct
6 Correct 2 ms 3164 KB Output is correct
7 Incorrect 2 ms 3164 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 3160 KB Output is correct
2 Correct 1 ms 3164 KB Output is correct
3 Incorrect 1 ms 3164 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 3416 KB Output is correct
2 Incorrect 1 ms 3164 KB Output isn't correct
3 Halted 0 ms 0 KB -