# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
46353 | SpaimaCarpatilor | Bitaro’s Party (JOI18_bitaro) | C++17 | 1576 ms | 173032 KiB |
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>
using namespace std;
const int K = 200;
int N, M, Q, maxD[100009], ap[100009], h[100009];
vector < int > v[100009], g[100009];
pair < int, int > *dp[100009];
bool cmp (int i, int j) {return (maxD[i] > maxD[j]);}
int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);
scanf ("%d %d %d", &N, &M, &Q);
while (M --)
{
int x, y;
scanf ("%d %d", &x, &y);
v[y].push_back (x);
g[x].push_back (y);
}
for (int i=1; i<=N; i++)
{
dp[i] = new pair < int, int > [K];
for (int j=0; j<K; j++)
dp[i][j] = {-3 * N, 0};
}
for (int i=1; i<=N; i++)
{
int nr = 0;
for (auto it : v[i])
for (int j=0; j<K; j++)
if (dp[it][j].first >= 0)
{
int nod = dp[it][j].second;
if (ap[nod] == 0 || dp[it][j].first + 1 > maxD[nod])
maxD[nod] = dp[it][j].first + 1;
if (ap[nod] == 0)
ap[nod] = 1, h[++nr] = nod;
}
h[++nr] = i, maxD[i] = 0;
sort (h + 1, h + nr + 1, cmp);
for (int j=1; j<=nr && j<=K; j++)
dp[i][j - 1] = {maxD[h[j]], h[j]};
for (int j=nr + 1; j<=K; j++)
dp[i][j - 1] = {-1, 0};
for (int j=1; j<=nr; j++) ap[h[j]] = 0;
}
while (Q --)
{
int pos, L;
scanf ("%d %d", &pos, &L);
for (int i=1; i<=L; i++)
scanf ("%d", &h[i]), ap[h[i]] = 1;
int val = -2;
for (int j=0; j<K; j++)
{
if (dp[pos][j].first < 0)
{
val = -1;
break;
}
int nod = dp[pos][j].second;
if (ap[nod] == 0)
{
val = dp[pos][j].first;
break;
}
}
if (val == -2)
{
///that's few times
maxD[pos] = 0, val = (ap[pos] ? -1 : 0);
for (int i=pos - 1; i>=1; i--)
{
maxD[i] = -3 * N;
for (auto it : g[i])
if (it <= pos && maxD[it] + 1 > maxD[i])
maxD[i] = maxD[it] + 1;
if (ap[i] == 0 && maxD[i] > val)
val = maxD[i];
}
printf ("%d\n", val);
for (int i=1; i<=L; i++)
ap[h[i]] = 0;
continue;
}
for (int i=1; i<=L; i++)
ap[h[i]] = 0;
printf ("%d\n", val);
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |