Submission #660198

# Submission time Handle Problem Language Result Execution time Memory
660198 2022-11-21T05:55:30 Z Sohsoh84 Jail (JOI22_jail) C++17
0 / 100
12 ms 23764 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;

#define all(x)			(x).begin(),(x).end()
#define X			first
#define Y			second
#define sep			' '
#define endl			'\n'
#define debug(x)		cerr << #x << ": " <<  x << endl;

const ll MAXN = 1e6 + 10;
const ll LOG = 20;

int n, m, t, tin[MAXN], tout[MAXN], S[MAXN], T[MAXN], Par[MAXN][LOG];
vector<int> adj[MAXN];

void dfs(int v, int p) {
	tin[v] = ++t;
	Par[v][0] = p;

	for (int u : adj[v])
		if (u != p)
			dfs(u, v);

	tout[v] = t;
}

inline bool par(int u, int v) {
	return tin[u] <= tin[v] && tout[u] >= tout[v];
}

inline int LCA(int u, int v) {
	if (par(u, v)) return u;
	if (par(v, u)) return v;

	for (int i = LOG - 1; i >= 0; i--)
		if (Par[u][i] != 0 && !par(Par[u][i], v))
			u = Par[u][i];

	return Par[u][0];
}

inline bool in_path(int v, int a, int b) {
	int lca = LCA(a, b);
	if (!par(lca, v)) return false;
	return par(v, a) || par(v, b);
}

inline int solve() {
	t = 0;
	for (int i = 0; i < n + 10; i++) adj[i].clear();

	cin >> n;
	for (int i = 1; i < n; i++) {
		int u, v;
		cin >> u >> v;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	
	dfs(1, 0);
	for (int i = 1; i < LOG; i++)
		for (int v = 1; v <= n; v++)
			Par[v][i] = Par[Par[v][i - 1]][i - 1];

	cin >> m;
	bool flag = true;
	for (int i = 1; i <= m; i++)
		cin >> S[i] >> T[i];

	vector<int> vec;
	for (int i = 1; i <= m; i++)
		vec.push_back(i);

	do {
		bool flag = true;
		for (int i = 0; i < m; i++) {
			for (int j = 0; j < i; j++)
				flag &= (!in_path(T[vec[j]], S[vec[i]], T[vec[i]]));

			for (int j = i + 1; j < n; j++)
				flag &= (!in_path(S[vec[j]], S[vec[i]], T[vec[i]]));
		}

		if (flag) return cout << "YES" << endl, 0;
	} while (next_permutation(all(vec)));

	cout << "NO" << endl;
	return 0;
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int q;
	cin >> q;
	while (q--) solve();
	return 0;
}

Compilation message

jail.cpp: In function 'int solve()':
jail.cpp:71:7: warning: unused variable 'flag' [-Wunused-variable]
   71 |  bool flag = true;
      |       ^~~~
# Verdict Execution time Memory Grader output
1 Incorrect 11 ms 23712 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 12 ms 23752 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 12 ms 23752 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 12 ms 23752 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 12 ms 23752 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 12 ms 23764 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 11 ms 23712 KB Output isn't correct
2 Halted 0 ms 0 KB -