Submission #927298

# Submission time Handle Problem Language Result Execution time Memory
927298 2024-02-14T16:28:18 Z andrei_boaca Jail (JOI22_jail) C++17
61 / 100
5000 ms 32832 KB
#include <bits/stdc++.h>

using namespace std;
typedef pair<int,int> pii;
int t,n,m,A[120005],B[120005],in[120005],out[120005],timp,par[120005],niv[1200005],dp[21][120005];
vector<int> muchii[120005];
vector<int> edges[120005];
map<pii,int> f;
bool isancestor(int a,int b)
{
    return in[a]<=in[b]&&out[a]>=out[b];
}
int LCA(int a,int b)
{
    if(niv[a]>niv[b])
        swap(a,b);
    if(isancestor(a,b))
        return a;
    for(int i=18;i>=0;i--)
        if(dp[i][a]!=0&&!isancestor(dp[i][a],b))
            a=dp[i][a];
    return par[a];
}
int dist(int a,int b)
{
    int lca=LCA(a,b);
    return niv[a]+niv[b]-2*niv[lca];
}
void dfs(int nod)
{
    timp++;
    in[nod]=timp;
    dp[0][nod]=par[nod];
    for(int i=1;i<=18;i++)
        dp[i][nod]=dp[i-1][dp[i-1][nod]];
    for(int i:muchii[nod])
        if(i!=par[nod])
        {
            par[i]=nod;
            niv[i]=niv[nod]+1;
            dfs(i);
        }
    out[nod]=timp;
}
bool onchain(int x,int a,int b)
{
    return dist(a,x)+dist(x,b)==dist(a,b);
}
int grad[120005];
void solve()
{
    cin>>n;
    timp=0;
    for(int i=1;i<=n;i++)
        muchii[i].clear();
    for(int i=1;i<n;i++)
    {
        int a,b;
        cin>>a>>b;
        muchii[a].push_back(b);
        muchii[b].push_back(a);
    }
    dfs(1);
    cin>>m;
    for(int i=1;i<=m;i++)
    {
        cin>>A[i]>>B[i];
        edges[i].clear();
        grad[i]=0;
    }
    f.clear();
    for(int i=1;i<=m;i++)
        for(int j=1;j<=m;j++)
            if(i!=j)
            {
                if(onchain(A[j],A[i],B[i]))
                {
                    edges[j].push_back(i);
                    grad[i]++;
                }
                if(onchain(B[j],A[i],B[i]))
                {
                    edges[i].push_back(j);
                    grad[j]++;
                }
            }
    queue<int> coada;
    int cnt=0;
    for(int i=1;i<=m;i++)
        if(grad[i]==0)
            coada.push(i);
    while(!coada.empty())
    {
        int nod=coada.front();
        coada.pop();
        cnt++;
        for(int i:edges[nod])
        {
            grad[i]--;
            if(grad[i]==0)
                coada.push(i);
        }
    }
    if(cnt==m)
        cout<<"Yes\n";
    else
        cout<<"No\n";
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin>>t;
    while(t--)
        solve();
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 18780 KB Output is correct
2 Correct 3 ms 18780 KB Output is correct
3 Correct 3 ms 18780 KB Output is correct
4 Correct 9 ms 18780 KB Output is correct
5 Correct 17 ms 18776 KB Output is correct
6 Correct 4 ms 18780 KB Output is correct
7 Correct 4 ms 18944 KB Output is correct
8 Correct 7 ms 19036 KB Output is correct
9 Correct 118 ms 21432 KB Output is correct
10 Correct 48 ms 31568 KB Output is correct
11 Correct 8 ms 18780 KB Output is correct
12 Correct 72 ms 19028 KB Output is correct
13 Execution timed out 5043 ms 32832 KB Time limit exceeded
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 18776 KB Output is correct
2 Correct 3 ms 18780 KB Output is correct
3 Correct 3 ms 18780 KB Output is correct
4 Correct 4 ms 18776 KB Output is correct
5 Correct 4 ms 18780 KB Output is correct
6 Correct 4 ms 18776 KB Output is correct
7 Correct 3 ms 18936 KB Output is correct
8 Correct 3 ms 18780 KB Output is correct
9 Correct 4 ms 18780 KB Output is correct
10 Correct 5 ms 18780 KB Output is correct
11 Correct 4 ms 18780 KB Output is correct
12 Correct 3 ms 18780 KB Output is correct
13 Correct 4 ms 18780 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 18776 KB Output is correct
2 Correct 3 ms 18780 KB Output is correct
3 Correct 3 ms 18780 KB Output is correct
4 Correct 4 ms 18776 KB Output is correct
5 Correct 4 ms 18780 KB Output is correct
6 Correct 4 ms 18776 KB Output is correct
7 Correct 3 ms 18936 KB Output is correct
8 Correct 3 ms 18780 KB Output is correct
9 Correct 4 ms 18780 KB Output is correct
10 Correct 5 ms 18780 KB Output is correct
11 Correct 4 ms 18780 KB Output is correct
12 Correct 3 ms 18780 KB Output is correct
13 Correct 4 ms 18780 KB Output is correct
14 Correct 3 ms 18780 KB Output is correct
15 Correct 4 ms 18780 KB Output is correct
16 Correct 4 ms 18776 KB Output is correct
17 Correct 4 ms 18960 KB Output is correct
18 Correct 4 ms 18780 KB Output is correct
19 Correct 3 ms 18780 KB Output is correct
20 Correct 4 ms 19032 KB Output is correct
21 Correct 3 ms 18780 KB Output is correct
22 Correct 5 ms 19036 KB Output is correct
23 Correct 3 ms 18780 KB Output is correct
24 Correct 3 ms 18780 KB Output is correct
25 Correct 4 ms 18780 KB Output is correct
26 Correct 3 ms 18952 KB Output is correct
27 Correct 4 ms 18776 KB Output is correct
28 Correct 3 ms 18780 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 18776 KB Output is correct
2 Correct 3 ms 18780 KB Output is correct
3 Correct 3 ms 18780 KB Output is correct
4 Correct 4 ms 18776 KB Output is correct
5 Correct 4 ms 18780 KB Output is correct
6 Correct 4 ms 18776 KB Output is correct
7 Correct 3 ms 18936 KB Output is correct
8 Correct 3 ms 18780 KB Output is correct
9 Correct 4 ms 18780 KB Output is correct
10 Correct 5 ms 18780 KB Output is correct
11 Correct 4 ms 18780 KB Output is correct
12 Correct 3 ms 18780 KB Output is correct
13 Correct 4 ms 18780 KB Output is correct
14 Correct 3 ms 18780 KB Output is correct
15 Correct 4 ms 18780 KB Output is correct
16 Correct 4 ms 18776 KB Output is correct
17 Correct 4 ms 18960 KB Output is correct
18 Correct 4 ms 18780 KB Output is correct
19 Correct 3 ms 18780 KB Output is correct
20 Correct 4 ms 19032 KB Output is correct
21 Correct 3 ms 18780 KB Output is correct
22 Correct 5 ms 19036 KB Output is correct
23 Correct 3 ms 18780 KB Output is correct
24 Correct 3 ms 18780 KB Output is correct
25 Correct 4 ms 18780 KB Output is correct
26 Correct 3 ms 18952 KB Output is correct
27 Correct 4 ms 18776 KB Output is correct
28 Correct 3 ms 18780 KB Output is correct
29 Correct 8 ms 19288 KB Output is correct
30 Correct 19 ms 18968 KB Output is correct
31 Correct 15 ms 18780 KB Output is correct
32 Correct 11 ms 18780 KB Output is correct
33 Correct 4 ms 18780 KB Output is correct
34 Correct 28 ms 18952 KB Output is correct
35 Correct 38 ms 19136 KB Output is correct
36 Correct 25 ms 18780 KB Output is correct
37 Correct 18 ms 18780 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 18776 KB Output is correct
2 Correct 3 ms 18780 KB Output is correct
3 Correct 3 ms 18780 KB Output is correct
4 Correct 4 ms 18776 KB Output is correct
5 Correct 4 ms 18780 KB Output is correct
6 Correct 4 ms 18776 KB Output is correct
7 Correct 3 ms 18936 KB Output is correct
8 Correct 3 ms 18780 KB Output is correct
9 Correct 4 ms 18780 KB Output is correct
10 Correct 5 ms 18780 KB Output is correct
11 Correct 4 ms 18780 KB Output is correct
12 Correct 3 ms 18780 KB Output is correct
13 Correct 4 ms 18780 KB Output is correct
14 Correct 3 ms 18780 KB Output is correct
15 Correct 4 ms 18780 KB Output is correct
16 Correct 4 ms 18776 KB Output is correct
17 Correct 4 ms 18960 KB Output is correct
18 Correct 4 ms 18780 KB Output is correct
19 Correct 3 ms 18780 KB Output is correct
20 Correct 4 ms 19032 KB Output is correct
21 Correct 3 ms 18780 KB Output is correct
22 Correct 5 ms 19036 KB Output is correct
23 Correct 3 ms 18780 KB Output is correct
24 Correct 3 ms 18780 KB Output is correct
25 Correct 4 ms 18780 KB Output is correct
26 Correct 3 ms 18952 KB Output is correct
27 Correct 4 ms 18776 KB Output is correct
28 Correct 3 ms 18780 KB Output is correct
29 Correct 8 ms 19288 KB Output is correct
30 Correct 19 ms 18968 KB Output is correct
31 Correct 15 ms 18780 KB Output is correct
32 Correct 11 ms 18780 KB Output is correct
33 Correct 4 ms 18780 KB Output is correct
34 Correct 28 ms 18952 KB Output is correct
35 Correct 38 ms 19136 KB Output is correct
36 Correct 25 ms 18780 KB Output is correct
37 Correct 18 ms 18780 KB Output is correct
38 Correct 114 ms 21380 KB Output is correct
39 Correct 51 ms 31604 KB Output is correct
40 Correct 922 ms 20228 KB Output is correct
41 Correct 870 ms 19412 KB Output is correct
42 Correct 648 ms 20728 KB Output is correct
43 Correct 27 ms 19304 KB Output is correct
44 Correct 617 ms 19080 KB Output is correct
45 Correct 119 ms 22608 KB Output is correct
46 Correct 122 ms 22748 KB Output is correct
47 Correct 192 ms 26460 KB Output is correct
48 Correct 208 ms 26452 KB Output is correct
49 Correct 162 ms 23160 KB Output is correct
50 Correct 181 ms 22904 KB Output is correct
51 Correct 52 ms 23900 KB Output is correct
52 Correct 49 ms 23896 KB Output is correct
53 Correct 561 ms 19472 KB Output is correct
54 Correct 107 ms 22616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 18776 KB Output is correct
2 Correct 3 ms 18780 KB Output is correct
3 Correct 3 ms 18780 KB Output is correct
4 Correct 3 ms 18780 KB Output is correct
5 Correct 7 ms 18780 KB Output is correct
6 Correct 3 ms 18776 KB Output is correct
7 Correct 3 ms 18780 KB Output is correct
8 Correct 3 ms 18780 KB Output is correct
9 Correct 3 ms 18780 KB Output is correct
10 Correct 3 ms 18780 KB Output is correct
11 Correct 3 ms 18780 KB Output is correct
12 Correct 31 ms 18780 KB Output is correct
13 Correct 301 ms 18780 KB Output is correct
14 Correct 153 ms 18944 KB Output is correct
15 Correct 204 ms 18936 KB Output is correct
16 Execution timed out 5038 ms 23476 KB Time limit exceeded
17 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 18780 KB Output is correct
2 Correct 3 ms 18780 KB Output is correct
3 Correct 3 ms 18780 KB Output is correct
4 Correct 9 ms 18780 KB Output is correct
5 Correct 17 ms 18776 KB Output is correct
6 Correct 4 ms 18780 KB Output is correct
7 Correct 4 ms 18944 KB Output is correct
8 Correct 7 ms 19036 KB Output is correct
9 Correct 118 ms 21432 KB Output is correct
10 Correct 48 ms 31568 KB Output is correct
11 Correct 8 ms 18780 KB Output is correct
12 Correct 72 ms 19028 KB Output is correct
13 Execution timed out 5043 ms 32832 KB Time limit exceeded
14 Halted 0 ms 0 KB -