Submission #632608

# Submission time Handle Problem Language Result Execution time Memory
632608 2022-08-20T12:13:06 Z Mahdi Jail (JOI22_jail) C++17
72 / 100
5000 ms 863100 KB
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
#define all(v) v.begin(), v.end()
#define F first
#define S second
typedef pair<int, int> pii;
typedef long long ll;
const int N=12e4+5;
int n, m, s[N], t[N], pr[N][18], dis[N];
vector<int>g[N], h[N], nd;
bool mk[N];
pii st[N];

void dfs(const int &v, const int &p=-1){
    for(int u: g[v]){
        if(u!=p){
            pr[u][0]=v;
            for(int i=1;i<17;++i)
                pr[u][i]=pr[pr[u][i-1]][i-1];
            dis[u]=dis[v]+1;
            dfs(u, v);
        }   
    }
}

int par(int v, int p){
    for(int i=0;p>0;++i){
        if(p&1)
            v=pr[v][i];
        p>>=1;
    }
    return v;
}

int lca(int u, int v){
    u=par(u, dis[u]-dis[v]);
    v=par(v, dis[v]-dis[u]);
    if(u==v)
        return v;
    for(int i=16;i>=0;--i){
        if(pr[u][i]!=pr[v][i]){
            v=pr[v][i];
            u=pr[u][i];
        }
    }
    return pr[v][0];
}

void sfd(const int &v){
    mk[v]=1;
    for(int u: h[v]){
        if(!mk[u])
            sfd(u);
    }
    nd.push_back(v);
}

void sol(){
    cin>>n;
    for(int i=0;i<n;++i)
        g[i].clear();
    for(int i=1;i<n;++i){
        int u, v;
        cin>>u>>v;
        g[--u].push_back(--v);
        g[v].push_back(u);
    }
    cin>>m;
    memset(s, -1, 4*n);
    memset(t, -1, 4*n);
    for(int i=0;i<m;++i){
        int u, v;
        cin>>u>>v;
        s[--u]=i;
        t[--v]=i;
        st[i]={u, v};
    }
    dfs(0);
    for(int i=0;i<m;++i)
        h[i].clear();
    for(int i=0;i<m;++i){
        int u=st[i].F;
        int v=st[i].S;
        int w=lca(u, v);
        int x=u;
        while(true){
            if(s[x]!=-1 && s[x]!=i)
                h[s[x]].push_back(i);
            if(t[x]!=-1 && t[x]!=i)
                h[i].push_back(t[x]);
            if(x==w)
                break;
            x=pr[x][0];
        }
        x=v;
        while(true){
            if(s[x]!=-1 && s[x]!=i)
                h[s[x]].push_back(i);
            if(t[x]!=-1 && t[x]!=i)
                h[i].push_back(t[x]);
            if(x==w)
                break;
            x=pr[x][0];
        }
    }
    nd.clear();
    memset(mk, 0, m);
    for(int i=0;i<m;++i){
        if(!mk[i])
            sfd(i);
    }
    memset(mk, 0, m);
    for(int i=0;i<m;++i){
        mk[nd[i]]=1;
        for(int u: h[nd[i]]){
            if(!mk[u]){
                cout<<"No\n";
                return;
            }
        }
    }
    cout<<"Yes\n";
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    int T;
    cin>>T;
    while(T--)
        sol();
}

Compilation message

In file included from /usr/include/string.h:495,
                 from /usr/include/c++/10/cstring:42,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:48,
                 from jail.cpp:1:
In function 'void* memset(void*, int, size_t)',
    inlined from 'void sol()' at jail.cpp:108:11:
/usr/include/x86_64-linux-gnu/bits/string_fortified.h:71:33: warning: 'void* __builtin___memset_chk(void*, int, long unsigned int, long unsigned int)' specified size between 18446744071562067968 and 18446744073709551615 exceeds maximum object size 9223372036854775807 [-Wstringop-overflow=]
   71 |   return __builtin___memset_chk (__dest, __ch, __len, __bos0 (__dest));
      |          ~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5972 KB Output is correct
