이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 < ll, ll > ii;
const ll maxn = 1e5 + 7, oo = 1e18, mod = 1e9 + 7, can = 317;
ll n, m, q, x, y, busy[maxn], st, n_people_busy, f[maxn];
vector < ll > a[maxn], Ma[maxn];
vector < ii > furthest[maxn];
void pre()
{
rep (i, 1, n)
{
vector < ii > tmp;
tmp.pb({0, i});
for (int j : a[i])
{
for (auto h : furthest[j])
tmp.pb({h.ff + 1, h.ss});
}
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 st)
{
rep (i, 1, n)
f[i] = -oo;
f[st] = 0;
rep (i, 1, st)
for (int j : Ma[i])
f[j] = max (f[j], f[i] + 1);
ll res = -1;
rep (i, 1, st)
if (!busy[i])
res = max (res, f[i]);
cout << res << '\n';
}
void solve2(int st)
{
ll 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;
Ma[x].pb(y);
a[y].pb(x);
}
pre(); // find can the furthest cities for each city
while (q--)
{
cin >> st >> n_people_busy;
vector < ll > MBusy;
rep (i, 1, n_people_busy)
{
cin >> x;
MBusy.pb(x);
busy[x] = 1;
}
if (n_people_busy >= can)
solve1(st);
else solve2(st);
for (auto i : MBusy)
busy[i] = 0;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |