This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#define _FORTIFY_SOURCE 0
#pragma GCC optimize("Ofast")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-fwhole-program")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("inline-functions")
#pragma GCC optimize("-ftree-tail-merge")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-fstrict-overflow")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-fcse-skip-blocks")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("-fhoist-adjacent-loads")
#pragma GCC optimize("-frerun-cse-after-loop")
#pragma GCC optimize("inline-small-functions")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("-funsafe-loop-optimizations")
#pragma GCC optimize("inline-functions-called-once")
#pragma GCC optimize("-fdelete-null-pointer-checks")
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 5;
const int MAXS = 200;
vector<int> adj[MAXN], rev[MAXN];
vector<pair<int, int>> caras[MAXN];
int in[MAXN], bosta[MAXN], best[MAXN], dp[MAXN], valid[MAXN];
bool mark[MAXN], blocked[MAXN];
void merge(int a, int b) {
vector<pair<int, int>> result;
int j = 0;
for (int i = 0; i < (int) caras[a].size(); i++) {
for (; j < (int) caras[b].size() && caras[b][j].first + 1 > caras[a][i].first; j++) {
result.push_back({caras[b][j].first + 1, caras[b][j].second});
}
result.push_back(caras[a][i]);
}
for (; j < (int) caras[b].size(); j++) {
result.push_back({caras[b][j].first + 1, caras[b][j].second});
}
caras[a].clear();
for (auto x : result) {
if (!mark[x.second] && (int) caras[a].size() < MAXS + 1) {
caras[a].push_back(x);
mark[x.second] = true;
}
}
for (auto x : caras[a]) {
mark[x.second] = false;
}
}
int solve(int v) {
if (dp[v] != -1) return dp[v];
valid[v] = (int) !blocked[v];
int ans = 0;
for (int u : rev[v]) {
ans = max(ans, solve(u) + valid[u]);
if (valid[u]) valid[v] = 1;
}
return dp[v] = ans;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int n, m, q;
cin >> n >> m >> q;
for (int i = 0; i < m; i++) {
int a, b;
cin >> a >> b;
adj[a].push_back(b);
rev[b].push_back(a);
in[b]++;
}
vector<int> lista;
for (int i = 1; i <= n; i++) {
caras[i].push_back({0, i});
if (!in[i]) lista.push_back(i);
}
for (int i = 0; i < (int) lista.size(); i++) {
int cur = lista[i];
for (int nxt : adj[cur]) {
in[nxt]--;
if (!in[nxt]) lista.push_back(nxt);
merge(nxt, cur);
}
}
for (int i = 0; i < q; i++) {
int t, y;
cin >> t >> y;
for (int j = 0; j < y; j++) {
cin >> bosta[j];
blocked[bosta[j]] = true;
}
if (y > MAXS) {
for (int j = 1; j <= n; j++) {
dp[j] = -1;
valid[j] = 0;
}
int ans = (solve(t) == 0 ? blocked[t] ? -1 : 0 : dp[t]);
cout << ans << '\n';
} else {
int ans = -1;
for (auto x : caras[t]) {
if (!blocked[x.second]) {
ans = x.first;
break;
}
}
cout << ans << '\n';
}
for (int j = 0; j < y; j++) {
blocked[bosta[j]] = false;
}
}
return 0;
}
Compilation message (stderr)
bitaro.cpp:1: warning: "_FORTIFY_SOURCE" redefined
1 | #define _FORTIFY_SOURCE 0
|
<built-in>: note: this is the location of the previous definition
bitaro.cpp:25:39: warning: bad option '-fwhole-program' to pragma 'optimize' [-Wpragmas]
25 | #pragma GCC optimize("-fwhole-program")
| ^
bitaro.cpp:32:41: warning: bad option '-fstrict-overflow' to pragma 'optimize' [-Wpragmas]
32 | #pragma GCC optimize("-fstrict-overflow")
| ^
bitaro.cpp:34:41: warning: bad option '-fcse-skip-blocks' to pragma 'optimize' [-Wpragmas]
34 | #pragma GCC optimize("-fcse-skip-blocks")
| ^
bitaro.cpp:48:51: warning: bad option '-funsafe-loop-optimizations' to pragma 'optimize' [-Wpragmas]
48 | #pragma GCC optimize("-funsafe-loop-optimizations")
| ^
bitaro.cpp:66:24: warning: bad option '-fwhole-program' to attribute 'optimize' [-Wattributes]
66 | void merge(int a, int b) {
| ^
bitaro.cpp:66:24: warning: bad option '-fstrict-overflow' to attribute 'optimize' [-Wattributes]
bitaro.cpp:66:24: warning: bad option '-fcse-skip-blocks' to attribute 'optimize' [-Wattributes]
bitaro.cpp:66:24: warning: bad option '-funsafe-loop-optimizations' to attribute 'optimize' [-Wattributes]
bitaro.cpp:90:16: warning: bad option '-fwhole-program' to attribute 'optimize' [-Wattributes]
90 | int solve(int v) {
| ^
bitaro.cpp:90:16: warning: bad option '-fstrict-overflow' to attribute 'optimize' [-Wattributes]
bitaro.cpp:90:16: warning: bad option '-fcse-skip-blocks' to attribute 'optimize' [-Wattributes]
bitaro.cpp:90:16: warning: bad option '-funsafe-loop-optimizations' to attribute 'optimize' [-Wattributes]
bitaro.cpp:101:10: warning: bad option '-fwhole-program' to attribute 'optimize' [-Wattributes]
101 | int main(){
| ^
bitaro.cpp:101:10: warning: bad option '-fstrict-overflow' to attribute 'optimize' [-Wattributes]
bitaro.cpp:101:10: warning: bad option '-fcse-skip-blocks' to attribute 'optimize' [-Wattributes]
bitaro.cpp:101:10: warning: bad option '-funsafe-loop-optimizations' to attribute 'optimize' [-Wattributes]
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |