Submission #712907

# Submission time Handle Problem Language Result Execution time Memory
712907 2023-03-20T12:35:23 Z lam Jail (JOI22_jail) C++14
0 / 100
5000 ms 23696 KB
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 2e4 + 10;
typedef pair<int,int> ii;
#define ff first
#define ss second
int n,m;
vector <int> adj[maxn];
int par[18][maxn];
int in[maxn],out[maxn],cnt;
ii num[maxn], a[maxn];
void dfs(int x, int p)
{
    par[0][x]=p;
    in[x]=++cnt;
    for (int i=1; i<=17; i++) par[i][x]=par[i-1][par[i-1][x]];
    for (int i:adj[x])
        if (i!=p)
            dfs(i,x);
    out[x]=cnt;
}
bool check(int u, int v)
{
    return in[u]<=in[v]&&out[v]<=out[u];
}
int lca(int u, int v)
{
    if (check(u,v)) return u;
    if (check(v,u)) return v;
    for (int i=17; i>=0; i--)
        if (!check(par[i][u],v)) u=par[i][u];
    return par[0][u];
}
void upd(int u, int v, int type)
{
//    int it=1;
    while (v!=u)
    {
//        it++; if (it==10) break;
//        cerr<<u<<' '<<v<<endl;
        if (type==1) num[v].ff++;
        else num[v].ss++;
        v=par[0][v];
    }
}
bool check_mid(int u, int v, int mid)
{
    return check(u,mid)&&check(mid,v);
}
bool check_path(int u, int v, int x, int y)
{
    /**
    u x y v
    **/
    int p=lca(u,v);
    if ((check_mid(p,u,x)||check_mid(p,v,x))&&(check_mid(p,u,y)||check_mid(p,v,y))) return 1;
    return 0;
}
void xuly()
{
    cin>>n;
    for (int i=1; i<=n; i++) adj[i].clear(), in[i]=out[i]=0, num[i]={0,0}; cnt=0;
    for (int i=1; i<n; i++)
    {
        int u,v; cin>>u>>v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    dfs(1,1);
    cin>>m;
    for (int i=1; i<=m; i++) cin>>a[i].ff>>a[i].ss;
    for (int i=1; i<=m; i++)
    {
        int u=a[i].ff; int v=a[i].ss;
        int p=lca(u,v);
//        cerr<<i<<" :> "<<endl;
        upd(p,u,1); upd(p,v,2);
    }
    for (int i=1; i<=n; i++)
        if (num[i].ff>0&&num[i].ss>0)
        {
            cout<<"No\n";
            return;
        }
    for (int i=1; i<=m; i++)
        for (int j=1; j<=m; j++) if (i!=j&&check_path(a[i].ff,a[i].ss,a[j].ff,a[j].ss))
    {
        cout<<"No\n";
        return;
    }
    cout<<"Yes\n";
}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    int tt; cin>>tt;
    while (tt--) xuly();
}

Compilation message

jail.cpp: In function 'void xuly()':
jail.cpp:62:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   62 |     for (int i=1; i<=n; i++) adj[i].clear(), in[i]=out[i]=0, num[i]={0,0}; cnt=0;
      |     ^~~
jail.cpp:62:76: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   62 |     for (int i=1; i<=n; i++) adj[i].clear(), in[i]=out[i]=0, num[i]={0,0}; cnt=0;
      |                                                                            ^~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3156 KB Output is correct
2 Correct 2 ms 3156 KB Output is correct
3 Correct 2 ms 3156 KB Output is correct
4 Correct 10 ms 3412 KB Output is correct
5 Correct 22 ms 3784 KB Output is correct
6 Correct 3 ms 3320 KB Output is correct
7 Correct 3 ms 3280 KB Output is correct
8 Correct 4 ms 3340 KB Output is correct
9 Correct 60 ms 4636 KB Output is correct
10 Correct 166 ms 23368 KB Output is correct
11 Correct 6 ms 3360 KB Output is correct
12 Correct 29 ms 3660 KB Output is correct
13 Execution timed out 5048 ms 23696 KB Time limit exceeded
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 3156 KB Output is correct
2 Correct 2 ms 3156 KB Output is correct
3 Correct 3 ms 3284 KB Output is correct
4 Incorrect 2 ms 3156 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 3156 KB Output is correct
2 Correct 2 ms 3156 KB Output is correct
3 Correct 3 ms 3284 KB Output is correct
4 Incorrect 2 ms 3156 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 3156 KB Output is correct
2 Correct 2 ms 3156 KB Output is correct
3 Correct 3 ms 3284 KB Output is correct
4 Incorrect 2 ms 3156 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 3156 KB Output is correct
2 Correct 2 ms 3156 KB Output is correct
3 Correct 3 ms 3284 KB Output is correct
4 Incorrect 2 ms 3156 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 3156 KB Output is correct
2 Correct 2 ms 3156 KB Output is correct
3 Correct 2 ms 3156 KB Output is correct
4 Correct 2 ms 3156 KB Output is correct
5 Correct 10 ms 3156 KB Output is correct
6 Correct 3 ms 3284 KB Output is correct
7 Incorrect 2 ms 3288 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3156 KB Output is correct
2 Correct 2 ms 3156 KB Output is correct
3 Correct 2 ms 3156 KB Output is correct
4 Correct 10 ms 3412 KB Output is correct
5 Correct 22 ms 3784 KB Output is correct
6 Correct 3 ms 3320 KB Output is correct
7 Correct 3 ms 3280 KB Output is correct
8 Correct 4 ms 3340 KB Output is correct
9 Correct 60 ms 4636 KB Output is correct
10 Correct 166 ms 23368 KB Output is correct
11 Correct 6 ms 3360 KB Output is correct
12 Correct 29 ms 3660 KB Output is correct
13 Execution timed out 5048 ms 23696 KB Time limit exceeded
14 Halted 0 ms 0 KB -