Submission #567153

#TimeUsernameProblemLanguageResultExecution timeMemory
567153AbdullahMWBitaro’s Party (JOI18_bitaro)C++17
0 / 100
2081 ms134172 KiB
#include <bits/stdc++.h>

#define all(vec) vec.begin(), vec.end()
#define ll long long
#define db double
#define pb push_back
#define pf push_front
#define newl "\n"
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define f first
#define s second
#define MOD 1000000007

using namespace std;

#pragma GCC diagnostic ignored "-Wunused-result"
void setIO(string name = "") {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout << fixed << setprecision(15);
    if (name.size()) {
        freopen((name+".in").c_str(), "r", stdin);
        freopen((name+".out").c_str(), "w", stdout);
    }
}

vector <ll> gr[100005];
ll dj(ll beg, ll town)
{
    ll mx = -1;
    priority_queue <pair <ll, ll>, vector <pair <ll, ll>>, greater <pair <ll, ll>>> pq;
    pq.push({0, beg});
    
    while (pq.size())
    {
        ll x = pq.top().s, len = pq.top().f;
        pq.pop();
        
        if (x == town) mx = max(mx, len);
        else
        {
            for (auto v : gr[x])
            {
                pq.push({len + 1, v});
            }
        }
    }
    return mx;
}

int main()
{
    fast
    //setIO("");
    
    //freopen("filename.in", "r", stdin);
    //freopen("filename.out", "w", stdout);
  
    ll n, m, q; cin >> n >> m >> q;
    for (ll i = 1; i <= m; i++)
    {
        ll x, y; cin >> x >> y;
        gr[x].pb(y);
    }
    
    while (q--)
    {
        ll t, f; cin >> t >> f;
        unordered_map <ll, bool> busy;
        for (ll i = 1; i <= f; i++)
        {
            ll fr; cin >> fr;
            busy[fr] = true;
        }
        
        ll mx = -1;
        if (!busy[t]) mx = 0;
        for (ll i = 1; i <= n; i++)
        {
            if (!busy[i] && i != t) mx = max(mx, dj(i, t));
        }
        
        cout << mx << newl;
    }
}
    
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...