This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/** Im the best because i work as hard as i possibly can **/
#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
#define Mp make_pair
#define fast_io ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io freopen("in.txt" , "r+" , stdin) ; freopen("out.txt" , "w+" , stdout);
#define endl "\n"
const int N = 1e5 + 10;
const ll mod = 1e9 + 7;
const ll mod2 = 998244353;
const ll inf = 8e18;
const int LOG = 22;
const int B = 290;
ll pw(ll a , ll b, ll M) { return (!b ? 1 : (b & 1 ? (a * pw(a * a % M, b / 2, M)) % M : pw(a * a % M, b / 2, M))); }
vector < int > G[N];
int n, m, q, mark[N], A[N], use[N], dp[N];
pii dis[B][N], cu[B];
void merge(int v, int u)
{
for(int i = 0; i < B; i ++) mark[dis[i][v].S] = mark[dis[i][u].S] = 0, cu[i] = Mp(-1e9, 0);
int l = 0, r = 0, i = 0;
for(i = 0; i < B; i ++)
{
while(l < B and mark[dis[l][v].S]) l ++;
while(r < B and mark[dis[r][u].S]) r ++;
if(r >= B and l >= B) break;
if(r >= B or dis[l][v].F + 1 > dis[r][u].F)
{
cu[i] = dis[l][v], cu[i].F ++;
mark[cu[i].S] = 1;
}
else if(r < B)
{
cu[i] = dis[r][u];
mark[cu[i].S] = 1;
}
}
for(i = 0; i < B; i ++) dis[i][u] = cu[i];
}
int main()
{
scanf("%d%d%d", &n, &m, &q);
for(int i = 1; i <= m; i ++)
{
int a, b, x, y;
scanf("%d%d", &a, &b);
x = min(a, b), y = max(a, b);
G[x].push_back(y);
}
for(int i = 1; i <= n; i ++)
{
dis[0][i] = Mp(0, i);
for(int j = 1; j < B; j ++)
{
dis[j][i] = Mp(-1e9, 0);
}
}
for(int i = 1; i <= n; i ++)
{
for(auto u : G[i]) merge(i, u);
}
while(q--)
{
int v, cnt;
scanf("%d%d", &v, &cnt);
for(int i = 1; i <= cnt; i ++)
{
scanf("%d", &A[i]);
use[A[i]] = 1;
}
if(cnt >= B)
{
for(int i = 0; i <= v; i ++) dp[i] = -1e9;
for(int i = 1; i <= v; i ++)
{
if(!use[i])
{
dp[i] = max(dp[i], 0);
}
for(auto u : G[i]) dp[u] = max(dp[u], dp[i] + 1);
}
printf("%d\n", max(dp[v], -1));
}
else
{
for(int i = 0; i < B; i ++)
{
if(!use[dis[i][v].S])
{
printf("%d\n", max(dis[i][v].F, -1));
break;
}
}
}
for(int i = 1; i <= cnt; i ++) { use[A[i]] = 0; }
}
return 0;
}
Compilation message (stderr)
bitaro.cpp: In function 'int main()':
bitaro.cpp:59:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
59 | scanf("%d%d%d", &n, &m, &q);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~
bitaro.cpp:63:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
63 | scanf("%d%d", &a, &b);
| ~~~~~^~~~~~~~~~~~~~~~
bitaro.cpp:82:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
82 | scanf("%d%d", &v, &cnt);
| ~~~~~^~~~~~~~~~~~~~~~~~
bitaro.cpp:85:11: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
85 | scanf("%d", &A[i]);
| ~~~~~^~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |