답안 #410587

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
410587 2021-05-23T05:18:16 Z super_j6 Viruses (BOI20_viruses) C++14
100 / 100
125 ms 19164 KB
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string.h>
#include <vector>
#include <array>
#include <queue>
using namespace std;
#define endl '\n'
#define ll long long
#define pi pair<int, int>
#define f first
#define s second

typedef array<ll, 4> T;

const int mxn = 102;
int n, m, k, u = 1, w = 1;
int a[mxn], lk[mxn];
int b[mxn][mxn], g[mxn][mxn], tr[mxn][2];
ll f[mxn][mxn][mxn], dp[mxn][mxn][mxn];
queue<int> q;
priority_queue<T, vector<T>, greater<T>> pq;

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> m >> k;
	
	for(int i = 0; i < m; i++){
		int x, y, z = 0;
		cin >> x >> y;
		for(int j = 0; j < y; j++){
			int e;
			cin >> e;
			if(!g[z][e]) g[z][e] = u++;
			z = g[z][e];
		}
		b[z][x] = 1;
	}

	for(int i = 0; i < k; i++){
		int x, z = 0;
		cin >> x;
		for(int j = 0; j < x; j++){
			int y;
			cin >> y;
			if(!tr[z][y]) tr[z][y] = w++;
			z = tr[z][y];
		}
		a[z] = 1;
	}
	
	memset(f, 0x3f, sizeof(f));
	q.push(0);
	while(!q.empty()){
		int c = q.front();
		q.pop();
		for(int i = 0; i < 2; i++){
			int &x = tr[c][i], y = c ? tr[lk[c]][i] : 0;
			if(x) lk[x] = y, q.push(x);
			else x = y;
			if(!a[tr[0][i]] && !a[c] && !a[x]) f[i][c][x] = 1;
		}
	}
	
	memset(dp, 0x3f, sizeof(dp));
	for(int i = 0; i < w; i++) if(!a[i]) pq.push({dp[0][i][i] = 0, 0, i, i});
	
	while(!pq.empty()){
		ll c = pq.top()[1], x = pq.top()[2], y = pq.top()[3], d = pq.top()[0];
		pq.pop();
		if(d != dp[c][x][y]) continue;
		for(int i = 0; i < n; i++) if(b[c][i] && f[i][x][y] > d){
			f[i][x][y] = d;
			for(int j = 0, z; j < u; j++) if(z = g[j][i])
			for(int l = 0; l < w; l++){
				if(dp[z][l][y] > dp[j][l][x] + d){
					pq.push({dp[z][l][y] = dp[j][l][x] + d, z, l, y});
				}
			}
		} 
		for(int i = 0, z; i < n; i++) if(z = g[c][i])
		for(int j = 0; j < w; j++){
			if(dp[z][x][j] > d + f[i][y][j]){
				pq.push({dp[z][x][j] = d + f[i][y][j], z, x, j});
			}
		}
	}
	
	for(int i = 2; i < n; i++){
		ll ret = *min_element(f[i][0], f[i][0] + w);
		if(ret < 0x3f3f3f3f3f3f3f3f) cout << "NO " << ret << endl;
		else cout << "YES" << endl;
	}
	
	return 0;
}

Compilation message

Viruses.cpp: In function 'int main()':
Viruses.cpp:77:39: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   77 |    for(int j = 0, z; j < u; j++) if(z = g[j][i])
      |                                     ~~^~~~~~~~~
Viruses.cpp:84:38: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   84 |   for(int i = 0, z; i < n; i++) if(z = g[c][i])
      |                                    ~~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 16844 KB Output is correct
