-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay11.cpp
More file actions
75 lines (61 loc) · 1.6 KB
/
Day11.cpp
File metadata and controls
75 lines (61 loc) · 1.6 KB
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
#include <bits/stdc++.h>
#define int long long
#define allr(x) (x).rbegin(), (x).rend()
#define all(x) (x).begin(), (x).end()
#define ld long double
#define INF (int)(1e18)
#define MOD 1000000007
using namespace std;
int cnt_pathpart1(string src, string dest, map<string, vector<string> > &adj) {
if (src == dest) return 1;
int ans = 0;
for (auto v: adj[src]) {
ans += cnt_pathpart1(v, dest, adj);
}
return ans;
}
map<pair<string, pair<bool, bool> >,int> memo;
int cnt_pathpart2(string src, bool f1, bool f2, map<string, vector<string> > &adj) {
if (src == "fft")f1 = true;
if (src == "dac")f2 = true;
if (src == "out") {
if (f1 & f2)return 1;
return 0;
}
if (memo.count({src, {f1, f2}}))
return memo[{src, {f1, f2}}];
int ans = 0;
if (adj.count(src)) {
for (auto v: adj[src]) {
ans += cnt_pathpart2(v, f1, f2, adj);
}
}
return memo[{src, {f1, f2}}] = ans;
}
void solve() {
string s;
map<string, vector<string> > adj;
while (getline(cin, s) && s != "?") {
stringstream ss(s);
string s1, s2;
ss >> s1;
s1.pop_back();
while (ss >> s2) {
adj[s1].push_back(s2);
}
}
cout << cnt_pathpart1("you", "out", adj) << "\n";
cout << cnt_pathpart2("svr", false, false, adj) << "\n";
}
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
// freopen("promote.in","r",stdin);
// freopen("promote.out","w",stdout);
int tests = 1;
// cin >> tests;
while (tests--) {
solve();
}
}