답안 #875760

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
875760 2023-11-20T12:45:16 Z dimashhh Jail (JOI22_jail) C++17
72 / 100
4215 ms 1048576 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5 + 10, MOD = 998244353;

vector<int> g[N], x[N], gt[N];
int timer = 0, tin[N], tout[N], n, m, s[N], t[N], pp[N], val[N], used[N], val1[N];
void dfs(int v, int pr = 1)
{
    tin[v] = ++timer;
    pp[v] = pr;
    for (int to : g[v])
    {
        if (to == pr)
            continue;
        dfs(to, v);
    }
    tout[v] = ++timer;
}
bool is(int v, int u)
{
    return (tin[v] <= tin[u] && tout[v] >= tout[u]);
}
vector<int> path(int v,int u){
    vector<int> p(1,v);
    while(!is(v,u)){
        v = pp[v];
        p.push_back(v);
    }
    while(!is(u,v)){
        p.push_back(u);
        u = pp[u];
    }
    return p;
}
bool res = 1;
void dfs1(int v){
    used[v] = 1;
    for(int to:gt[v]){
        if(used[to] == 1){
            res =0 ;
        }
        if(!used[to]){
            dfs1(to);
        }
    }
    used[v] = 2;
}
void test()
{
    res = 1;
    timer = 0;
    cin >> n;
    for (int i = 1; i <= n; i++)
        g[i].clear();
    for (int i = 1; i <= n - 1; i++)
    {
        int x, y;
        cin >> x >> y;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    dfs(1);
    cin >> m;
    for(int i = 1;i <= n;i++){
        val1[i] = val[i] = 0;
    }
    for(int i = 1;i <= m;i++){
        gt[i].clear();
    }
    for (int i = 1; i <= m; ++i)
    {
        cin >> s[i] >> t[i];
        used[i] = 0;
        val[s[i]] = i;
        val1[t[i]] = i;
    }
    for(int i = 1;i <= m;i++){
        for(int j:path(s[i],t[i])){
            int x = val[j];
            // cout << j << ' ';
            if(x && x != i){
                gt[i].push_back(x);
                // cout << i << ' ' << x << '\n';
            }
            x = val1[j];
            if(x && x != i){
                gt[x].push_back(i);
                // cout << i << ' ' << x << '\n';
            }
        }
        cout << '\n';
    }
    for(int i = 1;i <= m;i++){
        if(!used[i] && res){
            dfs1(i);
        }
    }
    cout << (res ? "Yes\n" : "No\n");
}
main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int T = 1;
    cin >> T;
    for (int i = 1; i <= T; i++)
    {
        test();
    }
}

Compilation message

