답안 #854963

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
854963 2023-09-29T12:59:42 Z parlimoos Bitaro’s Party (JOI18_bitaro) C++17
100 / 100
875 ms 145688 KB
#include<bits/stdc++.h>
using namespace std;

const int root = 100;

int n , m , q , r;
vector<int> g[100000];
vector<pair<int , int>> lps[100000];
int dels[100000];
int dis[100000];
int ddd[100000][2];

void init(){
	for(int i = 0 ; i < n ; i++){
		vector<int> exs;
		lps[i].push_back({0 , i});
		exs.push_back(i);
		ddd[i][0] = 0;
		ddd[i][1] = i + 1;
		
		for(int v : g[i]){
			for(pair<int , int> el : lps[v]){
				if(ddd[el.second][1] != i + 1){
					exs.push_back(el.second);
					ddd[el.second][1] = i + 1;
					ddd[el.second][0] = el.first + 1;
				}else ddd[el.second][0] = max(ddd[el.second][0] , el.first + 1);
			}
		}
		for(int el : exs){
			lps[i].push_back({ddd[el][0] , el});
		}
		sort(lps[i].begin() , lps[i].end() , greater<pair<int , int>>());
		
		int len = (int)lps[i].size();
		while(len > root){
			lps[i].pop_back();
			len--;
		}
	}
}
void bfs(int op){
	fill(&dis[0] , &dis[100000] , 0);
	for(int i = 0 ; i <= r ; i++){
		for(int u : g[i]){
			dis[i] = max(dis[u] + 1 , dis[i]);
		}
		if(dis[i] == 0 and dels[i] == op){
			dis[i] = -1;
		}
	}
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	cin >> n >> m >> q;
	for(int i = 0 ; i < m ; i++){
		int v , u;
		cin >> v >> u;
		v-- , u--;
		g[u].push_back(v);
	}
	
	if(q > 1) init();
	for(int i = 0 ; i < q ; i++){
		int y;
		cin >> r >> y;
		r--;
		
		for(int j = 0 ; j < y ; j++){
			int d;
			cin >> d;
			d--;
			dels[d] = i + 1;
		}
		if(y >= root or q == 1){
			bfs(i + 1);
			cout << dis[r] << "\n";
		}else{
			int res = -1;
			for(int j = 0 ; j < (int)lps[r].size() ; j++){
				if(dels[lps[r][j].second] != i + 1){
					res = lps[r][j].first;
					break;
				}
			}
			cout << res << "\n";
		}
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6488 KB Output is correct
2 Correct 2 ms 6492 KB Output is correct
3 Correct 2 ms 6492 KB Output is correct
4 Correct 2 ms 6492 KB Output is correct
5 Correct 2 ms 6336 KB Output is correct
6 Correct 2 ms 6492 KB Output is correct
7 Correct 2 ms 6492 KB Output is correct
8 Correct 2 ms 6492 KB Output is correct
9 Correct 2 ms 6492 KB Output is correct
10 Correct 2 ms 6492 KB Output is correct
11 Correct 2 ms 6492 KB Output is correct
12 Correct 2 ms 6492 KB Output is correct
13 Correct 2 ms 6492 KB Output is correct
14 Correct 3 ms 6492 KB Output is correct
15 Correct 3 ms 6492 KB Output is correct
16 Correct 2 ms 6488 KB Output is correct
17 Correct 2 ms 6492 KB Output is correct
18 Correct 2 ms 6492 KB Output is correct
19 Correct 2 ms 6492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6488 KB Output is correct
2 Correct 2 ms 6492 KB Output is correct
3 Correct 2 ms 6492 KB Output is correct
4 Correct 2 ms 6492 KB Output is correct
5 Correct 2 ms 6336 KB Output is correct
6 Correct 2 ms 6492 KB Output is correct
7 Correct 2 ms 6492 KB Output is correct
8 Correct 2 ms 6492 KB Output is correct
9 Correct 2 ms 6492 KB Output is correct
10 Correct 2 ms 6492 KB Output is correct
11 Correct 2 ms 6492 KB Output is correct
12 Correct 2 ms 6492 KB Output is correct
13 Correct 2 ms 6492 KB Output is correct
14 Correct 3 ms 6492 KB Output is correct
15 Correct 3 ms 6492 KB Output is correct
16 Correct 2 ms 6488 KB Output is correct
17 Correct 2 ms 6492 KB Output is correct
18 Correct 2 ms 6492 KB Output is correct
19 Correct 2 ms 6492 KB Output is correct
20 Correct 21 ms 7772 KB Output is correct
21 Correct 23 ms 7772 KB Output is correct
22 Correct 22 ms 7772 KB Output is correct
23 Correct 27 ms 8032 KB Output is correct
24 Correct 37 ms 9308 KB Output is correct
25 Correct 40 ms 9196 KB Output is correct
26 Correct 38 ms 9136 KB Output is correct
27 Correct 41 ms 9560 KB Output is correct
28 Correct 35 ms 9564 KB Output is correct
29 Correct 40 ms 9664 KB Output is correct
30 Correct 53 ms 9724 KB Output is correct
31 Correct 35 ms 9560 KB Output is correct
32 Correct 36 ms 9560 KB Output is correct
33 Correct 35 ms 9052 KB Output is correct
34 Correct 36 ms 9044 KB Output is correct
35 Correct 35 ms 9224 KB Output is correct
36 Correct 36 ms 9304 KB Output is correct
37 Correct 44 ms 9296 KB Output is correct
38 Correct 38 ms 9296 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 6488 KB Output is correct
2 Correct 2 ms 6492 KB Output is correct
3 Correct 2 ms 6492 KB Output is correct
4 Correct 2 ms 6492 KB Output is correct
5 Correct 2 ms 6336 KB Output is correct
6 Correct 2 ms 6492 KB Output is correct
7 Correct 2 ms 6492 KB Output is correct
8 Correct 2 ms 6492 KB Output is correct
9 Correct 2 ms 6492 KB Output is correct
10 Correct 2 ms 6492 KB Output is correct
11 Correct 2 ms 6492 KB Output is correct
12 Correct 2 ms 6492 KB Output is correct
13 Correct 2 ms 6492 KB Output is correct
14 Correct 3 ms 6492 KB Output is correct
15 Correct 3 ms 6492 KB Output is correct
16 Correct 2 ms 6488 KB Output is correct
17 Correct 2 ms 6492 KB Output is correct
18 Correct 2 ms 6492 KB Output is correct
19 Correct 2 ms 6492 KB Output is correct
20 Correct 21 ms 7772 KB Output is correct
21 Correct 23 ms 7772 KB Output is correct
22 Correct 22 ms 7772 KB Output is correct
23 Correct 27 ms 8032 KB Output is correct
24 Correct 37 ms 9308 KB Output is correct
25 Correct 40 ms 9196 KB Output is correct
26 Correct 38 ms 9136 KB Output is correct
27 Correct 41 ms 9560 KB Output is correct
28 Correct 35 ms 9564 KB Output is correct
29 Correct 40 ms 9664 KB Output is correct
30 Correct 53 ms 9724 KB Output is correct
31 Correct 35 ms 9560 KB Output is correct
32 Correct 36 ms 9560 KB Output is correct
33 Correct 35 ms 9052 KB Output is correct
34 Correct 36 ms 9044 KB Output is correct
35 Correct 35 ms 9224 KB Output is correct
36 Correct 36 ms 9304 KB Output is correct
37 Correct 44 ms 9296 KB Output is correct
38 Correct 38 ms 9296 KB Output is correct
39 Correct 631 ms 116688 KB Output is correct
40 Correct 559 ms 112960 KB Output is correct
41 Correct 818 ms 114340 KB Output is correct
42 Correct 626 ms 113492 KB Output is correct
43 Correct 594 ms 115544 KB Output is correct
44 Correct 69 ms 9044 KB Output is correct
45 Correct 56 ms 8680 KB Output is correct
46 Correct 104 ms 8528 KB Output is correct
47 Correct 67 ms 8788 KB Output is correct
48 Correct 50 ms 8600 KB Output is correct
49 Correct 447 ms 112212 KB Output is correct
50 Correct 647 ms 111700 KB Output is correct
51 Correct 69 ms 9012 KB Output is correct
52 Correct 103 ms 8528 KB Output is correct
53 Correct 456 ms 92528 KB Output is correct
54 Correct 611 ms 114624 KB Output is correct
55 Correct 652 ms 92212 KB Output is correct
56 Correct 821 ms 117928 KB Output is correct
57 Correct 68 ms 9040 KB Output is correct
58 Correct 69 ms 9040 KB Output is correct
59 Correct 111 ms 8532 KB Output is correct
60 Correct 106 ms 8784 KB Output is correct
61 Correct 495 ms 111440 KB Output is correct
62 Correct 471 ms 92496 KB Output is correct
63 Correct 613 ms 113412 KB Output is correct
64 Correct 590 ms 111636 KB Output is correct
65 Correct 554 ms 92244 KB Output is correct
66 Correct 734 ms 115624 KB Output is correct
67 Correct 641 ms 111712 KB Output is correct
68 Correct 642 ms 92632 KB Output is correct
69 Correct 799 ms 115112 KB Output is correct
70 Correct 417 ms 111408 KB Output is correct
71 Correct 442 ms 92284 KB Output is correct
72 Correct 579 ms 114800 KB Output is correct
73 Correct 449 ms 111564 KB Output is correct
74 Correct 441 ms 92280 KB Output is correct
75 Correct 583 ms 117016 KB Output is correct
76 Correct 464 ms 112464 KB Output is correct
77 Correct 657 ms 111700 KB Output is correct
78 Correct 417 ms 111440 KB Output is correct
79 Correct 70 ms 9040 KB Output is correct
80 Correct 110 ms 8680 KB Output is correct
81 Correct 50 ms 8632 KB Output is correct
82 Correct 518 ms 112464 KB Output is correct
83 Correct 711 ms 134760 KB Output is correct
84 Correct 666 ms 111444 KB Output is correct
85 Correct 875 ms 145688 KB Output is correct
86 Correct 504 ms 111412 KB Output is correct
87 Correct 642 ms 134264 KB Output is correct
88 Correct 68 ms 8860 KB Output is correct
89 Correct 70 ms 9044 KB Output is correct
90 Correct 104 ms 8672 KB Output is correct
91 Correct 108 ms 8876 KB Output is correct
92 Correct 56 ms 8528 KB Output is correct
93 Correct 52 ms 8528 KB Output is correct
94 Correct 372 ms 76628 KB Output is correct
95 Correct 644 ms 111856 KB Output is correct
96 Correct 549 ms 76148 KB Output is correct
97 Correct 831 ms 112508 KB Output is correct
98 Correct 342 ms 76244 KB Output is correct
99 Correct 579 ms 108532 KB Output is correct
100 Correct 72 ms 9044 KB Output is correct
101 Correct 71 ms 8944 KB Output is correct
102 Correct 91 ms 8708 KB Output is correct
103 Correct 91 ms 8532 KB Output is correct
104 Correct 53 ms 8684 KB Output is correct
105 Correct 57 ms 8552 KB Output is correct
106 Correct 429 ms 92596 KB Output is correct
107 Correct 624 ms 119892 KB Output is correct
108 Correct 647 ms 92668 KB Output is correct
109 Correct 782 ms 110904 KB Output is correct
110 Correct 410 ms 92756 KB Output is correct
111 Correct 589 ms 116812 KB Output is correct
112 Correct 77 ms 8884 KB Output is correct
113 Correct 70 ms 9028 KB Output is correct
114 Correct 100 ms 8532 KB Output is correct
115 Correct 107 ms 8528 KB Output is correct
116 Correct 51 ms 8532 KB Output is correct
117 Correct 52 ms 8856 KB Output is correct
118 Correct 424 ms 111444 KB Output is correct
119 Correct 406 ms 92412 KB Output is correct
120 Correct 591 ms 121172 KB Output is correct
121 Correct 452 ms 111512 KB Output is correct
122 Correct 424 ms 92320 KB Output is correct
123 Correct 600 ms 120148 KB Output is correct
124 Correct 452 ms 111528 KB Output is correct
125 Correct 431 ms 92852 KB Output is correct
126 Correct 591 ms 116796 KB Output is correct