Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- const int N = 41;
- int n, p;
- pair<int, int> match[N];
- int cur[N], match_state[N];
- int want[N];
- bool dfs(int at) {
- if (at == p) {
- for (int i = 0; i < n; ++i)
- cur[i] = 0;
- for (int i = 0; i < p; ++i) {
- int u = match[i].first;
- int v = match[i].second;
- if (match_state[i] == 0)
- cur[u] += 3;
- else if (match_state[i] == 1)
- ++cur[u], ++cur[v];
- else
- cur[v] += 3;
- }
- bool ok = true;
- for (int i = 0; i < n; ++i)
- ok &= (cur[i] == want[i]);
- return ok;
- }
- bool ok = false;
- for (int i = 0; i < 3; ++i) {
- match_state[at] = i;
- ok |= dfs(at + 1);
- }
- return ok;
- }
- void solve() {
- scanf("%d", &n);
- for (int i = 0; i < n; ++i)
- scanf("%d", &want[i]);
- p = 0;
- for (int i = 0; i < n; ++i)
- for (int j = i + 1; j < n; ++j)
- match[p] = {i, j}, ++p;
- puts(dfs(0) ? "YES" : "NO");
- }
- int main() {
- int qq;
- scanf("%d", &qq);
- while (qq--)
- solve();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement