제출 #334189

#제출 시각아이디문제언어결과실행 시간메모리
334189trthminhBitaro’s Party (JOI18_bitaro)C++14
14 / 100
2095 ms123884 KiB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, a, b) for(ll i = (a); i <= (b); ++i)
#define req(i, a, b) for(ll i = (a); i >= (b); --i)
#define name "bitaro"
#define pb push_back
#define sz size()
#define ff first
#define ss second
typedef pair < int, int > ii;
const ll maxn = 2e5 + 7, oo = 1e9, mod = 1e9 + 7, can = 75;
int n, m, q, x, y, busy[maxn], st, n_people_busy, f[maxn];
int bbusy[maxn];
vector < ll > a[maxn], Ma[maxn];
vector < ii > furthest[maxn];
void pre()
{
    rep (i, 1, n)
    {
        vector < ii > tmp;
        for (int j : a[i])
        {
            for (auto h : furthest[j])
                tmp.pb({h.ff + 1, h.ss});
        }
        tmp.pb({0, i});
        sort(tmp.begin(), tmp.end(), greater < ii > ());
        for (auto ttm : tmp)
        {
            if (busy[ttm.ss] == 0) // not busy
            {
                busy[ttm.ss] = 1;
                furthest[i].pb(ttm);
                if (furthest[i].sz == can)
                    break;
            }
        }
        for (auto ttm : furthest[i])
            busy[ttm.ss] = 0;
    }
}
void solve1(int s)
{
//    rep (i, 1, n)
//        f[i] = -oo;
//    f[st] = 0;
//    for (int i = st - 1; i >= 1; --i)
//        for (int j : Ma[i])
//            f[i] = max (f[i], f[j] + 1);
//    int res = -1;
//    for (int i = st; i >= 1; --i)
//        if (!busy[i])
//            res = max (res, f[i]);
//    cout << res << '\n';
    f[s] = 0;
    for (int i = 1; i < s; ++i) f[i] = -oo;
    for (int i = s; i > 1; --i)
        for (int j : a[i])
            f[j] = max(f[j], f[i] + 1);
    int ans = -1;
    for (int i = 1; i <= s; ++i)
        if (!busy[i]) ans = max(ans, f[i]);
    cout << ans << '\n';
}
void solve2(int st)
{
    int res = -1;
    for (auto i : furthest[st])
        if (!busy[i.ss])
            res = max (res, i.ff);
    cout << res << '\n';
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
//    freopen(name".inp", "r", stdin);
//    freopen(name".out", "w", stdout);
    cin >> n >> m >> q;
    rep (i, 1, m)
    {
        cin >> x >> y;
        a[y].pb(x);
    }
    pre(); // find can the furthest cities for each city
    while (q--)
    {
        cin >> st >> n_people_busy;
        rep (i, 1, n_people_busy)
        {
            cin >> bbusy[i];
            busy[bbusy[i]] = 1;
        }
        if (n_people_busy >= can)
            solve1(st);
        else solve2(st);
        rep (i, 1, n_people_busy)
            busy[bbusy[i]] = 0;
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...