#include<bits/stdc++.h> #define int long long usingnamespace std; intfun(int h, int x, int y){ if (h <= x) return1; returnceil ( (h - x) * 1.0 / (x - y) ) + 1; } voidsolve(){ int q; cin >> q; bool f = false; int l, r; while (q --) { int op, a, b, n; cin >> op >> a >> b; if (op == 1) { cin >> n; if (!f) { if (n == 1) { l = 1; r = a; } else { l = a * n - b * n - a + 2 * b + 1; r = a * n - b * n + b; } f = true; cout << 1 << " "; } else { int x, y; if (n == 1) { x = 1; y = a; } else { x = a * n - b * n - a + 2 * b + 1; y = a * n - b * n + b; } if (max (x, l) > min (y, r) ) cout << 0 << " "; else { l = max (x, l); r = min (y, r); cout << 1 << " "; } } } else { if (!f) cout << -1 << " "; else { if (fun (l, a, b) == fun (r, a, b) ) cout << fun (l, a, b) << " "; else cout << -1 << " "; } } } cout << "\n"; } signedmain(){ ios::sync_with_stdio(false); cin.tie(nullptr);
int t; cin >> t; while (t --) { solve(); } return0; }
using i64 = longlong; constexprint inf = 1e9 + 7; structnode { int u, w; booloperator>(const node& a) const { returnthis->w > a.w; } }; voidsolve(){ int n, m; cin >> n >> m;
vector<int> a(n + 1); for (int i = 1; i <= n; i++) { cin >> a[i]; }
vector<vector<int>> e(n + 1); for (int i = 1; i <= m; i++) { int u, v; cin >> u >> v; e[u].push_back(v); e[v].push_back(u); } vector<int> vis(n + 1);
auto fun = [&](int s) -> bool { priority_queue<node, vector<node>, greater<node>> q; //queue<int> Q; int cnt = 0; q.push({s, a[s]});
while (!q.empty()) { auto [u, w] = q.top(); q.pop(); if (vis[u] == s) continue; vis[u] = s;
if (cnt >= w) { cnt++; for (auto v : e[u]) if (vis[v] != s) { q.push({v, a[v]}); } } else { break; } } //cerr << "cnt : " << cnt << '\n'; return (cnt == n); };
for (int i = 1; i <= n; i++) { if (a[i] == 0 && !vis[i]) { if (fun(i)) { cout << "Yes\n"; return; } } } cout << "No\n"; } intmain(){ ios::sync_with_stdio(false); cin.tie(nullptr);