jail.cpp:101:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
  101 | main()
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 20572 KB Output is correct
2 Correct 4 ms 20572 KB Output is correct
3 Correct 4 ms 20572 KB Output is correct
4 Correct 11 ms 20572 KB Output is correct
5 Correct 17 ms 21264 KB Output is correct
6 Correct 5 ms 20572 KB Output is correct
7 Correct 5 ms 20572 KB Output is correct
8 Correct 6 ms 20572 KB Output is correct
9 Correct 99 ms 24108 KB Output is correct
10 Correct 469 ms 33924 KB Output is correct
11 Correct 8 ms 20572 KB Output is correct
12 Correct 37 ms 21540 KB Output is correct
13 Correct 127 ms 61848 KB Output is correct
14 Correct 159 ms 76552 KB Output is correct
15 Runtime error 4215 ms 1048576 KB Execution killed with signal 9
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 20568 KB Output is correct
2 Correct 4 ms 20572 KB Output is correct
3 Correct 5 ms 20572 KB Output is correct
4 Correct 5 ms 20664 KB Output is correct
5 Correct 6 ms 20828 KB Output is correct
6 Correct 5 ms 20572 KB Output is correct
7 Correct 5 ms 20584 KB Output is correct
8 Correct 5 ms 20568 KB Output is correct
9 Correct 5 ms 20572 KB Output is correct
10 Correct 5 ms 20572 KB Output is correct
11 Correct 5 ms 20572 KB Output is correct
12 Correct 5 ms 20572 KB Output is correct
13 Correct 5 ms 20572 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 20568 KB Output is correct
2 Correct 4 ms 20572 KB Output is correct
3 Correct 5 ms 20572 KB Output is correct
4 Correct 5 ms 20664 KB Output is correct
5 Correct 6 ms 20828 KB Output is correct
6 Correct 5 ms 20572 KB Output is correct
7 Correct 5 ms 20584 KB Output is correct
8 Correct 5 ms 20568 KB Output is correct
9 Correct 5 ms 20572 KB Output is correct
10 Correct 5 ms 20572 KB Output is correct
11 Correct 5 ms 20572 KB Output is correct
12 Correct 5 ms 20572 KB Output is correct
13 Correct 5 ms 20572 KB Output is correct
14 Correct 4 ms 20572 KB Output is correct
15 Correct 4 ms 20572 KB Output is correct
16 Correct 5 ms 20572 KB Output is correct
17 Correct 5 ms 20444 KB Output is correct
18 Correct 5 ms 20572 KB Output is correct
19 Correct 4 ms 20572 KB Output is correct
20 Correct 5 ms 20572 KB Output is correct
21 Correct 5 ms 20572 KB Output is correct
22 Correct 5 ms 20572 KB Output is correct
23 Correct 4 ms 20572 KB Output is correct
24 Correct 4 ms 20572 KB Output is correct
25 Correct 5 ms 20572 KB Output is correct
26 Correct 5 ms 20572 KB Output is correct
27 Correct 5 ms 20572 KB Output is correct
28 Correct 4 ms 20572 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 20568 KB Output is correct
2 Correct 4 ms 20572 KB Output is correct
3 Correct 5 ms 20572 KB Output is correct
4 Correct 5 ms 20664 KB Output is correct
5 Correct 6 ms 20828 KB Output is correct
6 Correct 5 ms 20572 KB Output is correct
7 Correct 5 ms 20584 KB Output is correct
8 Correct 5 ms 20568 KB Output is correct
9 Correct 5 ms 20572 KB Output is correct
10 Correct 5 ms 20572 KB Output is correct
11 Correct 5 ms 20572 KB Output is correct
12 Correct 5 ms 20572 KB Output is correct
13 Correct 5 ms 20572 KB Output is correct
14 Correct 4 ms 20572 KB Output is correct
15 Correct 4 ms 20572 KB Output is correct
16 Correct 5 ms 20572 KB Output is correct
17 Correct 5 ms 20444 KB Output is correct
18 Correct 5 ms 20572 KB Output is correct
19 Correct 4 ms 20572 KB Output is correct
20 Correct 5 ms 20572 KB Output is correct
21 Correct 5 ms 20572 KB Output is correct
22 Correct 5 ms 20572 KB Output is correct
23 Correct 4 ms 20572 KB Output is correct
24 Correct 4 ms 20572 KB Output is correct
25 Correct 5 ms 20572 KB Output is correct
26 Correct 5 ms 20572 KB Output is correct
27 Correct 5 ms 20572 KB Output is correct
28 Correct 4 ms 20572 KB Output is correct
29 Correct 7 ms 20572 KB Output is correct
30 Correct 5 ms 20520 KB Output is correct
31 Correct 6 ms 20572 KB Output is correct
32 Correct 5 ms 20692 KB Output is correct
33 Correct 5 ms 20568 KB Output is correct
34 Correct 5 ms 20568 KB Output is correct
35 Correct 8 ms 20588 KB Output is correct
36 Correct 6 ms 20828 KB Output is correct
37 Correct 5 ms 20572 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 20568 KB Output is correct
2 Correct 4 ms 20572 KB Output is correct
3 Correct 5 ms 20572 KB Output is correct
4 Correct 5 ms 20664 KB Output is correct
5 Correct 6 ms 20828 KB Output is correct
6 Correct 5 ms 20572 KB Output is correct
7 Correct 5 ms 20584 KB Output is correct
8 Correct 5 ms 20568 KB Output is correct
9 Correct 5 ms 20572 KB Output is correct
10 Correct 5 ms 20572 KB Output is correct
11 Correct 5 ms 20572 KB Output is correct
12 Correct 5 ms 20572 KB Output is correct
13 Correct 5 ms 20572 KB Output is correct
14 Correct 4 ms 20572 KB Output is correct
15 Correct 4 ms 20572 KB Output is correct
16 Correct 5 ms 20572 KB Output is correct
17 Correct 5 ms 20444 KB Output is correct
18 Correct 5 ms 20572 KB Output is correct
19 Correct 4 ms 20572 KB Output is correct
20 Correct 5 ms 20572 KB Output is correct
21 Correct 5 ms 20572 KB Output is correct
22 Correct 5 ms 20572 KB Output is correct
23 Correct 4 ms 20572 KB Output is correct
24 Correct 4 ms 20572 KB Output is correct
25 Correct 5 ms 20572 KB Output is correct
26 Correct 5 ms 20572 KB Output is correct
27 Correct 5 ms 20572 KB Output is correct
28 Correct 4 ms 20572 KB Output is correct
29 Correct 7 ms 20572 KB Output is correct
30 Correct 5 ms 20520 KB Output is correct
31 Correct 6 ms 20572 KB Output is correct
32 Correct 5 ms 20692 KB Output is correct
33 Correct 5 ms 20568 KB Output is correct
34 Correct 5 ms 20568 KB Output is correct
35 Correct 8 ms 20588 KB Output is correct
36 Correct 6 ms 20828 KB Output is correct
37 Correct 5 ms 20572 KB Output is correct
38 Correct 118 ms 24148 KB Output is correct
39 Correct 473 ms 34024 KB Output is correct
40 Correct 52 ms 23124 KB Output is correct
41 Correct 25 ms 22040 KB Output is correct
42 Correct 44 ms 23376 KB Output is correct
43 Correct 19 ms 22104 KB Output is correct
44 Correct 10 ms 20892 KB Output is correct
45 Correct 37 ms 25876 KB Output is correct
46 Correct 35 ms 25976 KB Output is correct
47 Correct 90 ms 29416 KB Output is correct
48 Correct 93 ms 29272 KB Output is correct
49 Correct 47 ms 26160 KB Output is correct
50 Correct 37 ms 25940 KB Output is correct
51 Correct 30 ms 26708 KB Output is correct
52 Correct 35 ms 26964 KB Output is correct
53 Correct 11 ms 21296 KB Output is correct
54 Correct 36 ms 25948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 20576 KB Output is correct
2 Correct 4 ms 20576 KB Output is correct
3 Correct 4 ms 20628 KB Output is correct
4 Correct 5 ms 20568 KB Output is correct
5 Correct 8 ms 20568 KB Output is correct
6 Correct 5 ms 20664 KB Output is correct
7 Correct 5 ms 20572 KB Output is correct
8 Correct 5 ms 20576 KB Output is correct
9 Correct 4 ms 20568 KB Output is correct
10 Correct 4 ms 20644 KB Output is correct
11 Correct 4 ms 20592 KB Output is correct
12 Correct 5 ms 20572 KB Output is correct
13 Correct 20 ms 21084 KB Output is correct
14 Correct 25 ms 21524 KB Output is correct
15 Correct 23 ms 21340 KB Output is correct
16 Correct 38 ms 26268 KB Output is correct
17 Correct 92 ms 33136 KB Output is correct
18 Correct 217 ms 55212 KB Output is correct
19 Correct 41 ms 26448 KB Output is correct
20 Correct 44 ms 26448 KB Output is correct
21 Correct 47 ms 26292 KB Output is correct
22 Correct 78 ms 32972 KB Output is correct
23 Correct 68 ms 33096 KB Output is correct
24 Correct 68 ms 32976 KB Output is correct
25 Correct 67 ms 33092 KB Output is correct
26 Correct 70 ms 32844 KB Output is correct
27 Correct 86 ms 35524 KB Output is correct
28 Correct 76 ms 37572 KB Output is correct
29 Correct 72 ms 34248 KB Output is correct
30 Correct 70 ms 31184 KB Output is correct
31 Correct 56 ms 31436 KB Output is correct
32 Correct 63 ms 31184 KB Output is correct
33 Correct 55 ms 31644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 20572 KB Output is correct
2 Correct 4 ms 20572 KB Output is correct
3 Correct 4 ms 20572 KB Output is correct
4 Correct 11 ms 20572 KB Output is correct
5 Correct 17 ms 21264 KB Output is correct
6 Correct 5 ms 20572 KB Output is correct
7 Correct 5 ms 20572 KB Output is correct
8 Correct 6 ms 20572 KB Output is correct
9 Correct 99 ms 24108 KB Output is correct
10 Correct 469 ms 33924 KB Output is correct
11 Correct 8 ms 20572 KB Output is correct
12 Correct 37 ms 21540 KB Output is correct
13 Correct 127 ms 61848 KB Output is correct
14 Correct 159 ms 76552 KB Output is correct
15 Runtime error 4215 ms 1048576 KB Execution killed with signal 9
16 Halted 0 ms 0 KB -