Submission #875662

# Submission time Handle Problem Language Result Execution time Memory
875662 2023-11-20T10:36:30 Z vjudge1 Jail (JOI22_jail) C++17
49 / 100
5000 ms 282184 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 5e5 + 10, MOD = 998244353;

vector<int> g[N],x[N];
int timer = 0,tin[N],tout[N],n,m,s[N],t[N],blocked[N],c[N],pp[N];
bool used[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 can(int i){
    for(int j:x[i]){
        if(j != s[i] && used[j]) return false;
    }
    if(c[t[i]] > 1) return false;
    return true;
}
void test(){
    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);
        used[x] = used[y] = c[x] = c[y] = 0;
    }
    dfs(1);
    cin >> m;
    for(int i = 1;i <= m;i++){
        blocked[i] = 0;
    }
    for(int i = 1;i <= m;++i){
        cin >> s[i] >> t[i];
        used[s[i]] = 1;

        x[i] = path(s[i],t[i]);
        for(auto j:x[i]){
            c[j]++;
        }
    }
    for(int i = 1;i <= m;i++){
        bool ok = false;
        for(int j = 1;j <= m;j++){
            if(blocked[j] || !can(j)) continue;
            blocked[j] = 1;
            for(auto k:x[j]){
                c[k]--;
            }
            ok = 1;
            used[s[j]] = 0;
            used[t[j]] = 1;
            break;
        }
        if(!ok){
            cout << "No\n";
            return;
        }
    }
    cout << "Yes\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: In function 'void test()':
jail.cpp:50:34: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   50 |         used[x] = used[y] = c[x] = c[y] = 0;
      |                             ~~~~~^~~~~~~~~~