2 Correct 9 ms 16844 KB Output is correct
3 Correct 9 ms 16972 KB Output is correct
4 Correct 9 ms 16844 KB Output is correct
5 Correct 9 ms 16996 KB Output is correct
6 Correct 9 ms 16972 KB Output is correct
7 Correct 9 ms 16936 KB Output is correct
8 Correct 9 ms 16972 KB Output is correct
9 Correct 9 ms 16972 KB Output is correct
10 Correct 9 ms 16904 KB Output is correct
11 Correct 9 ms 16972 KB Output is correct
12 Correct 9 ms 16972 KB Output is correct
13 Correct 9 ms 16972 KB Output is correct
14 Correct 9 ms 16896 KB Output is correct
15 Correct 9 ms 16972 KB Output is correct
16 Correct 9 ms 16972 KB Output is correct
17 Correct 9 ms 16972 KB Output is correct
18 Correct 9 ms 16960 KB Output is correct
19 Correct 9 ms 16972 KB Output is correct
20 Correct 9 ms 16960 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 16844 KB Output is correct
2 Correct 9 ms 16844 KB Output is correct
3 Correct 10 ms 16972 KB Output is correct
4 Correct 10 ms 16972 KB Output is correct
5 Correct 10 ms 16972 KB Output is correct
6 Correct 11 ms 16964 KB Output is correct
7 Correct 11 ms 16972 KB Output is correct
8 Correct 10 ms 17024 KB Output is correct
9 Correct 10 ms 16972 KB Output is correct
10 Correct 9 ms 16836 KB Output is correct
11 Correct 9 ms 16844 KB Output is correct
12 Correct 9 ms 16964 KB Output is correct
13 Correct 10 ms 16992 KB Output is correct
14 Correct 9 ms 16844 KB Output is correct
15 Correct 10 ms 16868 KB Output is correct
16 Correct 9 ms 16844 KB Output is correct
17 Correct 9 ms 16972 KB Output is correct
18 Correct 9 ms 16972 KB Output is correct
19 Correct 9 ms 16972 KB Output is correct
20 Correct 9 ms 16972 KB Output is correct
21 Correct 10 ms 16960 KB Output is correct
22 Correct 9 ms 16844 KB Output is correct
23 Correct 9 ms 16844 KB Output is correct
24 Correct 9 ms 16844 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 16972 KB Output is correct
2 Correct 10 ms 16972 KB Output is correct
3 Correct 10 ms 16972 KB Output is correct
4 Correct 11 ms 16964 KB Output is correct
5 Correct 11 ms 16972 KB Output is correct
6 Correct 10 ms 17024 KB Output is correct
7 Correct 10 ms 16972 KB Output is correct
8 Correct 9 ms 16972 KB Output is correct
9 Correct 9 ms 16972 KB Output is correct
10 Correct 9 ms 16916 KB Output is correct
11 Correct 9 ms 16968 KB Output is correct
12 Correct 9 ms 16968 KB Output is correct
13 Correct 9 ms 16980 KB Output is correct
14 Correct 9 ms 16972 KB Output is correct
15 Correct 9 ms 16972 KB Output is correct
16 Correct 9 ms 16964 KB Output is correct
17 Correct 9 ms 16976 KB Output is correct
18 Correct 9 ms 16972 KB Output is correct
19 Correct 9 ms 16972 KB Output is correct
20 Correct 9 ms 16960 KB Output is correct
21 Correct 9 ms 16972 KB Output is correct
22 Correct 9 ms 16972 KB Output is correct
23 Correct 9 ms 16972 KB Output is correct
24 Correct 9 ms 16956 KB Output is correct
25 Correct 11 ms 17084 KB Output is correct
26 Correct 10 ms 16844 KB Output is correct
27 Correct 125 ms 17404 KB Output is correct
28 Correct 11 ms 17012 KB Output is correct
29 Correct 94 ms 16972 KB Output is correct
30 Correct 87 ms 17096 KB Output is correct
31 Correct 14 ms 17076 KB Output is correct
32 Correct 12 ms 16972 KB Output is correct
33 Correct 12 ms 16956 KB Output is correct
34 Correct 82 ms 17012 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 16844 KB Output is correct
2 Correct 9 ms 16844 KB Output is correct
3 Correct 9 ms 16972 KB Output is correct
4 Correct 9 ms 16844 KB Output is correct
5 Correct 9 ms 16996 KB Output is correct
6 Correct 9 ms 16972 KB Output is correct
7 Correct 9 ms 16936 KB Output is correct
8 Correct 9 ms 16972 KB Output is correct
9 Correct 9 ms 16972 KB Output is correct
10 Correct 9 ms 16904 KB Output is correct
11 Correct 9 ms 16972 KB Output is correct
12 Correct 9 ms 16972 KB Output is correct
13 Correct 9 ms 16972 KB Output is correct
14 Correct 9 ms 16896 KB Output is correct
15 Correct 9 ms 16972 KB Output is correct
16 Correct 9 ms 16972 KB Output is correct
17 Correct 9 ms 16972 KB Output is correct
18 Correct 9 ms 16960 KB Output is correct
19 Correct 9 ms 16972 KB Output is correct
20 Correct 9 ms 16960 KB Output is correct
21 Correct 9 ms 16836 KB Output is correct
22 Correct 9 ms 16972 KB Output is correct
23 Correct 9 ms 16972 KB Output is correct
24 Correct 9 ms 16916 KB Output is correct
25 Correct 9 ms 16968 KB Output is correct
26 Correct 9 ms 16968 KB Output is correct
27 Correct 9 ms 16980 KB Output is correct
28 Correct 9 ms 16972 KB Output is correct
29 Correct 9 ms 16972 KB Output is correct
30 Correct 9 ms 16964 KB Output is correct
31 Correct 9 ms 16976 KB Output is correct
32 Correct 9 ms 16972 KB Output is correct
33 Correct 9 ms 16972 KB Output is correct
34 Correct 9 ms 16960 KB Output is correct
35 Correct 9 ms 16972 KB Output is correct
36 Correct 9 ms 16972 KB Output is correct
37 Correct 9 ms 16972 KB Output is correct
38 Correct 9 ms 16956 KB Output is correct
39 Correct 9 ms 16844 KB Output is correct
40 Correct 9 ms 16920 KB Output is correct
41 Correct 9 ms 16844 KB Output is correct
42 Correct 9 ms 16836 KB Output is correct
43 Correct 9 ms 16972 KB Output is correct
44 Correct 9 ms 16972 KB Output is correct
45 Correct 9 ms 16960 KB Output is correct
46 Correct 9 ms 16972 KB Output is correct
47 Correct 9 ms 16972 KB Output is correct
48 Correct 10 ms 16972 KB Output is correct
49 Correct 9 ms 16968 KB Output is correct
50 Correct 9 ms 16972 KB Output is correct
51 Correct 9 ms 16972 KB Output is correct
52 Correct 10 ms 16956 KB Output is correct
53 Correct 9 ms 16968 KB Output is correct
54 Correct 9 ms 16972 KB Output is correct
55 Correct 9 ms 16972 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 16844 KB Output is correct
2 Correct 9 ms 16844 KB Output is correct
3 Correct 9 ms 16972 KB Output is correct
4 Correct 9 ms 16844 KB Output is correct
5 Correct 9 ms 16996 KB Output is correct
6 Correct 9 ms 16972 KB Output is correct
7 Correct 9 ms 16936 KB Output is correct
8 Correct 9 ms 16972 KB Output is correct
9 Correct 9 ms 16972 KB Output is correct
10 Correct 9 ms 16904 KB Output is correct
11 Correct 9 ms 16972 KB Output is correct
12 Correct 9 ms 16972 KB Output is correct
13 Correct 9 ms 16972 KB Output is correct
14 Correct 9 ms 16896 KB Output is correct
15 Correct 9 ms 16972 KB Output is correct
16 Correct 9 ms 16972 KB Output is correct
17 Correct 9 ms 16972 KB Output is correct
18 Correct 9 ms 16960 KB Output is correct
19 Correct 9 ms 16972 KB Output is correct
20 Correct 9 ms 16960 KB Output is correct
21 Correct 10 ms 16972 KB Output is correct
22 Correct 10 ms 16972 KB Output is correct
23 Correct 10 ms 16972 KB Output is correct
24 Correct 11 ms 16964 KB Output is correct
25 Correct 11 ms 16972 KB Output is correct
26 Correct 10 ms 17024 KB Output is correct
27 Correct 10 ms 16972 KB Output is correct
28 Correct 9 ms 16836 KB Output is correct
29 Correct 9 ms 16844 KB Output is correct
30 Correct 9 ms 16964 KB Output is correct
31 Correct 10 ms 16992 KB Output is correct
32 Correct 9 ms 16844 KB Output is correct
33 Correct 10 ms 16868 KB Output is correct
34 Correct 9 ms 16844 KB Output is correct
35 Correct 9 ms 16972 KB Output is correct
36 Correct 9 ms 16972 KB Output is correct
37 Correct 9 ms 16972 KB Output is correct
38 Correct 9 ms 16972 KB Output is correct
39 Correct 10 ms 16960 KB Output is correct
40 Correct 9 ms 16844 KB Output is correct
41 Correct 9 ms 16844 KB Output is correct
42 Correct 9 ms 16844 KB Output is correct
43 Correct 9 ms 16972 KB Output is correct
44 Correct 9 ms 16972 KB Output is correct
45 Correct 9 ms 16916 KB Output is correct
46 Correct 9 ms 16968 KB Output is correct
47 Correct 9 ms 16968 KB Output is correct
48 Correct 9 ms 16980 KB Output is correct
49 Correct 9 ms 16972 KB Output is correct
50 Correct 9 ms 16972 KB Output is correct
51 Correct 9 ms 16964 KB Output is correct
52 Correct 9 ms 16976 KB Output is correct
53 Correct 9 ms 16972 KB Output is correct
54 Correct 9 ms 16972 KB Output is correct
55 Correct 9 ms 16960 KB Output is correct
56 Correct 9 ms 16972 KB Output is correct
57 Correct 9 ms 16972 KB Output is correct
58 Correct 9 ms 16972 KB Output is correct
59 Correct 9 ms 16956 KB Output is correct
60 Correct 11 ms 17084 KB Output is correct
61 Correct 10 ms 16844 KB Output is correct
62 Correct 125 ms 17404 KB Output is correct
63 Correct 11 ms 17012 KB Output is correct
64 Correct 94 ms 16972 KB Output is correct
65 Correct 87 ms 17096 KB Output is correct
66 Correct 14 ms 17076 KB Output is correct
67 Correct 12 ms 16972 KB Output is correct
68 Correct 12 ms 16956 KB Output is correct
69 Correct 82 ms 17012 KB Output is correct
70 Correct 9 ms 16844 KB Output is correct
71 Correct 9 ms 16920 KB Output is correct
72 Correct 9 ms 16844 KB Output is correct
73 Correct 9 ms 16836 KB Output is correct
74 Correct 9 ms 16972 KB Output is correct
75 Correct 9 ms 16972 KB Output is correct
76 Correct 9 ms 16960 KB Output is correct
77 Correct 9 ms 16972 KB Output is correct
78 Correct 9 ms 16972 KB Output is correct
79 Correct 10 ms 16972 KB Output is correct
80 Correct 9 ms 16968 KB Output is correct
81 Correct 9 ms 16972 KB Output is correct
82 Correct 9 ms 16972 KB Output is correct
83 Correct 10 ms 16956 KB Output is correct
84 Correct 9 ms 16968 KB Output is correct
85 Correct 9 ms 16972 KB Output is correct
86 Correct 9 ms 16972 KB Output is correct
87 Correct 15 ms 17100 KB Output is correct
88 Correct 9 ms 16844 KB Output is correct
89 Correct 9 ms 16836 KB Output is correct
90 Correct 9 ms 16972 KB Output is correct
91 Correct 9 ms 17012 KB Output is correct
92 Correct 39 ms 19164 KB Output is correct
93 Correct 29 ms 18124 KB Output is correct
94 Correct 9 ms 16972 KB Output is correct
95 Correct 9 ms 16968 KB Output is correct
96 Correct 10 ms 16972 KB Output is correct
97 Correct 15 ms 17356 KB Output is correct
98 Correct 9 ms 16964 KB Output is correct
99 Correct 19 ms 17192 KB Output is correct
100 Correct 9 ms 16972 KB Output is correct
101 Correct 11 ms 17020 KB Output is correct
102 Correct 57 ms 17616 KB Output is correct
103 Correct 11 ms 17100 KB Output is correct
104 Correct 22 ms 17116 KB Output is correct
105 Correct 9 ms 16972 KB Output is correct
106 Correct 43 ms 17600 KB Output is correct
107 Correct 47 ms 18040 KB Output is correct