File tree Expand file tree Collapse file tree 1 file changed +81
-0
lines changed Expand file tree Collapse file tree 1 file changed +81
-0
lines changed Original file line number Diff line number Diff line change 1+ /** THIS IS AN OUTPUT FILE. NOT EDIT THIS FILE DIRECTLY. **/
2+ use proconio:: input;
3+ use proconio:: marker:: * ;
4+ use std:: cmp:: Reverse ;
5+ use std:: collections:: * ;
6+
7+ struct Helper {
8+ n : usize ,
9+ m : usize ,
10+ memo : Vec < Vec < usize > > ,
11+ c : Vec < usize > ,
12+ result : usize
13+ }
14+
15+ impl Helper {
16+ fn dfs ( & mut self , i : usize , arr : & mut Vec < usize > ) {
17+ if i == self . n {
18+ let mut count = vec ! [ 0 ; self . m] ;
19+ let mut temp = 0 ;
20+
21+ for j in 0 ..self . n {
22+ let v = arr[ j] ;
23+ for k in & self . memo [ j] {
24+ count[ * k] += v;
25+ }
26+
27+ temp += self . c [ j] * v;
28+ }
29+
30+ let mut flag = true ;
31+ for j in 0 ..self . m {
32+ if count[ j] < 2 {
33+ flag = false ;
34+ break ;
35+ }
36+ }
37+
38+ if flag {
39+ self . result = self . result . min ( temp) ;
40+ }
41+
42+ return ;
43+ }
44+
45+ for j in 0 ..3 {
46+ arr. push ( j) ;
47+ self . dfs ( i+1 , arr) ;
48+ arr. pop ( ) ;
49+ }
50+ }
51+ }
52+
53+ fn main ( ) {
54+ input ! {
55+ n: usize ,
56+ m: usize ,
57+ c: [ usize ; n] ,
58+ }
59+
60+ let mut memo = vec ! [ vec![ ] ; n] ;
61+ for i in 0 ..m {
62+ input ! {
63+ k: usize ,
64+ a: [ Usize1 ; k]
65+ }
66+ for j in a {
67+ memo[ j] . push ( i) ;
68+ }
69+ }
70+
71+ let mut helper = Helper {
72+ n,
73+ m,
74+ memo,
75+ c,
76+ result : usize:: MAX
77+ } ;
78+ helper. dfs ( 0 , & mut vec ! [ ] ) ;
79+
80+ println ! ( "{}" , helper. result) ;
81+ }
You can’t perform that action at this time.
0 commit comments