Submission #967448

# Submission time Handle Problem Language Result Execution time Memory
967448 2024-04-22T06:32:54 Z Tuanlinh123 Bitaro’s Party (JOI18_bitaro) C++17
0 / 100
3 ms 7260 KB
#include<bits/stdc++.h>
#define ll int
#define pll pair<ll, ll>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ld long double
#define sz(a) ((ll)(a).size())
using namespace std;

const ll maxn=100005, s=500;
ll deg[maxn], seen[maxn];
vector <pll> best[maxn];
vector <ll> A[maxn], At[maxn];

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    ll n, m, q; cin >> n >> m >> q;
    for (ll i=1; i<=m; i++)
    {
        ll u, v; cin >> u >> v;
        A[u].pb(v), At[v].pb(u), deg[v]++;
    }
    queue <ll> Q;
    for (ll i=1; i<=n; i++)
        if (!deg[i]) Q.push(i);
    while (sz(Q))
    {
        ll u=Q.front(); Q.pop();
        vector <pll> val={{-1, u}};
        for (ll v:At[u]) 
            for (pll b:best[v])
                val.pb(b);
        sort(val.begin(), val.end(), greater<pll>());
        for (auto [x, v]:val)
            if (!seen[v] && sz(best[u])<s) 
                seen[v]=1, best[u].pb({x+1, v});
        for (auto [x, v]:best[u]) seen[v]=0;
        for (ll v:A[u])
        {
            deg[v]--;
            if (!deg[v]) Q.push(v);
        }
    }
    for (ll i=1; i<=q; i++)
    {
        ll X, x, ans=0; cin >> X >> x;
        vector <ll> a(x);
        for (ll &i:a) cin >> i;
        if (x>=s)
        {
            queue <ll> q;
            vector <ll> dp(n+5, 0), deg(n+5, 0);
            for (ll i=1; i<=n; i++) deg[i]=sz(At[i]), !deg[i]?q.push(i),0:0;
            for (ll i:a) dp[i]=-1e9;
            while (sz(q))
            {
                ll u=q.front(); q.pop();
                for (ll v:At[u]) 
                    dp[u]=max(dp[u], dp[v]+1);
                for (ll v:A[u])
                {
                    deg[v]--;
                    if (!deg[v]) q.push(v);
                }
            }
            ans=dp[X];
        }
        else
        {
            for (ll j:a) seen[j]=1;
            for (auto [x, v]:best[X])
                if (!seen[v]) {ans=x; break;}
            for (ll j:a) seen[j]=0;
        } 
        cout << ans << "\n";
    }
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 7256 KB Output is correct
2 Incorrect 2 ms 7260 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 7256 KB Output is correct
2 Incorrect 2 ms 7260 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 7256 KB Output is correct
2 Incorrect 2 ms 7260 KB Output isn't correct
3 Halted 0 ms 0 KB -