Submission #922676

# Submission time Handle Problem Language Result Execution time Memory
922676 2024-02-05T23:50:15 Z hazzle Jail (JOI22_jail) C++17
61 / 100
5000 ms 36680 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

//#pragma GCC optimize("Ofast,unroll-loops")
//#pragma GCC target("avx,avx2,fma")

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define all(m) (m).begin(), (m).end()
#define rall(m) (m).rbegin(), (m).rend()
#define vec vector
#define sz(a) (int) (a).size()
#define mpp make_pair
#define mtt make_tuple

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair <ll, ll> pll;
typedef pair <int, int> pii;
typedef tuple <int, int, int> tui;

template <typename T>
using prq = priority_queue <T>;

template <typename T>
using pgq = priority_queue <T, vec <T>, greater <T>>;

template <typename T> bool umin(T &a, T b) { return a > b ? a = b, 1 : 0; }
template <typename T> bool umax(T &a, T b) { return a < b ? a = b, 1 : 0; }

const int L = 17;

inline int solve(){
     int n; cin >> n;
     vec <vec <int>> g(n);
     for (int i = 0; i < n - 1; ++i){
          int u, v;
          cin >> u >> v, --u, --v;
          g[u].push_back(v);
          g[v].push_back(u);
     }
     vec <vec <int>> up(n, vec <int> (L));
     vec <int> fi(n), fo(n);
     int tmr = 0;
     auto dfs = [&](auto &&dfs, int u, int p) -> void{
          up[u][0] = p;
          for (int i = 1; i < L; ++i){
               up[u][i] = up[up[u][i - 1]][i - 1];
          }
          fi[u] = tmr++;
          for (auto &v: g[u]) if (v != p){
               dfs(dfs, v, u);
          }
          fo[u] = tmr;
     };
     dfs(dfs, 0, 0);
     auto par = [&](int u, int v){
          return fi[u] <= fi[v] && fo[v] <= fo[u];
     };
     auto lca = [&](int u, int v){
          if (par(u, v)) return u;
          if (par(v, u)) return v;
          for (int i = L - 1; ~i; --i){
               if (!par(up[u][i], v)) u = up[u][i];
          }
          return up[u][0];
     };
     auto on_path = [&](int u, int v, int w){
          return par(u, v) && par(v, w);
     };
     int m; cin >> m;
     vec <int> s(m), t(m), lc(m);
     for (int i = 0; i < m; ++i){
          cin >> s[i] >> t[i], --s[i], --t[i];
          lc[i] = lca(s[i], t[i]);
     }
     vec <int> deg(m);
     vec <vec <int>> gg(m);
     for (int i = 0; i < m; ++i){
          for (int j = 0; j < m; ++j){
               if (i == j) continue;
               if (on_path(lc[i], t[j], s[i]) || on_path(lc[i], t[j], t[i]) ||
                   on_path(lc[j], s[i], s[j]) || on_path(lc[j], s[i], t[j])){
                    gg[i].push_back(j);
                    ++deg[j];
               }
          }
     }
     vec <int> bfs;
     for (int i = 0; i < m; ++i){
          if (deg[i] == 0) bfs.push_back(i);
     }
     for (int pt = 0; pt < sz(bfs); ++pt){
          int u = bfs[pt];
          for (auto &v: gg[u]){
               if (--deg[v] == 0){
                    bfs.push_back(v);
               }
          }
     }
     cout << (sz(bfs) == m ? "Yes\n" : "No\n");
     return 0;
}

inline void precalc(){}

signed main(){
     ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
     int tst = 1; cin >> tst;
     precalc();
     while(tst--) solve();
     return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 15 ms 348 KB Output is correct
5 Correct 33 ms 1104 KB Output is correct
6 Correct 2 ms 348 KB Output is correct
7 Correct 2 ms 536 KB Output is correct
8 Correct 3 ms 592 KB Output is correct
9 Correct 72 ms 3620 KB Output is correct
10 Correct 49 ms 26096 KB Output is correct
11 Correct 7 ms 604 KB Output is correct
12 Correct 71 ms 1528 KB Output is correct
13 Execution timed out 5087 ms 36680 KB Time limit exceeded
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 2 ms 348 KB Output is correct
4 Correct 2 ms 348 KB Output is correct
5 Correct 2 ms 464 KB Output is correct
6 Correct 2 ms 348 KB Output is correct
7 Correct 2 ms 512 KB Output is correct
8 Correct 2 ms 348 KB Output is correct
9 Correct 2 ms 348 KB Output is correct
10 Correct 2 ms 348 KB Output is correct
11 Correct 2 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 2 ms 348 KB Output is correct
4 Correct 2 ms 348 KB Output is correct
5 Correct 2 ms 464 KB Output is correct
6 Correct 2 ms 348 KB Output is correct
7 Correct 2 ms 512 KB Output is correct
8 Correct 2 ms 348 KB Output is correct
9 Correct 2 ms 348 KB Output is correct
10 Correct 2 ms 348 KB Output is correct
11 Correct 2 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 2 ms 348 KB Output is correct
17 Correct 2 ms 348 KB Output is correct
18 Correct 3 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 2 ms 348 KB Output is correct
21 Correct 2 ms 348 KB Output is correct
22 Correct 2 ms 348 KB Output is correct
23 Correct 0 ms 460 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 2 ms 532 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 2 ms 348 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 2 ms 348 KB Output is correct
4 Correct 2 ms 348 KB Output is correct
5 Correct 2 ms 464 KB Output is correct
6 Correct 2 ms 348 KB Output is correct
7 Correct 2 ms 512 KB Output is correct
8 Correct 2 ms 348 KB Output is correct
9 Correct 2 ms 348 KB Output is correct
10 Correct 2 ms 348 KB Output is correct
11 Correct 2 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 2 ms 348 KB Output is correct
17 Correct 2 ms 348 KB Output is correct
18 Correct 3 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 2 ms 348 KB Output is correct
21 Correct 2 ms 348 KB Output is correct
22 Correct 2 ms 348 KB Output is correct
23 Correct 0 ms 460 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 2 ms 532 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 2 ms 348 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 4 ms 348 KB Output is correct
30 Correct 4 ms 348 KB Output is correct
31 Correct 3 ms 348 KB Output is correct
32 Correct 3 ms 544 KB Output is correct
33 Correct 2 ms 344 KB Output is correct
34 Correct 4 ms 544 KB Output is correct
35 Correct 4 ms 344 KB Output is correct
36 Correct 4 ms 348 KB Output is correct
37 Correct 3 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 2 ms 348 KB Output is correct
4 Correct 2 ms 348 KB Output is correct
5 Correct 2 ms 464 KB Output is correct
6 Correct 2 ms 348 KB Output is correct
7 Correct 2 ms 512 KB Output is correct
8 Correct 2 ms 348 KB Output is correct
9 Correct 2 ms 348 KB Output is correct
10 Correct 2 ms 348 KB Output is correct
11 Correct 2 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 2 ms 348 KB Output is correct
17 Correct 2 ms 348 KB Output is correct
18 Correct 3 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 2 ms 348 KB Output is correct
21 Correct 2 ms 348 KB Output is correct
22 Correct 2 ms 348 KB Output is correct
23 Correct 0 ms 460 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 2 ms 532 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 2 ms 348 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 4 ms 348 KB Output is correct
30 Correct 4 ms 348 KB Output is correct
31 Correct 3 ms 348 KB Output is correct
32 Correct 3 ms 544 KB Output is correct
33 Correct 2 ms 344 KB Output is correct
34 Correct 4 ms 544 KB Output is correct
35 Correct 4 ms 344 KB Output is correct
36 Correct 4 ms 348 KB Output is correct
37 Correct 3 ms 348 KB Output is correct
38 Correct 66 ms 3624 KB Output is correct
39 Correct 48 ms 26196 KB Output is correct
40 Correct 116 ms 3012 KB Output is correct
41 Correct 114 ms 2596 KB Output is correct
42 Correct 113 ms 2964 KB Output is correct
43 Correct 37 ms 2612 KB Output is correct
44 Correct 40 ms 856 KB Output is correct
45 Correct 91 ms 21612 KB Output is correct
46 Correct 77 ms 21588 KB Output is correct
47 Correct 57 ms 23612 KB Output is correct
48 Correct 53 ms 23376 KB Output is correct
49 Correct 76 ms 21588 KB Output is correct
50 Correct 69 ms 21588 KB Output is correct
51 Correct 49 ms 22104 KB Output is correct
52 Correct 50 ms 22104 KB Output is correct
53 Correct 56 ms 1872 KB Output is correct
54 Correct 106 ms 21756 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 7 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 4 ms 348 KB Output is correct
13 Correct 57 ms 1000 KB Output is correct
14 Correct 53 ms 1232 KB Output is correct
15 Correct 50 ms 1104 KB Output is correct
16 Correct 1804 ms 22788 KB Output is correct
17 Execution timed out 5046 ms 25612 KB Time limit exceeded
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 15 ms 348 KB Output is correct
5 Correct 33 ms 1104 KB Output is correct
6 Correct 2 ms 348 KB Output is correct
7 Correct 2 ms 536 KB Output is correct
8 Correct 3 ms 592 KB Output is correct
9 Correct 72 ms 3620 KB Output is correct
10 Correct 49 ms 26096 KB Output is correct
11 Correct 7 ms 604 KB Output is correct
12 Correct 71 ms 1528 KB Output is correct
13 Execution timed out 5087 ms 36680 KB Time limit exceeded
14 Halted 0 ms 0 KB -