이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5 + 2;
const int s = 100;
const int oo = -1e9;
int vis[MAX], f[MAX], n, m, q;
vector<int> a[MAX], v;
vector<pair<int, int>> b[MAX];
void solve() {
cin >> n >> m >> q;
for (int i = 1; i <= m; i++) {
int u, v;
cin >> u >> v;
a[v].push_back(u);
}
for (int i = 1; i <= n; i++) {
b[i].push_back({0, i});
for (auto j : a[i]) {
for (auto [dist, idx] : b[j]) {
if (!vis[idx]) {
vis[idx] = dist + 1;
v.push_back(idx);
} else {
vis[idx] = max(vis[idx], dist + 1);
}
}
}
for (auto j : v) {
b[i].push_back({vis[j], j});
vis[j] = 0;
}
sort(b[i].begin(), b[i].end(), greater<pair<int, int>>());
while (b[i].size() > s) b[i].pop_back();
v.clear();
}
/*for (int i = 1; i <= n; i++) {
for (auto [dist, idx] : b[i]) cout << dist << " " << idx << "\n";
cout << "\n";
}*/
for (int i = 1; i <= q; i++) {
int t, y;
cin >> t >> y;
for (int j = 1; j <= y; j++) {
int x;
cin >> x;
vis[x]++;
v.push_back(x);
}
if (y >= s) {
f[t] = 0;
int res = -1;
for (int j = t; j >= 1; j--) {
if (vis[j]) continue;
for (auto v : a[j]) {
if (!vis[j]) f[v] = max(f[v], f[j] + 1);
}
}
for (int j = 1; j <= t; j++) {
if (!vis[j]) res = max(res, f[j]);
}
cout << res << "\n";
} else {
int check = 0;
for (auto [dist, idx] : b[t]) {
if (!vis[idx]) {
check = 1;
cout << dist << "\n";
break;
}
}
if (!check) cout << -1 << "\n";
}
for (auto j : v) vis[j] = 0;
v.clear();
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
solve();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |