Submission #1104620

# Submission time Handle Problem Language Result Execution time Memory
1104620 2024-10-24T07:33:49 Z _callmelucian Jail (JOI22_jail) C++14
49 / 100
1048 ms 44552 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pl;
typedef pair<int,int> pii;
typedef tuple<int,int,int> tt;

#define all(a) a.begin(), a.end()
#define filter(a) a.erase(unique(all(a)), a.end())

const int mn = 1e5 + 5;
int up[mn][18], depth[mn], vis[mn];
vector<int> adj[mn], graph[mn];

void dfs (int u, int p, int d) {
    up[u][0] = p, depth[u] = d;
    for (int i = 1; i < 18; i++)
        up[u][i] = up[up[u][i - 1]][i - 1];
    for (int v : adj[u])
        if (v != p) dfs(v, u, d + 1);
}

int goUp (int a, int k) {
    for (int i = 0; i < 18; i++)
        if (k & (1 << i)) a = up[a][i];
    return a;
}

int lca (int a, int b) {
    if (depth[a] < depth[b]) swap(a, b);
    a = goUp(a, depth[a] - depth[b]);
    if (a == b) return a;
    for (int i = 17; i >= 0; i--)
        if (up[a][i] != up[b][i]) a = up[a][i], b = up[b][i];
    return up[a][0];
}

int distance (int a, int b) {
    return depth[a] + depth[b] - 2 * depth[lca(a, b)];
}

bool inPath (int node, int a, int b) {
    return distance(a, node) + distance(node, b) == distance(a, b);
}

bool detectCycle (int u) {
    if (vis[u] == 1) return 1;
    if (vis[u] == 2) return 0;
    vis[u] = 1;
    for (int v : graph[u])
        if (detectCycle(v)) return vis[u] = 2, 1;
    vis[u] = 2;
    return 0;
}