2 Correct 3 ms 5972 KB Output is correct
3 Correct 3 ms 5976 KB Output is correct
4 Correct 11 ms 6356 KB Output is correct
5 Correct 20 ms 6752 KB Output is correct
6 Correct 4 ms 5980 KB Output is correct
7 Correct 4 ms 5972 KB Output is correct
8 Correct 5 ms 6112 KB Output is correct
9 Correct 78 ms 10424 KB Output is correct
10 Correct 403 ms 33592 KB Output is correct
11 Correct 7 ms 6056 KB Output is correct
12 Correct 38 ms 6988 KB Output is correct
13 Correct 126 ms 63308 KB Output is correct
14 Correct 157 ms 77208 KB Output is correct
15 Execution timed out 5098 ms 863100 KB Time limit exceeded
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5972 KB Output is correct
2 Correct 3 ms 5972 KB Output is correct
3 Correct 4 ms 5980 KB Output is correct
4 Correct 5 ms 5972 KB Output is correct
5 Correct 4 ms 5972 KB Output is correct
6 Correct 4 ms 5972 KB Output is correct
7 Correct 4 ms 5972 KB Output is correct
8 Correct 4 ms 5980 KB Output is correct
9 Correct 4 ms 5972 KB Output is correct
10 Correct 4 ms 6048 KB Output is correct
11 Correct 4 ms 5972 KB Output is correct
12 Correct 3 ms 5972 KB Output is correct
13 Correct 4 ms 5948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5972 KB Output is correct
2 Correct 3 ms 5972 KB Output is correct
3 Correct 4 ms 5980 KB Output is correct
4 Correct 5 ms 5972 KB Output is correct
5 Correct 4 ms 5972 KB Output is correct
6 Correct 4 ms 5972 KB Output is correct
7 Correct 4 ms 5972 KB Output is correct
8 Correct 4 ms 5980 KB Output is correct
9 Correct 4 ms 5972 KB Output is correct
10 Correct 4 ms 6048 KB Output is correct
11 Correct 4 ms 5972 KB Output is correct
12 Correct 3 ms 5972 KB Output is correct
13 Correct 4 ms 5948 KB Output is correct
14 Correct 4 ms 5972 KB Output is correct
15 Correct 3 ms 5972 KB Output is correct
16 Correct 4 ms 5972 KB Output is correct
17 Correct 4 ms 5972 KB Output is correct
18 Correct 4 ms 5972 KB Output is correct
19 Correct 4 ms 5972 KB Output is correct
20 Correct 4 ms 5972 KB Output is correct
21 Correct 4 ms 5980 KB Output is correct
22 Correct 4 ms 5972 KB Output is correct
23 Correct 3 ms 5968 KB Output is correct
24 Correct 4 ms 5972 KB Output is correct
25 Correct 5 ms 5972 KB Output is correct
26 Correct 3 ms 5968 KB Output is correct
27 Correct 4 ms 5972 KB Output is correct
28 Correct 3 ms 5972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5972 KB Output is correct
2 Correct 3 ms 5972 KB Output is correct
3 Correct 4 ms 5980 KB Output is correct
4 Correct 5 ms 5972 KB Output is correct
5 Correct 4 ms 5972 KB Output is correct
6 Correct 4 ms 5972 KB Output is correct
7 Correct 4 ms 5972 KB Output is correct
8 Correct 4 ms 5980 KB Output is correct
9 Correct 4 ms 5972 KB Output is correct
10 Correct 4 ms 6048 KB Output is correct
11 Correct 4 ms 5972 KB Output is correct
12 Correct 3 ms 5972 KB Output is correct
13 Correct 4 ms 5948 KB Output is correct
14 Correct 4 ms 5972 KB Output is correct
15 Correct 3 ms 5972 KB Output is correct
16 Correct 4 ms 5972 KB Output is correct
17 Correct 4 ms 5972 KB Output is correct
18 Correct 4 ms 5972 KB Output is correct
19 Correct 4 ms 5972 KB Output is correct
20 Correct 4 ms 5972 KB Output is correct
21 Correct 4 ms 5980 KB Output is correct
22 Correct 4 ms 5972 KB Output is correct
23 Correct 3 ms 5968 KB Output is correct
24 Correct 4 ms 5972 KB Output is correct
25 Correct 5 ms 5972 KB Output is correct
26 Correct 3 ms 5968 KB Output is correct
27 Correct 4 ms 5972 KB Output is correct
28 Correct 3 ms 5972 KB Output is correct
29 Correct 6 ms 6112 KB Output is correct
30 Correct 5 ms 5984 KB Output is correct
31 Correct 4 ms 5976 KB Output is correct
32 Correct 4 ms 5972 KB Output is correct
33 Correct 5 ms 5984 KB Output is correct
34 Correct 4 ms 5984 KB Output is correct
35 Correct 6 ms 6112 KB Output is correct
36 Correct 5 ms 6100 KB Output is correct
37 Correct 4 ms 5980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5972 KB Output is correct
2 Correct 3 ms 5972 KB Output is correct
3 Correct 4 ms 5980 KB Output is correct
4 Correct 5 ms 5972 KB Output is correct
5 Correct 4 ms 5972 KB Output is correct
6 Correct 4 ms 5972 KB Output is correct
7 Correct 4 ms 5972 KB Output is correct
8 Correct 4 ms 5980 KB Output is correct
9 Correct 4 ms 5972 KB Output is correct
10 Correct 4 ms 6048 KB Output is correct
11 Correct 4 ms 5972 KB Output is correct
12 Correct 3 ms 5972 KB Output is correct
13 Correct 4 ms 5948 KB Output is correct
14 Correct 4 ms 5972 KB Output is correct
15 Correct 3 ms 5972 KB Output is correct
16 Correct 4 ms 5972 KB Output is correct
17 Correct 4 ms 5972 KB Output is correct
18 Correct 4 ms 5972 KB Output is correct
19 Correct 4 ms 5972 KB Output is correct
20 Correct 4 ms 5972 KB Output is correct
21 Correct 4 ms 5980 KB Output is correct
22 Correct 4 ms 5972 KB Output is correct
23 Correct 3 ms 5968 KB Output is correct
24 Correct 4 ms 5972 KB Output is correct
25 Correct 5 ms 5972 KB Output is correct
26 Correct 3 ms 5968 KB Output is correct
27 Correct 4 ms 5972 KB Output is correct
28 Correct 3 ms 5972 KB Output is correct
29 Correct 6 ms 6112 KB Output is correct
30 Correct 5 ms 5984 KB Output is correct
31 Correct 4 ms 5976 KB Output is correct
32 Correct 4 ms 5972 KB Output is correct
33 Correct 5 ms 5984 KB Output is correct
34 Correct 4 ms 5984 KB Output is correct
35 Correct 6 ms 6112 KB Output is correct
36 Correct 5 ms 6100 KB Output is correct
37 Correct 4 ms 5980 KB Output is correct
38 Correct 84 ms 10340 KB Output is correct
39 Correct 419 ms 33612 KB Output is correct
40 Correct 59 ms 9164 KB Output is correct
41 Correct 29 ms 7884 KB Output is correct
42 Correct 46 ms 9276 KB Output is correct
43 Correct 25 ms 8012 KB Output is correct
44 Correct 12 ms 6356 KB Output is correct
45 Correct 62 ms 20952 KB Output is correct
46 Correct 59 ms 21008 KB Output is correct
47 Correct 125 ms 26512 KB Output is correct
48 Correct 122 ms 26764 KB Output is correct
49 Correct 59 ms 21288 KB Output is correct
50 Correct 59 ms 21260 KB Output is correct
51 Correct 44 ms 22860 KB Output is correct
52 Correct 44 ms 22844 KB Output is correct
53 Correct 11 ms 7268 KB Output is correct
54 Correct 70 ms 21000 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5968 KB Output is correct
2 Correct 3 ms 5972 KB Output is correct
3 Correct 3 ms 5964 KB Output is correct
4 Correct 3 ms 5972 KB Output is correct
5 Correct 9 ms 6108 KB Output is correct
6 Correct 4 ms 5984 KB Output is correct
7 Correct 3 ms 5972 KB Output is correct
8 Correct 3 ms 5972 KB Output is correct
9 Correct 3 ms 5972 KB Output is correct
10 Correct 4 ms 5968 KB Output is correct
11 Correct 3 ms 5972 KB Output is correct
12 Correct 4 ms 5984 KB Output is correct
13 Correct 19 ms 6640 KB Output is correct
14 Correct 28 ms 6884 KB Output is correct
15 Correct 25 ms 6712 KB Output is correct
16 Correct 82 ms 21732 KB Output is correct
17 Correct 139 ms 28724 KB Output is correct
18 Correct 329 ms 52800 KB Output is correct
19 Correct 79 ms 21924 KB Output is correct
20 Correct 76 ms 21936 KB Output is correct
21 Correct 71 ms 21904 KB Output is correct
22 Correct 111 ms 29052 KB Output is correct
23 Correct 100 ms 29308 KB Output is correct
24 Correct 97 ms 28940 KB Output is correct
25 Correct 95 ms 29012 KB Output is correct
26 Correct 96 ms 28964 KB Output is correct
27 Correct 130 ms 29256 KB Output is correct
28 Correct 129 ms 31708 KB Output is correct
29 Correct 134 ms 30016 KB Output is correct
30 Correct 87 ms 26060 KB Output is correct
31 Correct 93 ms 26312 KB Output is correct
32 Correct 93 ms 25548 KB Output is correct
33 Correct 95 ms 26344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5972 KB Output is correct
2 Correct 3 ms 5972 KB Output is correct
3 Correct 3 ms 5976 KB Output is correct
4 Correct 11 ms 6356 KB Output is correct
5 Correct 20 ms 6752 KB Output is correct
6 Correct 4 ms 5980 KB Output is correct
7 Correct 4 ms 5972 KB Output is correct
8 Correct 5 ms 6112 KB Output is correct
9 Correct 78 ms 10424 KB Output is correct
10 Correct 403 ms 33592 KB Output is correct
11 Correct 7 ms 6056 KB Output is correct
12 Correct 38 ms 6988 KB Output is correct
13 Correct 126 ms 63308 KB Output is correct
14 Correct 157 ms 77208 KB Output is correct
15 Execution timed out 5098 ms 863100 KB Time limit exceeded
16 Halted 0 ms 0 KB -