Submission #1104621

# Submission time Handle Problem Language Result Execution time Memory
1104621 2024-10-24T07:38:35 Z _callmelucian Jail (JOI22_jail) C++14
61 / 100
5000 ms 32976 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 = 2e5 + 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;
    return vis[u] = 2, 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[i].first, paths[j].first, paths[j].second) &&
                inPath(paths[j].first, paths[i].first, paths[i].second)) return cout << "No\n", void();*/

            /*if (inPath(paths[i].first, paths[j].first, paths[j].second) &&
                inPath(paths[i].second, paths[j].first, paths[j].second)) return cout << "No\n", void();*/

            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 3 ms 12880 KB Output is correct
2 Correct 3 ms 12880 KB Output is correct
3 Correct 3 ms 12880 KB Output is correct
4 Correct 11 ms 12880 KB Output is correct
5 Correct 22 ms 12964 KB Output is correct
6 Correct 3 ms 12980 KB Output is correct
7 Correct 4 ms 12880 KB Output is correct
8 Correct 35 ms 12880 KB Output is correct
9 Correct 1058 ms 14444 KB Output is correct
10 Correct 69 ms 31208 KB Output is correct
11 Correct 16 ms 12880 KB Output is correct
12 Correct 344 ms 13896 KB Output is correct
13 Execution timed out 5063 ms 32976 KB Time limit exceeded
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 12880 KB Output is correct
2 Correct 2 ms 12880 KB Output is correct
3 Correct 4 ms 12880 KB Output is correct
4 Correct 3 ms 12880 KB Output is correct
5 Correct 3 ms 12880 KB Output is correct
6 Correct 4 ms 12880 KB Output is correct
7 Correct 3 ms 12880 KB Output is correct
8 Correct 3 ms 12880 KB Output is correct
9 Correct 3 ms 12880 KB Output is correct
10 Correct 3 ms 12880 KB Output is correct
11 Correct 3 ms 12880 KB Output is correct
12 Correct 3 ms 12960 KB Output is correct
13 Correct 3 ms 12880 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 12880 KB Output is correct
2 Correct 2 ms 12880 KB Output is correct
3 Correct 4 ms 12880 KB Output is correct
4 Correct 3 ms 12880 KB Output is correct
5 Correct 3 ms 12880 KB Output is correct
6 Correct 4 ms 12880 KB Output is correct
7 Correct 3 ms 12880 KB Output is correct
8 Correct 3 ms 12880 KB Output is correct
9 Correct 3 ms 12880 KB Output is correct
10 Correct 3 ms 12880 KB Output is correct
11 Correct 3 ms 12880 KB Output is correct
12 Correct 3 ms 12960 KB Output is correct
13 Correct 3 ms 12880 KB Output is correct
14 Correct 3 ms 13048 KB Output is correct
15 Correct 2 ms 12880 KB Output is correct
16 Correct 3 ms 12880 KB Output is correct
17 Correct 4 ms 12880 KB Output is correct
18 Correct 5 ms 12880 KB Output is correct
19 Correct 3 ms 13052 KB Output is correct
20 Correct 4 ms 12880 KB Output is correct
21 Correct 4 ms 12880 KB Output is correct
22 Correct 3 ms 13048 KB Output is correct
23 Correct 3 ms 12880 KB Output is correct
24 Correct 2 ms 12880 KB Output is correct
25 Correct 3 ms 12880 KB Output is correct
26 Correct 3 ms 13048 KB Output is correct
27 Correct 4 ms 12880 KB Output is correct
28 Correct 3 ms 13048 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 12880 KB Output is correct
2 Correct 2 ms 12880 KB Output is correct
3 Correct 4 ms 12880 KB Output is correct
4 Correct 3 ms 12880 KB Output is correct
5 Correct 3 ms 12880 KB Output is correct
6 Correct 4 ms 12880 KB Output is correct
7 Correct 3 ms 12880 KB Output is correct
8 Correct 3 ms 12880 KB Output is correct
9 Correct 3 ms 12880 KB Output is correct
10 Correct 3 ms 12880 KB Output is correct
11 Correct 3 ms 12880 KB Output is correct
12 Correct 3 ms 12960 KB Output is correct
13 Correct 3 ms 12880 KB Output is correct
14 Correct 3 ms 13048 KB Output is correct
15 Correct 2 ms 12880 KB Output is correct
16 Correct 3 ms 12880 KB Output is correct
17 Correct 4 ms 12880 KB Output is correct
18 Correct 5 ms 12880 KB Output is correct
19 Correct 3 ms 13052 KB Output is correct
20 Correct 4 ms 12880 KB Output is correct
21 Correct 4 ms 12880 KB Output is correct
22 Correct 3 ms 13048 KB Output is correct
23 Correct 3 ms 12880 KB Output is correct
24 Correct 2 ms 12880 KB Output is correct
25 Correct 3 ms 12880 KB Output is correct
26 Correct 3 ms 13048 KB Output is correct
27 Correct 4 ms 12880 KB Output is correct
28 Correct 3 ms 13048 KB Output is correct
29 Correct 31 ms 12972 KB Output is correct
30 Correct 24 ms 12880 KB Output is correct
31 Correct 26 ms 13044 KB Output is correct
32 Correct 15 ms 12880 KB Output is correct
33 Correct 5 ms 12880 KB Output is correct
34 Correct 44 ms 12880 KB Output is correct
35 Correct 49 ms 12880 KB Output is correct
36 Correct 36 ms 12880 KB Output is correct
37 Correct 27 ms 12880 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 12880 KB Output is correct
2 Correct 2 ms 12880 KB Output is correct
3 Correct 4 ms 12880 KB Output is correct
4 Correct 3 ms 12880 KB Output is correct
5 Correct 3 ms 12880 KB Output is correct
6 Correct 4 ms 12880 KB Output is correct
7 Correct 3 ms 12880 KB Output is correct
8 Correct 3 ms 12880 KB Output is correct
9 Correct 3 ms 12880 KB Output is correct
10 Correct 3 ms 12880 KB Output is correct
11 Correct 3 ms 12880 KB Output is correct
12 Correct 3 ms 12960 KB Output is correct
13 Correct 3 ms 12880 KB Output is correct
14 Correct 3 ms 13048 KB Output is correct
15 Correct 2 ms 12880 KB Output is correct
16 Correct 3 ms 12880 KB Output is correct
17 Correct 4 ms 12880 KB Output is correct
18 Correct 5 ms 12880 KB Output is correct
19 Correct 3 ms 13052 KB Output is correct
20 Correct 4 ms 12880 KB Output is correct
21 Correct 4 ms 12880 KB Output is correct
22 Correct 3 ms 13048 KB Output is correct
23 Correct 3 ms 12880 KB Output is correct
24 Correct 2 ms 12880 KB Output is correct
25 Correct 3 ms 12880 KB Output is correct
26 Correct 3 ms 13048 KB Output is correct
27 Correct 4 ms 12880 KB Output is correct
28 Correct 3 ms 13048 KB Output is correct
29 Correct 31 ms 12972 KB Output is correct
30 Correct 24 ms 12880 KB Output is correct
31 Correct 26 ms 13044 KB Output is correct
32 Correct 15 ms 12880 KB Output is correct
33 Correct 5 ms 12880 KB Output is correct
34 Correct 44 ms 12880 KB Output is correct
35 Correct 49 ms 12880 KB Output is correct
36 Correct 36 ms 12880 KB Output is correct
37 Correct 27 ms 12880 KB Output is correct
38 Correct 1092 ms 14472 KB Output is correct
39 Correct 64 ms 31048 KB Output is correct
40 Correct 1429 ms 15436 KB Output is correct
41 Correct 1202 ms 14408 KB Output is correct
42 Correct 1091 ms 15664 KB Output is correct
43 Correct 31 ms 14160 KB Output is correct
44 Correct 944 ms 13320 KB Output is correct
45 Correct 139 ms 26192 KB Output is correct
46 Correct 140 ms 26388 KB Output is correct
47 Correct 164 ms 29020 KB Output is correct
48 Correct 173 ms 29008 KB Output is correct
49 Correct 151 ms 26440 KB Output is correct
50 Correct 171 ms 26420 KB Output is correct
51 Correct 51 ms 27208 KB Output is correct
52 Correct 51 ms 27060 KB Output is correct
53 Correct 846 ms 13508 KB Output is correct
54 Correct 109 ms 26192 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 12880 KB Output is correct
2 Correct 3 ms 12880 KB Output is correct
3 Correct 3 ms 12880 KB Output is correct
4 Correct 3 ms 12880 KB Output is correct
5 Correct 13 ms 12880 KB Output is correct
6 Correct 3 ms 12880 KB Output is correct
7 Correct 4 ms 12892 KB Output is correct
8 Correct 3 ms 12880 KB Output is correct
9 Correct 4 ms 12916 KB Output is correct
10 Correct 4 ms 12880 KB Output is correct
11 Correct 3 ms 12880 KB Output is correct
12 Correct 36 ms 12880 KB Output is correct
13 Correct 419 ms 12964 KB Output is correct
14 Correct 212 ms 12880 KB Output is correct
15 Correct 300 ms 12968 KB Output is correct
16 Execution timed out 5066 ms 25256 KB Time limit exceeded
17 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 12880 KB Output is correct
2 Correct 3 ms 12880 KB Output is correct
3 Correct 3 ms 12880 KB Output is correct
4 Correct 11 ms 12880 KB Output is correct
5 Correct 22 ms 12964 KB Output is correct
6 Correct 3 ms 12980 KB Output is correct
7 Correct 4 ms 12880 KB Output is correct
8 Correct 35 ms 12880 KB Output is correct
9 Correct 1058 ms 14444 KB Output is correct
10 Correct 69 ms 31208 KB Output is correct
11 Correct 16 ms 12880 KB Output is correct
12 Correct 344 ms 13896 KB Output is correct
13 Execution timed out 5063 ms 32976 KB Time limit exceeded
14 Halted 0 ms 0 KB -