This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
typedef long long int ll;
#define INF (int)(1e9 + 7)
#define INF2 998244353
#define N (ll)(2e5 + 5)
using namespace std;
//#define int ll
#define lsb(x) (x & (-x))
int n, m, q, g, h, t1, t2;
vector<int> v[N], qu[N];
int dp[N], ans[N];
vector<int> c[N];
int k = 100;
int val[N];
vector<pair<int, int>> best [N];
bool used[N];
void solve(){
cin >> n >> m >> q;
for(int i=1; i<=m; i++){
cin >> g >> h;
v[h].push_back(g);
}
for(int i=1; i<=q; i++){
ans[i] = -1;
cin >> g >> h;
for(int j=1; j<=h; j++){
cin >> t1;
c[i].push_back(t1);
}
if(h > k){
for(int j=1; j<=n; j++)dp[j] = 0;
for(int j : c[i])dp[j] = -INF;
for(int j=1; j<=g; j++){
for(int u : v[j]){
dp[j] = max(dp[j], dp[u] + 1);
}
}
if(dp[g] >= 0)ans[i] = dp[g];
}
else{
qu[g].push_back(i);
}
}
for(int i=1; i<=n; i++){
vector<int> ch;
best[i].push_back({0, i});
for(int u : v[i]){
for(auto z : best[u]){
val[z.second] = max(val[z.second], z.first + 1);
ch.push_back(z.second);
}
}
for(int j : ch){
if(!used[j]){
best[i].push_back({val[j], j});
used[j] = 1;
}
}
for(int j : ch){
used[j] = 0;
val[j] = 0;
}
sort(best[i].begin(), best[i].end(), greater<pair<int, int>>());
if(best[i].size() > k + 1)best[i].resize(k + 1);
for(auto j : best[i])used[j.second] = 0;
for(int j : qu[i]){
for(int cc : c[j]){
used[cc] = 1;
}
for(auto p : best[i]){
if(!used[p.second]){
ans[j] = p.first;
break;
}
}
for(int cc : c[j]){
used[cc] = 0;
}
}
}
for(int i=1; i<=q; i++){
cout << ans[i] << '\n';
}
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int T = 1;
//cin>>T;
while (T--){
solve();
}
}
Compilation message (stderr)
bitaro.cpp: In function 'void solve()':
bitaro.cpp:73:27: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
73 | if(best[i].size() > k + 1)best[i].resize(k + 1);
| ~~~~~~~~~~~~~~~^~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |