/**
* In the name of Allah
* We are nothing and you're everything
* Ya Muhammad!
**/
#include <bits/stdc++.h>
#ifdef LOCAL
#define debug(x) cerr << #x << "= " << x << endl;
#else
#define debug(x)
#endif
using namespace std;
using ll = long long;
using ull = uint64_t;
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define mp(x, y) make_pair(x, y)
#define int long long
const char nl = '\n';
const int N = 1e5+5;
const int inf = 1e9;
vector<int> g[N];
vector<pair<int, int>> mx[N];
const int bl = 318;
vector<int> v, vis;
void dfs(int a) {
vis[a] = -inf;
if (!v[a])vis[a] = 0;
for (auto i: g[a]) {
if (vis[i] != -inf) {
vis[a] = max(vis[a], vis[i]+1);
continue;
}
dfs(i);
vis[a] = max(vis[a], vis[i]+1);
}
}
void solve() {
int n, m, qu; cin >> n >> m >> qu;
for (int i = 0; i < m; ++i) {
int a, b; cin >> a >> b;
g[b].push_back(a);
}
vector<int> pos(n+1);
for (int i = 1; i <= n; ++i) {
priority_queue<pair<pair<int, int>, int>> pq;
for (auto j: g[i])pq.push({mx[j][0], j});
int cnt = 0;
while (sz(mx[i])<bl && cnt < sz(g[i])) {
mx[i].push_back({pq.top().first.first+1, mx[pq.top().second][pos[pq.top().second]].second});
pos[pq.top().second] += 1;
if (pos[pq.top().second] == sz(mx[pq.top().second]))cnt += 1;
else {
pq.push({mx[pq.top().second][pos[pq.top().second]], pq.top().second});
}
pq.pop();
}
for (auto j: g[i])pos[j] = 0;
mx[i].push_back({0, i});
}
v.resize(n+1);
//for (auto j: mx[5])cout << j.first << " " << j.second << nl;
for (int i = 0; i < qu; ++i) {
int t, y; cin >> t >> y;
vector<int> c(y);
for (auto &j: c) {
cin >> j;
v[j] = 1;
}
bool res = true;
for (auto j: mx[t])
if (!v[j.second]) {
cout << j.first << nl;
res = false;
break;
}
if (res) {
dfs(t);
cout << vis[t] << nl;
}
for (auto j: c)v[j] = 0;
}
}
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
//int t; cin >> t;
//while(t--)
solve();
return 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... |