forked from mpfeifer1/Kattis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpizzahawaii.cpp
86 lines (69 loc) · 1.99 KB
/
pizzahawaii.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
int cases;
cin >> cases;
while(cases--) {
int n;
cin >> n;
unordered_map<string, vector<unordered_set<string>>> m;
vector<pair<unordered_set<string>,unordered_set<string>>> pizzas;
for(int i = 0; i < n; i++) {
string s;
cin >> s;
int s1,s2;
cin >> s1;
vector<string> v(s1);
unordered_set<string> top;
for(auto& i : v) {
cin >> i;
top.insert(i);
}
cin >> s2;
unordered_set<string> w;
for(int i = 0; i < s2; i++) {
string temp;
cin >> temp;
w.insert(temp);
}
for(auto i : v) {
m[i].push_back(w);
}
pizzas.push_back({top, w});
}
set<pair<string,string>> s;
// For each ingredient
for(auto i : m) {
// For all of its sets
unordered_set<string> all = i.second[0];
for(auto j : i.second) {
unordered_set<string> next;
// For everything in set, make sure it's in both
for(auto k : j) {
if(all.count(k) > 0) {
next.insert(k);
}
}
all.clear();
all = next;
}
for(auto j : all) {
s.insert({i.first, j});
}
}
for(auto i : s) {
bool works = true;
for(auto j : pizzas) {
if(j.first.count(i.first) != j.second.count(i.second)) {
works = false;
}
}
if(works) {
cout << "(" << i.first << ", " << i.second << ")" << endl;
}
}
cout << endl;
}
}