#include <bits/stdc++.h>
#define ALL(x) x.begin(), x.end()
#define pii pair<int,int>
const int MAXN = 1e5 + 64;
const int SQRT = 200;
using namespace std;
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx2,popcnt,lzcnt,abm,bmi,bmi2,fma,tune=native")
int block[MAXN], dp[MAXN], order[MAXN], tempo;
vector<int> trafo[MAXN];
pii best[MAXN][3*SQRT+5];
// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int main(){
ios::sync_with_stdio(false);
int n, m, q;
scanf("%d %d %d", &n, &m, &q);
for(int i=0, u, v; i<m; i++)
{
scanf("%d %d", &u, &v);
trafo[v].push_back(u);
dp[u]++;
}
deque<int> fila;
for(int i=1; i<=n; i++) if(!dp[i]) fila.push_back(i);
int od = n;
while(!fila.empty())
{
int u = fila.front(); fila.pop_front();
order[--od] = u;
// shuffle(ALL(trafo[u]), rng);
for(int v : trafo[u])
if(--dp[v] == 0)
fila.push_back(v);
}
order[n] = -1;
for(int u : order)
{
if(u == -1) break;
best[u][0] = pii(0, u);
int sz = 1;
for(auto v : trafo[u]){
for(auto [x, w] : best[v])
{
if(w == -1) break;
best[u][sz++] = pii(x-1, w);
}
if(sz >= 2*SQRT)
{
sort(best[u], best[u]+sz);
sz = min(SQRT, (int)(unique(best[u], best[u]+sz) - best[u]));
}
}
sort(best[u], best[u]+sz);
sz = min(SQRT, (int)(unique(best[u], best[u]+sz) - best[u]));
best[u][sz] = pii(999999, -1);
}
int t, y;
while(q--)
{
tempo++;
scanf("%d %d", &t, &y);
for(int i=0, x; i<y; i++)
{
scanf("%d", &x);
block[x] = tempo;
}
int ans = -1;
for(auto [x, w] : best[t])
{
if(w == -1) break;
if(block[w] != tempo)
{
ans = -x;
break;
}
}
if(ans == -1) for(int u : order)
{
dp[u] = (block[u] == tempo ? -1 : 0);
for(auto v : trafo[u])
if(~dp[v])
dp[u] = max(dp[u], dp[v]+1);
if(u == t){ ans = dp[u]; break; }
}
printf("%d\n", ans);
}
return 0;
}
Compilation message
bitaro.cpp: In function 'int main()':
bitaro.cpp:18:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
18 | scanf("%d %d %d", &n, &m, &q);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
bitaro.cpp:22:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
22 | scanf("%d %d", &u, &v);
| ~~~~~^~~~~~~~~~~~~~~~~
bitaro.cpp:70:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
70 | scanf("%d %d", &t, &y);
| ~~~~~^~~~~~~~~~~~~~~~~
bitaro.cpp:74:9: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
74 | scanf("%d", &x);
| ~~~~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2652 KB |
Output is correct |
2 |
Correct |
1 ms |
2652 KB |
Output is correct |
3 |
Correct |
1 ms |
2768 KB |
Output is correct |
4 |
Correct |
1 ms |
2652 KB |
Output is correct |
5 |
Correct |
7 ms |
7260 KB |
Output is correct |
6 |
Correct |
7 ms |
7188 KB |
Output is correct |
7 |
Correct |
7 ms |
7260 KB |
Output is correct |
8 |
Correct |
9 ms |
7516 KB |
Output is correct |
9 |
Correct |
8 ms |
7516 KB |
Output is correct |
10 |
Correct |
7 ms |
7448 KB |
Output is correct |
11 |
Correct |
8 ms |
7576 KB |
Output is correct |
12 |
Correct |
8 ms |
7260 KB |
Output is correct |
13 |
Correct |
9 ms |
7448 KB |
Output is correct |
14 |
Correct |
9 ms |
7256 KB |
Output is correct |
15 |
Correct |
7 ms |
7004 KB |
Output is correct |
16 |
Correct |
9 ms |
7148 KB |
Output is correct |
17 |
Correct |
9 ms |
7240 KB |
Output is correct |
18 |
Correct |
7 ms |
7108 KB |
Output is correct |
19 |
Correct |
14 ms |
7444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2652 KB |
Output is correct |
2 |
Correct |
1 ms |
2652 KB |
Output is correct |
3 |
Correct |
1 ms |
2768 KB |
Output is correct |
4 |
Correct |
1 ms |
2652 KB |
Output is correct |
5 |
Correct |
7 ms |
7260 KB |
Output is correct |
6 |
Correct |
7 ms |
7188 KB |
Output is correct |
7 |
Correct |
7 ms |
7260 KB |
Output is correct |
8 |
Correct |
9 ms |
7516 KB |
Output is correct |
9 |
Correct |
8 ms |
7516 KB |
Output is correct |
10 |
Correct |
7 ms |
7448 KB |
Output is correct |
11 |
Correct |
8 ms |
7576 KB |
Output is correct |
12 |
Correct |
8 ms |
7260 KB |
Output is correct |
13 |
Correct |
9 ms |
7448 KB |
Output is correct |
14 |
Correct |
9 ms |
7256 KB |
Output is correct |
15 |
Correct |
7 ms |
7004 KB |
Output is correct |
16 |
Correct |
9 ms |
7148 KB |
Output is correct |
17 |
Correct |
9 ms |
7240 KB |
Output is correct |
18 |
Correct |
7 ms |
7108 KB |
Output is correct |
19 |
Correct |
14 ms |
7444 KB |
Output is correct |
20 |
Correct |
714 ms |
10144 KB |
Output is correct |
21 |
Correct |
642 ms |
10320 KB |
Output is correct |
22 |
Correct |
757 ms |
10364 KB |
Output is correct |
23 |
Correct |
706 ms |
10200 KB |
Output is correct |
24 |
Correct |
1239 ms |
467204 KB |
Output is correct |
25 |
Correct |
1186 ms |
466848 KB |
Output is correct |
26 |
Correct |
1161 ms |
467288 KB |
Output is correct |
27 |
Correct |
559 ms |
483116 KB |
Output is correct |
28 |
Correct |
616 ms |
483248 KB |
Output is correct |
29 |
Correct |
618 ms |
482900 KB |
Output is correct |
30 |
Correct |
657 ms |
483216 KB |
Output is correct |
31 |
Correct |
807 ms |
482116 KB |
Output is correct |
32 |
Correct |
666 ms |
483152 KB |
Output is correct |
33 |
Correct |
696 ms |
455760 KB |
Output is correct |
34 |
Correct |
809 ms |
450132 KB |
Output is correct |
35 |
Correct |
731 ms |
455152 KB |
Output is correct |
36 |
Correct |
763 ms |
469328 KB |
Output is correct |
37 |
Correct |
1012 ms |
466256 KB |
Output is correct |
38 |
Correct |
769 ms |
469336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2652 KB |
Output is correct |
2 |
Correct |
1 ms |
2652 KB |
Output is correct |
3 |
Correct |
1 ms |
2768 KB |
Output is correct |
4 |
Correct |
1 ms |
2652 KB |
Output is correct |
5 |
Correct |
7 ms |
7260 KB |
Output is correct |
6 |
Correct |
7 ms |
7188 KB |
Output is correct |
7 |
Correct |
7 ms |
7260 KB |
Output is correct |
8 |
Correct |
9 ms |
7516 KB |
Output is correct |
9 |
Correct |
8 ms |
7516 KB |
Output is correct |
10 |
Correct |
7 ms |
7448 KB |
Output is correct |
11 |
Correct |
8 ms |
7576 KB |
Output is correct |
12 |
Correct |
8 ms |
7260 KB |
Output is correct |
13 |
Correct |
9 ms |
7448 KB |
Output is correct |
14 |
Correct |
9 ms |
7256 KB |
Output is correct |
15 |
Correct |
7 ms |
7004 KB |
Output is correct |
16 |
Correct |
9 ms |
7148 KB |
Output is correct |
17 |
Correct |
9 ms |
7240 KB |
Output is correct |
18 |
Correct |
7 ms |
7108 KB |
Output is correct |
19 |
Correct |
14 ms |
7444 KB |
Output is correct |
20 |
Correct |
714 ms |
10144 KB |
Output is correct |
21 |
Correct |
642 ms |
10320 KB |
Output is correct |
22 |
Correct |
757 ms |
10364 KB |
Output is correct |
23 |
Correct |
706 ms |
10200 KB |
Output is correct |
24 |
Correct |
1239 ms |
467204 KB |
Output is correct |
25 |
Correct |
1186 ms |
466848 KB |
Output is correct |
26 |
Correct |
1161 ms |
467288 KB |
Output is correct |
27 |
Correct |
559 ms |
483116 KB |
Output is correct |
28 |
Correct |
616 ms |
483248 KB |
Output is correct |
29 |
Correct |
618 ms |
482900 KB |
Output is correct |
30 |
Correct |
657 ms |
483216 KB |
Output is correct |
31 |
Correct |
807 ms |
482116 KB |
Output is correct |
32 |
Correct |
666 ms |
483152 KB |
Output is correct |
33 |
Correct |
696 ms |
455760 KB |
Output is correct |
34 |
Correct |
809 ms |
450132 KB |
Output is correct |
35 |
Correct |
731 ms |
455152 KB |
Output is correct |
36 |
Correct |
763 ms |
469328 KB |
Output is correct |
37 |
Correct |
1012 ms |
466256 KB |
Output is correct |
38 |
Correct |
769 ms |
469336 KB |
Output is correct |
39 |
Correct |
1209 ms |
468008 KB |
Output is correct |
40 |
Correct |
1196 ms |
467424 KB |
Output is correct |
41 |
Correct |
1239 ms |
467640 KB |
Output is correct |
42 |
Correct |
1217 ms |
468028 KB |
Output is correct |
43 |
Correct |
1212 ms |
467604 KB |
Output is correct |
44 |
Correct |
736 ms |
11600 KB |
Output is correct |
45 |
Correct |
704 ms |
10716 KB |
Output is correct |
46 |
Correct |
703 ms |
10728 KB |
Output is correct |
47 |
Correct |
709 ms |
10276 KB |
Output is correct |
48 |
Correct |
690 ms |
10320 KB |
Output is correct |
49 |
Correct |
699 ms |
484176 KB |
Output is correct |
50 |
Correct |
1193 ms |
482868 KB |
Output is correct |
51 |
Correct |
689 ms |
11376 KB |
Output is correct |
52 |
Correct |
927 ms |
10568 KB |
Output is correct |
53 |
Correct |
859 ms |
469736 KB |
Output is correct |
54 |
Correct |
958 ms |
466856 KB |
Output is correct |
55 |
Correct |
1399 ms |
468412 KB |
Output is correct |
56 |
Correct |
982 ms |
466000 KB |
Output is correct |
57 |
Correct |
734 ms |
11328 KB |
Output is correct |
58 |
Correct |
781 ms |
11344 KB |
Output is correct |
59 |
Correct |
985 ms |
10572 KB |
Output is correct |
60 |
Correct |
988 ms |
10568 KB |
Output is correct |
61 |
Correct |
702 ms |
482900 KB |
Output is correct |
62 |
Correct |
806 ms |
468956 KB |
Output is correct |
63 |
Correct |
974 ms |
465744 KB |
Output is correct |
64 |
Correct |
837 ms |
482888 KB |
Output is correct |
65 |
Correct |
880 ms |
468468 KB |
Output is correct |
66 |
Correct |
1089 ms |
466028 KB |
Output is correct |
67 |
Correct |
911 ms |
482984 KB |
Output is correct |
68 |
Correct |
987 ms |
469332 KB |
Output is correct |
69 |
Correct |
973 ms |
465148 KB |
Output is correct |
70 |
Correct |
635 ms |
483156 KB |
Output is correct |
71 |
Correct |
703 ms |
469072 KB |
Output is correct |
72 |
Correct |
1014 ms |
465904 KB |
Output is correct |
73 |
Correct |
682 ms |
482972 KB |
Output is correct |
74 |
Correct |
818 ms |
468568 KB |
Output is correct |
75 |
Correct |
991 ms |
465748 KB |
Output is correct |
76 |
Correct |
755 ms |
484716 KB |
Output is correct |
77 |
Correct |
691 ms |
483576 KB |
Output is correct |
78 |
Correct |
680 ms |
483508 KB |
Output is correct |
79 |
Correct |
806 ms |
11540 KB |
Output is correct |
80 |
Correct |
712 ms |
10628 KB |
Output is correct |
81 |
Correct |
778 ms |
10236 KB |
Output is correct |
82 |
Correct |
661 ms |
484952 KB |
Output is correct |
83 |
Correct |
912 ms |
483668 KB |
Output is correct |
84 |
Correct |
667 ms |
483664 KB |
Output is correct |
85 |
Correct |
889 ms |
482336 KB |
Output is correct |
86 |
Correct |
700 ms |
483668 KB |
Output is correct |
87 |
Correct |
812 ms |
482388 KB |
Output is correct |
88 |
Correct |
708 ms |
11456 KB |
Output is correct |
89 |
Correct |
667 ms |
11604 KB |
Output is correct |
90 |
Correct |
674 ms |
10492 KB |
Output is correct |
91 |
Correct |
694 ms |
10696 KB |
Output is correct |
92 |
Correct |
771 ms |
10324 KB |
Output is correct |
93 |
Correct |
691 ms |
10272 KB |
Output is correct |
94 |
Correct |
784 ms |
457376 KB |
Output is correct |
95 |
Correct |
763 ms |
451164 KB |
Output is correct |
96 |
Correct |
776 ms |
455604 KB |
Output is correct |
97 |
Correct |
718 ms |
450896 KB |
Output is correct |
98 |
Correct |
713 ms |
455524 KB |
Output is correct |
99 |
Correct |
690 ms |
450644 KB |
Output is correct |
100 |
Correct |
694 ms |
11616 KB |
Output is correct |
101 |
Correct |
719 ms |
11644 KB |
Output is correct |
102 |
Correct |
668 ms |
10604 KB |
Output is correct |
103 |
Correct |
664 ms |
10720 KB |
Output is correct |
104 |
Correct |
604 ms |
10324 KB |
Output is correct |
105 |
Correct |
611 ms |
10324 KB |
Output is correct |
106 |
Correct |
756 ms |
470632 KB |
Output is correct |
107 |
Correct |
906 ms |
467280 KB |
Output is correct |
108 |
Correct |
678 ms |
469504 KB |
Output is correct |
109 |
Correct |
848 ms |
465944 KB |
Output is correct |
110 |
Correct |
684 ms |
469728 KB |
Output is correct |
111 |
Correct |
879 ms |
466516 KB |
Output is correct |
112 |
Correct |
688 ms |
11656 KB |
Output is correct |
113 |
Correct |
656 ms |
11604 KB |
Output is correct |
114 |
Correct |
645 ms |
10652 KB |
Output is correct |
115 |
Correct |
721 ms |
10580 KB |
Output is correct |
116 |
Correct |
682 ms |
10320 KB |
Output is correct |
117 |
Correct |
754 ms |
10356 KB |
Output is correct |
118 |
Execution timed out |
2049 ms |
482896 KB |
Time limit exceeded |
119 |
Halted |
0 ms |
0 KB |
- |