void solve() {
    int n; cin >> n;
    for (int i = 1; i <= n; i++) adj[i].clear();
    for (int i = 1; i < n; i++) {
        int a, b; cin >> a >> b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    dfs(1, 1, 1);

    int m; cin >> m;
    for (int i = 0; i < m; i++) {
        graph[i].clear();
        vis[i] = 0;
    }

    vector<pii> paths(m);
    for (int i = 0; i < m; i++)
        cin >> paths[i].first >> paths[i].second;

    for (int i = 0; i < m; i++) {
        vis[i] = 0;
        for (int j = 0; j < m; j++) {
            if (i == j) continue;
            if (inPath(paths[j].first, paths[i].first, paths[i].second) ||
                inPath(paths[i].second, paths[j].first, paths[j].second)) graph[j].push_back(i);
        }
    }
    for (int i = 0; i < m; i++)
        if (!vis[i] && detectCycle(i)) return cout << "No\n", void();

    cout << "Yes\n";
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);

    int TC; cin >> TC;
    while (TC--) solve();

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6736 KB Output is correct
2 Correct 2 ms 6736 KB Output is correct
3 Correct 1 ms 6768 KB Output is correct
4 Correct 10 ms 6736 KB Output is correct
5 Correct 15 ms 7504 KB Output is correct
6 Correct 2 ms 6736 KB Output is correct
7 Correct 3 ms 6736 KB Output is correct
8 Correct 29 ms 6920 KB Output is correct
9 Correct 1016 ms 9612 KB Output is correct
10 Runtime error 53 ms 44360 KB Execution killed with signal 11
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6736 KB Output is correct
2 Correct 2 ms 6736 KB Output is correct
3 Correct 2 ms 6736 KB Output is correct
4 Correct 2 ms 6736 KB Output is correct
5 Correct 2 ms 6736 KB Output is correct
6 Correct 2 ms 6736 KB Output is correct
7 Correct 2 ms 6736 KB Output is correct
8 Correct 2 ms 6736 KB Output is correct
9 Correct 2 ms 6736 KB Output is correct
10 Correct 3 ms 6736 KB Output is correct
11 Correct 2 ms 6736 KB Output is correct
12 Correct 2 ms 6736 KB Output is correct
13 Correct 2 ms 6992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6736 KB Output is correct
2 Correct 2 ms 6736 KB Output is correct
3 Correct 2 ms 6736 KB Output is correct
4 Correct 2 ms 6736 KB Output is correct
5 Correct 2 ms 6736 KB Output is correct
6 Correct 2 ms 6736 KB Output is correct
7 Correct 2 ms 6736 KB Output is correct
8 Correct 2 ms 6736 KB Output is correct
9 Correct 2 ms 6736 KB Output is correct
10 Correct 3 ms 6736 KB Output is correct
11 Correct 2 ms 6736 KB Output is correct
12 Correct 2 ms 6736 KB Output is correct
13 Correct 2 ms 6992 KB Output is correct
14 Correct 2 ms 6736 KB Output is correct
15 Correct 2 ms 6736 KB Output is correct
16 Correct 3 ms 6736 KB Output is correct
17 Correct 3 ms 6736 KB Output is correct
18 Correct 3 ms 6736 KB Output is correct
19 Correct 2 ms 6736 KB Output is correct
20 Correct 3 ms 6900 KB Output is correct
21 Correct 3 ms 6736 KB Output is correct
22 Correct 2 ms 6812 KB Output is correct
23 Correct 2 ms 6736 KB Output is correct
24 Correct 2 ms 6736 KB Output is correct
25 Correct 4 ms 6992 KB Output is correct
26 Correct 2 ms 6736 KB Output is correct
27 Correct 3 ms 6848 KB Output is correct
28 Correct 2 ms 6736 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6736 KB Output is correct
2 Correct 2 ms 6736 KB Output is correct
3 Correct 2 ms 6736 KB Output is correct
4 Correct 2 ms 6736 KB Output is correct
5 Correct 2 ms 6736 KB Output is correct
6 Correct 2 ms 6736 KB Output is correct
7 Correct 2 ms 6736 KB Output is correct
8 Correct 2 ms 6736 KB Output is correct
9 Correct 2 ms 6736 KB Output is correct
10 Correct 3 ms 6736 KB Output is correct
11 Correct 2 ms 6736 KB Output is correct
12 Correct 2 ms 6736 KB Output is correct
13 Correct 2 ms 6992 KB Output is correct
14 Correct 2 ms 6736 KB Output is correct
15 Correct 2 ms 6736 KB Output is correct
16 Correct 3 ms 6736 KB Output is correct
17 Correct 3 ms 6736 KB Output is correct
18 Correct 3 ms 6736 KB Output is correct
19 Correct 2 ms 6736 KB Output is correct
20 Correct 3 ms 6900 KB Output is correct
21 Correct 3 ms 6736 KB Output is correct
22 Correct 2 ms 6812 KB Output is correct
23 Correct 2 ms 6736 KB Output is correct
24 Correct 2 ms 6736 KB Output is correct
25 Correct 4 ms 6992 KB Output is correct
26 Correct 2 ms 6736 KB Output is correct
27 Correct 3 ms 6848 KB Output is correct
28 Correct 2 ms 6736 KB Output is correct
29 Correct 30 ms 6736 KB Output is correct
30 Correct 22 ms 6736 KB Output is correct
31 Correct 21 ms 6736 KB Output is correct
32 Correct 14 ms 6736 KB Output is correct
33 Correct 4 ms 6736 KB Output is correct
34 Correct 39 ms 6736 KB Output is correct
35 Correct 48 ms 6736 KB Output is correct
36 Correct 35 ms 6824 KB Output is correct
37 Correct 26 ms 6980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6736 KB Output is correct
2 Correct 2 ms 6736 KB Output is correct
3 Correct 2 ms 6736 KB Output is correct
4 Correct 2 ms 6736 KB Output is correct
5 Correct 2 ms 6736 KB Output is correct
6 Correct 2 ms 6736 KB Output is correct
7 Correct 2 ms 6736 KB Output is correct
8 Correct 2 ms 6736 KB Output is correct
9 Correct 2 ms 6736 KB Output is correct
10 Correct 3 ms 6736 KB Output is correct
11 Correct 2 ms 6736 KB Output is correct
12 Correct 2 ms 6736 KB Output is correct
13 Correct 2 ms 6992 KB Output is correct
14 Correct 2 ms 6736 KB Output is correct
15 Correct 2 ms 6736 KB Output is correct
16 Correct 3 ms 6736 KB Output is correct
17 Correct 3 ms 6736 KB Output is correct
18 Correct 3 ms 6736 KB Output is correct
19 Correct 2 ms 6736 KB Output is correct
20 Correct 3 ms 6900 KB Output is correct
21 Correct 3 ms 6736 KB Output is correct
22 Correct 2 ms 6812 KB Output is correct
23 Correct 2 ms 6736 KB Output is correct
24 Correct 2 ms 6736 KB Output is correct
25 Correct 4 ms 6992 KB Output is correct
26 Correct 2 ms 6736 KB Output is correct
27 Correct 3 ms 6848 KB Output is correct
28 Correct 2 ms 6736 KB Output is correct
29 Correct 30 ms 6736 KB Output is correct
30 Correct 22 ms 6736 KB Output is correct
31 Correct 21 ms 6736 KB Output is correct
32 Correct 14 ms 6736 KB Output is correct
33 Correct 4 ms 6736 KB Output is correct
34 Correct 39 ms 6736 KB Output is correct
35 Correct 48 ms 6736 KB Output is correct
36 Correct 35 ms 6824 KB Output is correct
37 Correct 26 ms 6980 KB Output is correct
38 Correct 1048 ms 9544 KB Output is correct
39 Runtime error 58 ms 44552 KB Execution killed with signal 11
40 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6904 KB Output is correct
2 Correct 2 ms 6736 KB Output is correct
3 Correct 1 ms 6736 KB Output is correct
4 Correct 2 ms 6736 KB Output is correct
5 Correct 13 ms 6736 KB Output is correct
6 Correct 2 ms 6736 KB Output is correct
7 Correct 2 ms 6736 KB Output is correct
8 Correct 2 ms 6736 KB Output is correct
9 Correct 2 ms 6964 KB Output is correct
10 Correct 2 ms 6736 KB Output is correct
11 Correct 2 ms 6736 KB Output is correct
12 Correct 35 ms 6980 KB Output is correct
13 Correct 431 ms 7380 KB Output is correct
14 Correct 204 ms 7664 KB Output is correct
15 Correct 312 ms 7308 KB Output is correct
16 Runtime error 57 ms 35400 KB Execution killed with signal 11
17 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6736 KB Output is correct
2 Correct 2 ms 6736 KB Output is correct
3 Correct 1 ms 6768 KB Output is correct
4 Correct 10 ms 6736 KB Output is correct
5 Correct 15 ms 7504 KB Output is correct
6 Correct 2 ms 6736 KB Output is correct
7 Correct 3 ms 6736 KB Output is correct
8 Correct 29 ms 6920 KB Output is correct
9 Correct 1016 ms 9612 KB Output is correct
10 Runtime error 53 ms 44360 KB Execution killed with signal 11
11 Halted 0 ms 0 KB -