Submission #95087

# Submission time Handle Problem Language Result Execution time Memory
95087 2019-01-27T08:06:02 Z ImaniAm Bitaro’s Party (JOI18_bitaro) C++14
100 / 100
1224 ms 261804 KB
#include <bits/stdc++.h>

using namespace std;

#define pb push_back

typedef pair <int, int> pii;

const int maxn = 1e5 + 10, maxm = 2e5 + 10, sq = 320;
int n, m, q, size[maxn], h[maxn], input[maxn];
vector <pii> mx[maxn], vec;
vector <int> in[maxn];
bitset <maxn> mark;

int main(){
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> n >> m >> q;
	for (int i = 0; i < n; ++i)
		mx[i].reserve(sq);
	for (int i = 0, v, u; i < m; ++i) {
		cin >> v >> u;
		in[--u].pb(--v);
	}
	for (int i = 0; i < n; ++i) {
		mx[i].pb({-1, i});
		for (auto j: in[i]) {
			int se = mx[i].size(), se2 = mx[j].size();
			vec.resize(se + se2);
			merge(mx[i].begin(), mx[i].end(), mx[j].begin(), mx[j].end(), vec.begin());
			mx[i].clear();
			mx[i].reserve(sq);
			for (int j = se + se2 - 1, ptr = 0; ~j; --j)
				if (!mark[vec[j].second]) {
					mark[vec[j].second] = true;
					mx[i].pb(vec[j]);
					if (++ptr == sq - 1)
						break;
				}
			reverse(mx[i].begin(), mx[i].end());
			for (auto j: mx[i])
				mark[j.second] = false;
		}
		size[i] = mx[i].size();
		for (int j = 0; j < size[i]; ++j)
			mx[i][j].first++;
	}
	for (int i = 0, v, num; i < q; ++i) {
		cin >> v >> num; --v;
		for (int j = 0; j < num; ++j) {
			cin >> input[j];
			mark[--input[j]] = true;
		}
		int ans = -1;
		for (int j = 0; j < size[v]; ++j)
			if (!mark[mx[v][j].second])
				ans = mx[v][j].first;
		if (ans == -1) {
			memset(h, -63, sizeof(h));
			h[v] = 0;
			for (int j = v; ~j; --j) {
				if (!mark[j])
					ans = max(ans, h[j]);
				for (auto u: in[j])
					h[u] = max(h[u], h[j] + 1);
			}
		}
		cout << ans << '\n';
		for (int j = 0; j < num; ++j)
			mark[input[j]] = false;
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 4984 KB Output is correct
2 Correct 5 ms 5496 KB Output is correct
3 Correct 6 ms 5496 KB Output is correct
4 Correct 5 ms 5368 KB Output is correct
5 Correct 9 ms 7544 KB Output is correct
6 Correct 9 ms 7544 KB Output is correct
7 Correct 9 ms 7544 KB Output is correct
8 Correct 12 ms 7672 KB Output is correct
9 Correct 13 ms 7544 KB Output is correct
10 Correct 12 ms 8056 KB Output is correct
11 Correct 12 ms 7544 KB Output is correct
12 Correct 10 ms 7544 KB Output is correct
13 Correct 13 ms 8056 KB Output is correct
14 Correct 13 ms 8056 KB Output is correct
15 Correct 11 ms 7672 KB Output is correct
16 Correct 14 ms 7672 KB Output is correct
17 Correct 14 ms 7672 KB Output is correct
18 Correct 12 ms 7672 KB Output is correct
19 Correct 14 ms 7544 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 4984 KB Output is correct
2 Correct 5 ms 5496 KB Output is correct
3 Correct 6 ms 5496 KB Output is correct
4 Correct 5 ms 5368 KB Output is correct
5 Correct 9 ms 7544 KB Output is correct
6 Correct 9 ms 7544 KB Output is correct
7 Correct 9 ms 7544 KB Output is correct
8 Correct 12 ms 7672 KB Output is correct
9 Correct 13 ms 7544 KB Output is correct
10 Correct 12 ms 8056 KB Output is correct
11 Correct 12 ms 7544 KB Output is correct
12 Correct 10 ms 7544 KB Output is correct
13 Correct 13 ms 8056 KB Output is correct
14 Correct 13 ms 8056 KB Output is correct
15 Correct 11 ms 7672 KB Output is correct
16 Correct 14 ms 7672 KB Output is correct
17 Correct 14 ms 7672 KB Output is correct
18 Correct 12 ms 7672 KB Output is correct
19 Correct 14 ms 7544 KB Output is correct
20 Correct 623 ms 8956 KB Output is correct
21 Correct 496 ms 8952 KB Output is correct
22 Correct 621 ms 9372 KB Output is correct
23 Correct 682 ms 8840 KB Output is correct
24 Correct 1113 ms 260668 KB Output is correct
25 Correct 1224 ms 260548 KB Output is correct
26 Correct 1161 ms 260988 KB Output is correct
27 Correct 949 ms 260984 KB Output is correct
28 Correct 923 ms 260924 KB Output is correct
29 Correct 941 ms 261292 KB Output is correct
30 Correct 1008 ms 260872 KB Output is correct
31 Correct 926 ms 261048 KB Output is correct
32 Correct 932 ms 261368 KB Output is correct
33 Correct 891 ms 260568 KB Output is correct
34 Correct 786 ms 260472 KB Output is correct
35 Correct 967 ms 260572 KB Output is correct
36 Correct 890 ms 260612 KB Output is correct
37 Correct 863 ms 260520 KB Output is correct
38 Correct 888 ms 261008 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 4984 KB Output is correct
2 Correct 5 ms 5496 KB Output is correct
3 Correct 6 ms 5496 KB Output is correct
4 Correct 5 ms 5368 KB Output is correct
5 Correct 9 ms 7544 KB Output is correct
6 Correct 9 ms 7544 KB Output is correct
7 Correct 9 ms 7544 KB Output is correct
8 Correct 12 ms 7672 KB Output is correct
9 Correct 13 ms 7544 KB Output is correct
10 Correct 12 ms 8056 KB Output is correct
11 Correct 12 ms 7544 KB Output is correct
12 Correct 10 ms 7544 KB Output is correct
13 Correct 13 ms 8056 KB Output is correct
14 Correct 13 ms 8056 KB Output is correct
15 Correct 11 ms 7672 KB Output is correct
16 Correct 14 ms 7672 KB Output is correct
17 Correct 14 ms 7672 KB Output is correct
18 Correct 12 ms 7672 KB Output is correct
19 Correct 14 ms 7544 KB Output is correct
20 Correct 623 ms 8956 KB Output is correct
21 Correct 496 ms 8952 KB Output is correct
22 Correct 621 ms 9372 KB Output is correct
23 Correct 682 ms 8840 KB Output is correct
24 Correct 1113 ms 260668 KB Output is correct
25 Correct 1224 ms 260548 KB Output is correct
26 Correct 1161 ms 260988 KB Output is correct
27 Correct 949 ms 260984 KB Output is correct
28 Correct 923 ms 260924 KB Output is correct
29 Correct 941 ms 261292 KB Output is correct
30 Correct 1008 ms 260872 KB Output is correct
31 Correct 926 ms 261048 KB Output is correct
32 Correct 932 ms 261368 KB Output is correct
33 Correct 891 ms 260568 KB Output is correct
34 Correct 786 ms 260472 KB Output is correct
35 Correct 967 ms 260572 KB Output is correct
36 Correct 890 ms 260612 KB Output is correct
37 Correct 863 ms 260520 KB Output is correct
38 Correct 888 ms 261008 KB Output is correct
39 Correct 1093 ms 260664 KB Output is correct
40 Correct 1027 ms 260428 KB Output is correct
41 Correct 1024 ms 260344 KB Output is correct
42 Correct 1029 ms 260620 KB Output is correct
43 Correct 1041 ms 260392 KB Output is correct
44 Correct 680 ms 9336 KB Output is correct
45 Correct 624 ms 8952 KB Output is correct
46 Correct 629 ms 8824 KB Output is correct
47 Correct 608 ms 8924 KB Output is correct
48 Correct 602 ms 8952 KB Output is correct
49 Correct 1155 ms 261804 KB Output is correct
50 Correct 959 ms 261244 KB Output is correct
51 Correct 573 ms 9688 KB Output is correct
52 Correct 512 ms 9340 KB Output is correct
53 Correct 1195 ms 261300 KB Output is correct
54 Correct 1074 ms 260788 KB Output is correct
55 Correct 963 ms 260504 KB Output is correct
56 Correct 917 ms 260696 KB Output is correct
57 Correct 670 ms 9732 KB Output is correct
58 Correct 692 ms 9592 KB Output is correct
59 Correct 577 ms 9208 KB Output is correct
60 Correct 632 ms 9336 KB Output is correct
61 Correct 992 ms 261196 KB Output is correct
62 Correct 1012 ms 260816 KB Output is correct
63 Correct 863 ms 260792 KB Output is correct
64 Correct 1030 ms 261172 KB Output is correct
65 Correct 996 ms 260880 KB Output is correct
66 Correct 864 ms 260788 KB Output is correct
67 Correct 928 ms 261120 KB Output is correct
68 Correct 960 ms 260776 KB Output is correct
69 Correct 936 ms 260328 KB Output is correct
70 Correct 1000 ms 261152 KB Output is correct
71 Correct 994 ms 260824 KB Output is correct
72 Correct 969 ms 260792 KB Output is correct
73 Correct 1022 ms 261172 KB Output is correct
74 Correct 1070 ms 260916 KB Output is correct
75 Correct 983 ms 260696 KB Output is correct
76 Correct 1157 ms 261548 KB Output is correct
77 Correct 1002 ms 260768 KB Output is correct
78 Correct 1018 ms 260784 KB Output is correct
79 Correct 567 ms 9336 KB Output is correct
80 Correct 501 ms 9080 KB Output is correct
81 Correct 494 ms 8924 KB Output is correct
82 Correct 1158 ms 261624 KB Output is correct
83 Correct 1208 ms 261152 KB Output is correct
84 Correct 975 ms 260916 KB Output is correct
85 Correct 989 ms 260840 KB Output is correct
86 Correct 957 ms 261016 KB Output is correct
87 Correct 932 ms 260808 KB Output is correct
88 Correct 680 ms 9208 KB Output is correct
89 Correct 679 ms 9208 KB Output is correct
90 Correct 612 ms 8952 KB Output is correct
91 Correct 639 ms 8952 KB Output is correct
92 Correct 601 ms 8952 KB Output is correct
93 Correct 600 ms 9084 KB Output is correct
94 Correct 919 ms 260808 KB Output is correct
95 Correct 901 ms 260640 KB Output is correct
96 Correct 818 ms 260344 KB Output is correct
97 Correct 834 ms 260468 KB Output is correct
98 Correct 832 ms 260472 KB Output is correct
99 Correct 750 ms 260288 KB Output is correct
100 Correct 780 ms 9192 KB Output is correct
101 Correct 721 ms 9324 KB Output is correct
102 Correct 693 ms 8944 KB Output is correct
103 Correct 705 ms 9068 KB Output is correct
104 Correct 687 ms 8868 KB Output is correct
105 Correct 698 ms 8952 KB Output is correct
106 Correct 1097 ms 260860 KB Output is correct
107 Correct 1072 ms 260744 KB Output is correct
108 Correct 950 ms 260512 KB Output is correct
109 Correct 960 ms 260340 KB Output is correct
110 Correct 976 ms 260440 KB Output is correct
111 Correct 933 ms 260524 KB Output is correct
112 Correct 703 ms 9416 KB Output is correct
113 Correct 681 ms 9340 KB Output is correct
114 Correct 636 ms 8956 KB Output is correct
115 Correct 704 ms 8848 KB Output is correct
116 Correct 600 ms 8956 KB Output is correct
117 Correct 625 ms 9080 KB Output is correct
118 Correct 880 ms 261240 KB Output is correct
119 Correct 852 ms 260820 KB Output is correct
120 Correct 847 ms 260844 KB Output is correct
121 Correct 884 ms 260856 KB Output is correct
122 Correct 874 ms 260860 KB Output is correct
123 Correct 854 ms 260372 KB Output is correct
124 Correct 964 ms 261112 KB Output is correct
125 Correct 986 ms 260384 KB Output is correct
126 Correct 845 ms 260348 KB Output is correct