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
| #include <bits/stdc++.h> #define ouo ios_base::sync_with_stdio(false), cin.tie(0) #define ll long long #define db double using namespace std;
struct node { int type; int result; };
int p, q, r, m; vector<node> vc; vector<bool> visited; vector<int> ans; vector<vector<int>> g; vector<pair<int, int>> dp;
pair<int, int> dfs(int idx) { if (idx <= p) { visited[idx] = true; return dp[idx] = {vc[idx].result, 0}; }
if (idx > p + q && idx <= p + q + r) return dfs(g[idx][0]);
if (visited[idx]) return dp[idx];
visited[idx] = true; auto a = dfs(g[idx][0]);
if (vc[idx].type == 4) return dp[idx] = {!a.first, a.second + 1};
auto b = dfs(g[idx][1]);
if (vc[idx].type == 1) return dp[idx] = {(a.first && b.first), max(a.second, b.second) + 1}; if (vc[idx].type == 2) return dp[idx] = {(a.first || b.first), max(a.second, b.second) + 1}; if (vc[idx].type == 3) return dp[idx] = {(a.first != b.first), max(a.second, b.second) + 1}; return {vc[idx].result, 0}; }
int main() { ouo; cin >> p >> q >> r >> m;
vc.resize(p + q + r + 1); visited.assign(p + q + r + 1, false); g.assign(p + q + r + 1, {}); dp.resize(p + q + r + 1); for (int i = 1; i <= p + q; i++) { vc[i].result = 0; vc[i].type = -1; }
for (int i = 1; i <= p; i++) { cin >> vc[i].result; }
for (int i = 1; i <= q; i++) { cin >> vc[p + i].type; }
for (int i = 1; i <= m; i++) { int a, b; cin >> a >> b; g[b].push_back(a); }
int delay = -1; for (int i = p + q + 1; i <= p + q + r; i++) { auto f = dfs(i); ans.push_back(f.first); delay = max(delay, f.second); }
cout << delay << "\n"; for (auto i : ans) cout << i << " "; }
|