#include <bits/stdc++.h>
#define N 100050
#define RAIZ 350
#define f first
#define s second
#define gc getchar_unlocked
using namespace std;
typedef pair<int, int> pii;
int n, m, q, dp[N], block[N], grau[N], save[N], qualquer[N], aparecidos[N];
vector<int> grafo[N], lista;
vector < pii > best[N];
inline void solve()
{
for(int i = 1; i <= n; i++) if(!grau[i]) lista.push_back(i);
for(int i = 0; i < lista.size(); i++)
{
int x = lista[i];
vector<pii> aux2;
for(auto tt: best[x]) aux2.push_back({tt.f - 1, tt.s });
for(auto v: grafo[x])
{
grau[v] --;
vector<pii> aux ( best[v].size() + best[x].size() ), fim;
vector<int> cu;
merge( best[v].begin(), best[v].end(), aux2.begin(), aux2.end(), aux.begin() );
for(int i = 0; i < aux.size(); i++)
{
if(aparecidos[aux[i].s]) continue;
fim.push_back(aux[i]);
cu.push_back(aux[i].s);
aparecidos[aux[i].s] = 1;
}
for(auto tt: cu) aparecidos[tt] = 0;
while(fim.size() > 400) fim.pop_back();
best[v] = fim;
if(!grau[v]) lista.push_back(v);
}
}
}
int main()
{
ios::sync_with_stdio(false); cin.tie(0);
cin>>n>>m>>q;
for(int i = 1, a, b; i <= m; i++)
{
cin>>a>>b;
grafo[a].push_back(b);
grau[b] ++;
save[b] ++;
}
for(int i = 1; i <= n; i++) best[i].push_back({0, i});
solve();
for(int t = 1; t <= q; t++)
{
int T, Y;
cin>>T>>Y;
vector<int> mudar;
if(Y > RAIZ)
{
memset(dp, -1, sizeof dp);
memset(qualquer, 0, sizeof qualquer);
for(int i = 1; i <= n; i++) grau[i] = save[i];
for(int i = 1, x; i <= Y; i++)
{
cin>>x;
block[x] = 1;
mudar.push_back(x);
}
vector<pii> lista;
for(int i = 1; i <= n; i++)
{
if(!grau[i]) dp[i] = 0, lista.push_back( {i, !block[i] } );
qualquer[i] = !block[i];
if(!block[i]) dp[i] = 0;
else dp[i] = -1;
}
for(int i = 0; i < lista.size(); i++)
{
int x = lista[i].f, b = lista[i].s;
for(auto v: grafo[x])
{
grau[v] --;
if(b && dp[x] != -1) dp[v] = max(dp[v], dp[x] + 1);
qualquer[v] = (qualquer[v] || b);
if(!grau[v]) lista.push_back({v, qualquer[v]});
}
}
cout<<dp[T]<<"\n";
for(auto tt: mudar) block[tt] = 0;
continue;
}
for(int i = 1, x; i <= Y; i++)
{
cin>>x;
block[x] = 1;
mudar.push_back(x);
}
int ans = -1;
for(int i = 0; i < best[T].size(); i++)
{
int d = -best[T][i].f, v = best[T][i].s;
if(!block[v]) ans = max(ans, d);
}
for(auto tt: mudar) block[tt] = 0;
cout<<ans<<"\n";
}
}
Compilation message
bitaro.cpp: In function 'void solve()':
bitaro.cpp:20:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < lista.size(); i++)
~~^~~~~~~~~~~~~~
bitaro.cpp:38:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < aux.size(); i++)
~~^~~~~~~~~~~~
bitaro.cpp: In function 'int main()':
bitaro.cpp:119:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < lista.size(); i++)
~~^~~~~~~~~~~~~~
bitaro.cpp:153:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < best[T].size(); i++)
~~^~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
4988 KB |
Output is correct |
2 |
Correct |
7 ms |
5048 KB |
Output is correct |
3 |
Correct |
7 ms |
5080 KB |
Output is correct |
4 |
Correct |
6 ms |
5080 KB |
Output is correct |
5 |
Correct |
12 ms |
6252 KB |
Output is correct |
6 |
Correct |
12 ms |
6252 KB |
Output is correct |
7 |
Correct |
12 ms |
6252 KB |
Output is correct |
8 |
Correct |
23 ms |
9068 KB |
Output is correct |
9 |
Correct |
25 ms |
9068 KB |
Output is correct |
10 |
Correct |
24 ms |
9068 KB |
Output is correct |
11 |
Correct |
23 ms |
9068 KB |
Output is correct |
12 |
Correct |
15 ms |
9068 KB |
Output is correct |
13 |
Correct |
23 ms |
9068 KB |
Output is correct |
14 |
Correct |
19 ms |
9068 KB |
Output is correct |
15 |
Correct |
17 ms |
9068 KB |
Output is correct |
16 |
Correct |
19 ms |
9068 KB |
Output is correct |
17 |
Correct |
22 ms |
9068 KB |
Output is correct |
18 |
Correct |
15 ms |
9068 KB |
Output is correct |
19 |
Correct |
19 ms |
9068 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
4988 KB |
Output is correct |
2 |
Correct |
7 ms |
5048 KB |
Output is correct |
3 |
Correct |
7 ms |
5080 KB |
Output is correct |
4 |
Correct |
6 ms |
5080 KB |
Output is correct |
5 |
Correct |
12 ms |
6252 KB |
Output is correct |
6 |
Correct |
12 ms |
6252 KB |
Output is correct |
7 |
Correct |
12 ms |
6252 KB |
Output is correct |
8 |
Correct |
23 ms |
9068 KB |
Output is correct |
9 |
Correct |
25 ms |
9068 KB |
Output is correct |
10 |
Correct |
24 ms |
9068 KB |
Output is correct |
11 |
Correct |
23 ms |
9068 KB |
Output is correct |
12 |
Correct |
15 ms |
9068 KB |
Output is correct |
13 |
Correct |
23 ms |
9068 KB |
Output is correct |
14 |
Correct |
19 ms |
9068 KB |
Output is correct |
15 |
Correct |
17 ms |
9068 KB |
Output is correct |
16 |
Correct |
19 ms |
9068 KB |
Output is correct |
17 |
Correct |
22 ms |
9068 KB |
Output is correct |
18 |
Correct |
15 ms |
9068 KB |
Output is correct |
19 |
Correct |
19 ms |
9068 KB |
Output is correct |
20 |
Correct |
1056 ms |
10856 KB |
Output is correct |
21 |
Correct |
901 ms |
10856 KB |
Output is correct |
22 |
Correct |
1046 ms |
10856 KB |
Output is correct |
23 |
Correct |
1154 ms |
10856 KB |
Output is correct |
24 |
Execution timed out |
2093 ms |
215948 KB |
Time limit exceeded |
25 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
4988 KB |
Output is correct |
2 |
Correct |
7 ms |
5048 KB |
Output is correct |
3 |
Correct |
7 ms |
5080 KB |
Output is correct |
4 |
Correct |
6 ms |
5080 KB |
Output is correct |
5 |
Correct |
12 ms |
6252 KB |
Output is correct |
6 |
Correct |
12 ms |
6252 KB |
Output is correct |
7 |
Correct |
12 ms |
6252 KB |
Output is correct |
8 |
Correct |
23 ms |
9068 KB |
Output is correct |
9 |
Correct |
25 ms |
9068 KB |
Output is correct |
10 |
Correct |
24 ms |
9068 KB |
Output is correct |
11 |
Correct |
23 ms |
9068 KB |
Output is correct |
12 |
Correct |
15 ms |
9068 KB |
Output is correct |
13 |
Correct |
23 ms |
9068 KB |
Output is correct |
14 |
Correct |
19 ms |
9068 KB |
Output is correct |
15 |
Correct |
17 ms |
9068 KB |
Output is correct |
16 |
Correct |
19 ms |
9068 KB |
Output is correct |
17 |
Correct |
22 ms |
9068 KB |
Output is correct |
18 |
Correct |
15 ms |
9068 KB |
Output is correct |
19 |
Correct |
19 ms |
9068 KB |
Output is correct |
20 |
Correct |
1056 ms |
10856 KB |
Output is correct |
21 |
Correct |
901 ms |
10856 KB |
Output is correct |
22 |
Correct |
1046 ms |
10856 KB |
Output is correct |
23 |
Correct |
1154 ms |
10856 KB |
Output is correct |
24 |
Execution timed out |
2093 ms |
215948 KB |
Time limit exceeded |
25 |
Halted |
0 ms |
0 KB |
- |