답안 #876860

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
876860 2023-11-22T12:44:29 Z Ivkosqn Jail (JOI22_jail) C++14
49 / 100
5000 ms 10588 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], 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[s[j]] = 1;
            dfs(s[i]);
            if(!used[f[i]]){
                g[j].push_back(i);
                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);
                continue;
            }
            dfs(s[j]);
            if(!used[f[j]]){
                g[j].push_back(i);
            }
        }
    }
    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 1 ms 6748 KB Output is correct
2 Correct 2 ms 6748 KB Output is correct
3 Correct 2 ms 6748 KB Output is correct
4 Correct 11 ms 6580 KB Output is correct
5 Correct 23 ms 6748 KB Output is correct
6 Correct 2 ms 6748 KB Output is correct
7 Correct 3 ms 6744 KB Output is correct
8 Correct 356 ms 6748 KB Output is correct
9 Execution timed out 5059 ms 7088 KB Time limit exceeded
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6748 KB Output is correct
2 Correct 1 ms 6744 KB Output is correct
3 Correct 2 ms 6744 KB Output is correct
4 Correct 2 ms 6748 KB Output is correct
5 Correct 2 ms 6748 KB Output is correct
6 Correct 2 ms 6748 KB Output is correct
7 Correct 2 ms 6804 KB Output is correct
8 Correct 3 ms 6748 KB Output is correct
9 Correct 2 ms 6748 KB Output is correct
10 Correct 2 ms 6744 KB Output is correct
11 Correct 2 ms 6748 KB Output is correct
12 Correct 2 ms 6748 KB Output is correct
13 Correct 2 ms 6748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6748 KB Output is correct
2 Correct 1 ms 6744 KB Output is correct
3 Correct 2 ms 6744 KB Output is correct
4 Correct 2 ms 6748 KB Output is correct
5 Correct 2 ms 6748 KB Output is correct
6 Correct 2 ms 6748 KB Output is correct
7 Correct 2 ms 6804 KB Output is correct
8 Correct 3 ms 6748 KB Output is correct
9 Correct 2 ms 6748 KB Output is correct
10 Correct 2 ms 6744 KB Output is correct
11 Correct 2 ms 6748 KB Output is correct
12 Correct 2 ms 6748 KB Output is correct
13 Correct 2 ms 6748 KB Output is correct
14 Correct 2 ms 6748 KB Output is correct
15 Correct 2 ms 6748 KB Output is correct
16 Correct 3 ms 6748 KB Output is correct
17 Correct 3 ms 6748 KB Output is correct
18 Correct 4 ms 6748 KB Output is correct
19 Correct 2 ms 6748 KB Output is correct
20 Correct 4 ms 6748 KB Output is correct
21 Correct 4 ms 6748 KB Output is correct
22 Correct 3 ms 6748 KB Output is correct
23 Correct 2 ms 6748 KB Output is correct
24 Correct 2 ms 6748 KB Output is correct
25 Correct 4 ms 6804 KB Output is correct
26 Correct 2 ms 6748 KB Output is correct
27 Correct 3 ms 6748 KB Output is correct
28 Correct 2 ms 6748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6748 KB Output is correct
2 Correct 1 ms 6744 KB Output is correct
3 Correct 2 ms 6744 KB Output is correct
4 Correct 2 ms 6748 KB Output is correct
5 Correct 2 ms 6748 KB Output is correct
6 Correct 2 ms 6748 KB Output is correct
7 Correct 2 ms 6804 KB Output is correct
8 Correct 3 ms 6748 KB Output is correct
9 Correct 2 ms 6748 KB Output is correct
10 Correct 2 ms 6744 KB Output is correct
11 Correct 2 ms 6748 KB Output is correct
12 Correct 2 ms 6748 KB Output is correct
13 Correct 2 ms 6748 KB Output is correct
14 Correct 2 ms 6748 KB Output is correct
15 Correct 2 ms 6748 KB Output is correct
16 Correct 3 ms 6748 KB Output is correct
17 Correct 3 ms 6748 KB Output is correct
18 Correct 4 ms 6748 KB Output is correct
19 Correct 2 ms 6748 KB Output is correct
20 Correct 4 ms 6748 KB Output is correct
21 Correct 4 ms 6748 KB Output is correct
22 Correct 3 ms 6748 KB Output is correct
23 Correct 2 ms 6748 KB Output is correct
24 Correct 2 ms 6748 KB Output is correct
25 Correct 4 ms 6804 KB Output is correct
26 Correct 2 ms 6748 KB Output is correct
27 Correct 3 ms 6748 KB Output is correct
28 Correct 2 ms 6748 KB Output is correct
29 Correct 354 ms 7056 KB Output is correct
30 Correct 174 ms 6792 KB Output is correct
31 Correct 152 ms 6804 KB Output is correct
32 Correct 99 ms 6748 KB Output is correct
33 Correct 19 ms 6748 KB Output is correct
34 Correct 301 ms 6800 KB Output is correct
35 Correct 281 ms 6748 KB Output is correct
36 Correct 234 ms 6796 KB Output is correct
37 Correct 161 ms 6744 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6748 KB Output is correct
2 Correct 1 ms 6744 KB Output is correct
3 Correct 2 ms 6744 KB Output is correct
4 Correct 2 ms 6748 KB Output is correct
5 Correct 2 ms 6748 KB Output is correct
6 Correct 2 ms 6748 KB Output is correct
7 Correct 2 ms 6804 KB Output is correct
8 Correct 3 ms 6748 KB Output is correct
9 Correct 2 ms 6748 KB Output is correct
10 Correct 2 ms 6744 KB Output is correct
11 Correct 2 ms 6748 KB Output is correct
12 Correct 2 ms 6748 KB Output is correct
13 Correct 2 ms 6748 KB Output is correct
14 Correct 2 ms 6748 KB Output is correct
15 Correct 2 ms 6748 KB Output is correct
16 Correct 3 ms 6748 KB Output is correct
17 Correct 3 ms 6748 KB Output is correct
18 Correct 4 ms 6748 KB Output is correct
19 Correct 2 ms 6748 KB Output is correct
20 Correct 4 ms 6748 KB Output is correct
21 Correct 4 ms 6748 KB Output is correct
22 Correct 3 ms 6748 KB Output is correct
23 Correct 2 ms 6748 KB Output is correct
24 Correct 2 ms 6748 KB Output is correct
25 Correct 4 ms 6804 KB Output is correct
26 Correct 2 ms 6748 KB Output is correct
27 Correct 3 ms 6748 KB Output is correct
28 Correct 2 ms 6748 KB Output is correct
29 Correct 354 ms 7056 KB Output is correct
30 Correct 174 ms 6792 KB Output is correct
31 Correct 152 ms 6804 KB Output is correct
32 Correct 99 ms 6748 KB Output is correct
33 Correct 19 ms 6748 KB Output is correct
34 Correct 301 ms 6800 KB Output is correct
35 Correct 281 ms 6748 KB Output is correct
36 Correct 234 ms 6796 KB Output is correct
37 Correct 161 ms 6744 KB Output is correct
38 Execution timed out 5065 ms 7076 KB Time limit exceeded
39 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6748 KB Output is correct
2 Correct 1 ms 6748 KB Output is correct
3 Correct 1 ms 6748 KB Output is correct
4 Correct 1 ms 6748 KB Output is correct
5 Correct 20 ms 6744 KB Output is correct
6 Correct 2 ms 6748 KB Output is correct
7 Correct 2 ms 6748 KB Output is correct
8 Correct 2 ms 6748 KB Output is correct
9 Correct 2 ms 6748 KB Output is correct
10 Correct 2 ms 6748 KB Output is correct
11 Correct 2 ms 6748 KB Output is correct
12 Correct 241 ms 6804 KB Output is correct
13 Correct 1880 ms 7008 KB Output is correct
14 Correct 846 ms 6784 KB Output is correct
15 Correct 1475 ms 7052 KB Output is correct
16 Execution timed out 5057 ms 10588 KB Time limit exceeded
17 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6748 KB Output is correct
2 Correct 2 ms 6748 KB Output is correct
3 Correct 2 ms 6748 KB Output is correct
4 Correct 11 ms 6580 KB Output is correct
5 Correct 23 ms 6748 KB Output is correct
6 Correct 2 ms 6748 KB Output is correct
7 Correct 3 ms 6744 KB Output is correct
8 Correct 356 ms 6748 KB Output is correct
9 Execution timed out 5059 ms 7088 KB Time limit exceeded
10 Halted 0 ms 0 KB -