This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
/****Author: Barish Namazov****/
#include <bits/stdc++.h>
using namespace std;
/***TEMPLATE***/
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define endl '\n'
const int max4 = 10004;
const int maxx = 200005;
const int max6 = 1000006;
const int lg5 = 17;
const int INF = 2 * 1000000007;
const long long INFLL = 4LL * 1000000000 * 1000000000;
/***************/
int powmod (int a, int b, int mod) {
int res = 1; a %= mod;
for (; b; b >>= 1) {
if (b & 1) {
res = 1LL * res * a % mod;
}
a = 1LL * a * a % mod;
}
return res;
}
int gcd (int a, int b) {
while (b > 0) {
int t = a % b;
a = b, b = t;
}
return a;
}
int lcm (int a, int b) {
return (a / gcd (a, b)) * b;
}
int is_prime (int n) {
if (n <= 1 || n > 3 && (n % 2 == 0 || n % 3 == 0))
return 0;
for (int i = 5, t = 2; i * i <= n; i += t, t = 6 - t)
if (n % i == 0)
return 0;
return 1;
}
/******Don't forget to use long long when needed!!******/
const int Block = 220;
int n, m, q;
vector <int> g[maxx];
vector <pair <int, int>> dp[maxx]; int res[maxx];
inline void update(int u, int v) {
for (auto i : dp[u]) {
res[i.S] = i.F;
}
for (auto i : dp[v]) {
res[i.S] = max(res[i.S], i.F + 1);
}
for (auto &i : dp[u]) {
i.F = max(i.F, res[i.S]); res[i.S] = 0;
}
for (auto i : dp[v]) {
if (res[i.S] > 0) {
dp[u].pb({i.F + 1, i.S}); res[i.S] = 0;
}
} sort(rall(dp[u]));
/*
vector <pair <int, int>> A, B;
for (auto i : dp[u]) B.pb(i);
for (auto i : dp[v]) {
if (res[i.S] > 0) {
A.pb({i.F + 1, i.S}); res[i.S] = 0;
}
} //sort(rall(A)); sort(rall(B));
while (!dp[u].empty()) dp[u].pop_back();
int ptr1 = 0, ptr2 = 0;
while (ptr1 < A.size() && ptr2 < B.size()) {
if (A[ptr1] > B[ptr2]) {
dp[u].pb(A[ptr1++]);
} else {
dp[u].pb(B[ptr2++]);
}
}
while (ptr1 < A.size()) dp[u].pb(A[ptr1++]);
while (ptr2 < B.size()) dp[u].pb(B[ptr2++]);*/
while (dp[u].size() > Block) {
dp[u].pop_back();
}
}
int has[maxx], lpath[maxx];
int main() {
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
ios_base :: sync_with_stdio(0);
cin.tie(0), cout.tie(0);
cin >> n >> m >> q;
int a, b;
for (int i = 1; i <= m; i++) {
cin >> a >> b;
g[b].pb(a);
}
for (int i = 1; i <= n; i++) {
for (int j : g[i]) {
update(i, j);
}
if (dp[i].size() < Block) {
dp[i].pb({0, i});
}
}
vector <int> bad; int tmp;
int t, y;
while (q --) {
cin >> t >> y;
for (int i = 0; i < y; i++) {
cin >> tmp;
bad.pb(tmp); has[tmp] = 1;
}
if (y < Block) {
int res = -1;
for (auto i : dp[t]) {
if (has[i.S] == 0) {
res = i.F; break;
}
}
cout << res << endl;
} else {
for (int i = 1; i <= t; i++) {
lpath[i] = -has[i];
for (int j : g[i]) {
if (lpath[j] != -1) {
lpath[i] = max(lpath[i], lpath[j] + 1);
}
}
}
cout << lpath[t] << endl;
}
for (int i = 0; i < y; i++) {
has[bad[i]] = 0;
}
bad.clear();
}
return 0;
}
Compilation message (stderr)
bitaro.cpp:1:0: warning: ignoring #pragma comment [-Wunknown-pragmas]
#pragma comment(linker, "/stack:200000000")
bitaro.cpp: In function 'int is_prime(int)':
bitaro.cpp:55:25: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
if (n <= 1 || n > 3 && (n % 2 == 0 || n % 3 == 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... |