jail.cpp: At global scope:
jail.cpp:86:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   86 | main()
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 10 ms 37720 KB Output is correct
2 Correct 7 ms 37724 KB Output is correct
3 Correct 7 ms 37896 KB Output is correct
4 Correct 13 ms 37724 KB Output is correct
5 Correct 21 ms 37724 KB Output is correct
6 Correct 8 ms 37724 KB Output is correct
7 Correct 8 ms 37980 KB Output is correct
8 Correct 10 ms 37980 KB Output is correct
9 Correct 548 ms 54676 KB Output is correct
10 Execution timed out 5061 ms 282184 KB Time limit exceeded
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 37724 KB Output is correct
2 Correct 8 ms 37724 KB Output is correct
3 Correct 7 ms 37724 KB Output is correct
4 Correct 9 ms 37884 KB Output is correct
5 Correct 8 ms 37724 KB Output is correct
6 Correct 8 ms 37724 KB Output is correct
7 Correct 8 ms 37720 KB Output is correct
8 Correct 8 ms 37724 KB Output is correct
9 Correct 9 ms 37724 KB Output is correct
10 Correct 8 ms 37964 KB Output is correct
11 Correct 9 ms 37724 KB Output is correct
12 Correct 7 ms 37808 KB Output is correct
13 Correct 7 ms 37724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 37724 KB Output is correct
2 Correct 8 ms 37724 KB Output is correct
3 Correct 7 ms 37724 KB Output is correct
4 Correct 9 ms 37884 KB Output is correct
5 Correct 8 ms 37724 KB Output is correct
6 Correct 8 ms 37724 KB Output is correct
7 Correct 8 ms 37720 KB Output is correct
8 Correct 8 ms 37724 KB Output is correct
9 Correct 9 ms 37724 KB Output is correct
10 Correct 8 ms 37964 KB Output is correct
11 Correct 9 ms 37724 KB Output is correct
12 Correct 7 ms 37808 KB Output is correct
13 Correct 7 ms 37724 KB Output is correct
14 Correct 8 ms 37876 KB Output is correct
15 Correct 7 ms 37724 KB Output is correct
16 Correct 8 ms 37980 KB Output is correct
17 Correct 7 ms 37720 KB Output is correct
18 Correct 8 ms 37724 KB Output is correct
19 Correct 8 ms 37948 KB Output is correct
20 Correct 9 ms 37968 KB Output is correct
21 Correct 8 ms 37724 KB Output is correct
22 Correct 8 ms 37980 KB Output is correct
23 Correct 7 ms 37720 KB Output is correct
24 Correct 7 ms 37720 KB Output is correct
25 Correct 8 ms 37968 KB Output is correct
26 Correct 7 ms 37724 KB Output is correct
27 Correct 8 ms 37724 KB Output is correct
28 Correct 7 ms 37976 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 37724 KB Output is correct
2 Correct 8 ms 37724 KB Output is correct
3 Correct 7 ms 37724 KB Output is correct
4 Correct 9 ms 37884 KB Output is correct
5 Correct 8 ms 37724 KB Output is correct
6 Correct 8 ms 37724 KB Output is correct
7 Correct 8 ms 37720 KB Output is correct
8 Correct 8 ms 37724 KB Output is correct
9 Correct 9 ms 37724 KB Output is correct
10 Correct 8 ms 37964 KB Output is correct
11 Correct 9 ms 37724 KB Output is correct
12 Correct 7 ms 37808 KB Output is correct
13 Correct 7 ms 37724 KB Output is correct
14 Correct 8 ms 37876 KB Output is correct
15 Correct 7 ms 37724 KB Output is correct
16 Correct 8 ms 37980 KB Output is correct
17 Correct 7 ms 37720 KB Output is correct
18 Correct 8 ms 37724 KB Output is correct
19 Correct 8 ms 37948 KB Output is correct
20 Correct 9 ms 37968 KB Output is correct
21 Correct 8 ms 37724 KB Output is correct
22 Correct 8 ms 37980 KB Output is correct
23 Correct 7 ms 37720 KB Output is correct
24 Correct 7 ms 37720 KB Output is correct
25 Correct 8 ms 37968 KB Output is correct
26 Correct 7 ms 37724 KB Output is correct
27 Correct 8 ms 37724 KB Output is correct
28 Correct 7 ms 37976 KB Output is correct
29 Correct 9 ms 37980 KB Output is correct
30 Correct 8 ms 37724 KB Output is correct
31 Correct 9 ms 37980 KB Output is correct
32 Correct 8 ms 37976 KB Output is correct
33 Correct 8 ms 37724 KB Output is correct
34 Correct 9 ms 37724 KB Output is correct
35 Correct 8 ms 37980 KB Output is correct
36 Correct 8 ms 37976 KB Output is correct
37 Correct 8 ms 37816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 37724 KB Output is correct
2 Correct 8 ms 37724 KB Output is correct
3 Correct 7 ms 37724 KB Output is correct
4 Correct 9 ms 37884 KB Output is correct
5 Correct 8 ms 37724 KB Output is correct
6 Correct 8 ms 37724 KB Output is correct
7 Correct 8 ms 37720 KB Output is correct
8 Correct 8 ms 37724 KB Output is correct
9 Correct 9 ms 37724 KB Output is correct
10 Correct 8 ms 37964 KB Output is correct
11 Correct 9 ms 37724 KB Output is correct
12 Correct 7 ms 37808 KB Output is correct
13 Correct 7 ms 37724 KB Output is correct
14 Correct 8 ms 37876 KB Output is correct
15 Correct 7 ms 37724 KB Output is correct
16 Correct 8 ms 37980 KB Output is correct
17 Correct 7 ms 37720 KB Output is correct
18 Correct 8 ms 37724 KB Output is correct
19 Correct 8 ms 37948 KB Output is correct
20 Correct 9 ms 37968 KB Output is correct
21 Correct 8 ms 37724 KB Output is correct
22 Correct 8 ms 37980 KB Output is correct
23 Correct 7 ms 37720 KB Output is correct
24 Correct 7 ms 37720 KB Output is correct
25 Correct 8 ms 37968 KB Output is correct
26 Correct 7 ms 37724 KB Output is correct
27 Correct 8 ms 37724 KB Output is correct
28 Correct 7 ms 37976 KB Output is correct
29 Correct 9 ms 37980 KB Output is correct
30 Correct 8 ms 37724 KB Output is correct
31 Correct 9 ms 37980 KB Output is correct
32 Correct 8 ms 37976 KB Output is correct
33 Correct 8 ms 37724 KB Output is correct
34 Correct 9 ms 37724 KB Output is correct
35 Correct 8 ms 37980 KB Output is correct
36 Correct 8 ms 37976 KB Output is correct
37 Correct 8 ms 37816 KB Output is correct
38 Correct 599 ms 54524 KB Output is correct
39 Execution timed out 5077 ms 282108 KB Time limit exceeded
40 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 37724 KB Output is correct
2 Correct 7 ms 37724 KB Output is correct
3 Correct 7 ms 37724 KB Output is correct
4 Correct 7 ms 37724 KB Output is correct
5 Correct 10 ms 37724 KB Output is correct
6 Correct 7 ms 37724 KB Output is correct
7 Correct 8 ms 37724 KB Output is correct
8 Correct 9 ms 37820 KB Output is correct
9 Correct 7 ms 37724 KB Output is correct
10 Correct 8 ms 37724 KB Output is correct
11 Correct 8 ms 37720 KB Output is correct
12 Correct 8 ms 37980 KB Output is correct
13 Correct 19 ms 37980 KB Output is correct
14 Correct 30 ms 37724 KB Output is correct
15 Correct 24 ms 37964 KB Output is correct
16 Correct 411 ms 43348 KB Output is correct
17 Correct 77 ms 48464 KB Output is correct
18 Correct 93 ms 56148 KB Output is correct
19 Correct 659 ms 44476 KB Output is correct
20 Correct 1780 ms 44628 KB Output is correct
21 Correct 1183 ms 44540 KB Output is correct
22 Correct 432 ms 49304 KB Output is correct
23 Correct 69 ms 49024 KB Output is correct
24 Correct 1295 ms 49872 KB Output is correct
25 Correct 2058 ms 50096 KB Output is correct
26 Correct 2219 ms 50028 KB Output is correct
27 Execution timed out 5032 ms 45804 KB Time limit exceeded
28 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 10 ms 37720 KB Output is correct
2 Correct 7 ms 37724 KB Output is correct
3 Correct 7 ms 37896 KB Output is correct
4 Correct 13 ms 37724 KB Output is correct
5 Correct 21 ms 37724 KB Output is correct
6 Correct 8 ms 37724 KB Output is correct
7 Correct 8 ms 37980 KB Output is correct
8 Correct 10 ms 37980 KB Output is correct
9 Correct 548 ms 54676 KB Output is correct
10 Execution timed out 5061 ms 282184 KB Time limit exceeded
11 Halted 0 ms 0 KB -