답안 #1001257

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1001257 2024-06-18T17:32:01 Z De3b0o Jail (JOI22_jail) C++14
0 / 100
5000 ms 314616 KB
#include<bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define in insert
#define pb push_back
#define ppb pop_back()
#define d3 ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define cans cout << ans << "\n";
#define yes cout << "Yes" << "\n";
#define no cout << "No" << "\n";
#define pll pair<ll,ll>
#define lin cout << "\n";
#define mod 1000000007
#define mid ((l+r)/2)
#define lc (2*x)
#define rc (2*x+1)

using namespace std;

ll n , m;
vector<ll> adj[120009];
ll S[120009] , T[120009];
ll o[120009];
vector<ll> g[120009];
ll vs;
ll vis[120009];
set<pll> seg[2000009];
ll et[250009];
ll ti[120009] , to[120009];
ll timer;
ll depth[120009];

void ett(ll x , ll p , ll de)
{
    depth[x]=de;
    et[timer]=x;
    ti[x]=timer;
    timer++;
    for(auto it : adj[x])
    {
        if(it==p)
            continue;
        ett(it,x,de+1);
    }
    et[timer]=x;
    to[x]=timer;
    timer++;
}

void ddfs(ll x)
{
    if(vis[x])
        return;
    vis[x]=1;
    vs++;
    for(auto it : g[x])
        ddfs(it);
}

void se(ll x , ll l , ll r , ll idx , ll val1 , ll val2)
{
    if(l>idx||r<idx)
        return;
    seg[x].in({val1,val2});
    if(l!=r)
    {
        se(lc,l,mid,idx,val1,val2);
        se(rc,mid+1,r,idx,val1,val2);
    }
}

pll sg(ll x , ll l , ll r , ll l1 , ll r1 , ll idx)
{
    if(l>r1||r<l1)
        return {1e18,-1};
    if(l>=l1&&r<=r1)
    {
        auto it = seg[x].lower_bound({idx,0});
        return *it;
    }
    pll le = sg(lc,l,mid,l1,r1,idx);
    pll ri = sg(rc,mid+1,r,l1,r1,idx);
    if(le.F>ri.F)
        return ri;
    else
        return le;
}

ll lca(ll u , ll v)
{
    pll x = sg(1,0,2*n-1,0,min(ti[u],ti[v]),max(ti[u],ti[v]));
    return x.S;
}

bool inpath(ll x , ll u , ll v)
{
    bool ans = 1;
    if((lca(x,u)==x||lca(x,v)==x)&&depth[x]>=depth[lca(u,v)])
        ans=0;
    return ans;
}

int main()
{
    d3
    ll t;
    cin >> t;
    while(t--)
    {
        cin >> n;
        for(int i = 0 ; 16*n>=i ; i++)
            seg[i].clear();
        for(int i = 1 ; n>=i ; i++)
            adj[i].clear();
        for(int i = 0 ; n-1>i ; i++)
        {
            ll u , v;
            cin >> u >> v;
            adj[u].pb(v);
            adj[v].pb(u);
        }
        timer=0;
        ett(1,0,0);
        for(int i = 1 ; n>=i ; i++)
            se(1,0,2*n-1,ti[i],to[i],i);
        cin >> m;
        for(int i = 1 ; m>=i ; i++)
        {
            cin >> S[i] >> T[i];
            g[i].clear();
            o[i]=0;
        }
        for(int i = 1 ; m>=i ; i++)
        {
            for(int j = 1 ; m>=j ; j++)
            {
                if(i==j)
                    continue;
                if(inpath(S[j],S[i],T[i])&&inpath(T[i],S[j],T[j]))
                {
                    g[j].pb(i);
                    o[i]++;
                }
            }
        }
        ll x = 0;
        ll v[120009] = {0};
        while(true)
        {
            ll y = 0;
            vector<ll> d;
            for(int i = 1 ; m>=i ; i++)
            {
                if(v[i])
                    continue;
                if(o[i]==m-x-1)
                {
                    v[i]=1;
                    d.pb(i);
                    y++;
                }
            }
            if(!y)
                break;
            x+=y;
            for(auto it : d)
            {
                for(auto it1 : g[it])
                    o[it1]--;
            }
        }
        if(x==m)
            yes
        else
            no
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 102992 KB Output is correct
2 Correct 26 ms 103004 KB Output is correct
3 Correct 25 ms 103004 KB Output is correct
4 Correct 54 ms 103608 KB Output is correct
5 Correct 93 ms 104016 KB Output is correct
6 Correct 29 ms 103260 KB Output is correct
7 Correct 29 ms 103260 KB Output is correct
8 Correct 74 ms 103504 KB Output is correct
9 Correct 3607 ms 112720 KB Output is correct
10 Correct 665 ms 263508 KB Output is correct
11 Correct 52 ms 103248 KB Output is correct
12 Correct 462 ms 104276 KB Output is correct
13 Execution timed out 5079 ms 314616 KB Time limit exceeded
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 103184 KB Output is correct
2 Correct 24 ms 103004 KB Output is correct
3 Correct 28 ms 103428 KB Output is correct
4 Incorrect 29 ms 103244 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 103184 KB Output is correct
2 Correct 24 ms 103004 KB Output is correct
3 Correct 28 ms 103428 KB Output is correct
4 Incorrect 29 ms 103244 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 103184 KB Output is correct
2 Correct 24 ms 103004 KB Output is correct
3 Correct 28 ms 103428 KB Output is correct
4 Incorrect 29 ms 103244 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 103184 KB Output is correct
2 Correct 24 ms 103004 KB Output is correct
3 Correct 28 ms 103428 KB Output is correct
4 Incorrect 29 ms 103244 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 102960 KB Output is correct
2 Incorrect 25 ms 103000 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 102992 KB Output is correct
2 Correct 26 ms 103004 KB Output is correct
3 Correct 25 ms 103004 KB Output is correct
4 Correct 54 ms 103608 KB Output is correct
5 Correct 93 ms 104016 KB Output is correct
6 Correct 29 ms 103260 KB Output is correct
7 Correct 29 ms 103260 KB Output is correct
8 Correct 74 ms 103504 KB Output is correct
9 Correct 3607 ms 112720 KB Output is correct
10 Correct 665 ms 263508 KB Output is correct
11 Correct 52 ms 103248 KB Output is correct
12 Correct 462 ms 104276 KB Output is correct
13 Execution timed out 5079 ms 314616 KB Time limit exceeded
14 Halted 0 ms 0 KB -