답안 #726812

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
726812 2023-04-19T11:49:15 Z dozer Jail (JOI22_jail) C++14
61 / 100
5000 ms 33692 KB
#include <bits/stdc++.h>
using namespace std;
#define fastio() cin.tie(0), ios_base::sync_with_stdio(0)
#define sp " "
#define endl "\n"
#define pb push_back
#define pii pair<int, int>
#define st first
#define nd second
#define N 200005
#define LOGN 18


vector<int> adj[N], adj2[N];
int tin[N], tout[N], s[N], t[N], par[LOGN][N];
int cntr, dep[N], deg[N];


void dfs(int node, int root, int d)
{
	tin[node] = cntr++;
	dep[node] = d;
	par[0][node] = root;
	for (auto i : adj[node])
		if (i != root) dfs(i, node, d + 1);
	tout[node] = cntr++;
}

bool ancestor(int a, int b)
{
	return (tin[a] <= tin[b] && tout[a] >= tout[b]);
}

int lca(int a, int b)
{
	for (int i = LOGN - 1; i >= 0; i--)
	{
		if ((1<<i) < dep[a] && !ancestor(par[i][a], b)) a = par[i][a];
	}
	if (!ancestor(a, b)) a = par[0][a];
	return a;
}

bool intersects(int x, int a, int b)
{
	int l = lca(a, b);
	if (x == l) return 1;
	return (ancestor(x, a) ^ ancestor(x, b));
}


int32_t main()
{
	fastio();


	int q;
	cin>>q;
	while(q--)
	{
		int n, m;
		cin>>n;
		for (int i = 1; i <= n; i++)
			adj[i].clear();
		for (int i = 1; i < n; i++)
		{
			int u, v;
			cin>>u>>v;
			adj[u].pb(v);
			adj[v].pb(u);
		}

		cntr = 0;
		dfs(1, 0, 0);
		for (int i = 1; i < LOGN; i++)
		{
			for (int j = 1; j <= n; j++)
				par[i][j] = par[i - 1][par[i - 1][j]];
		}
		vector<pii> v;
		cin>>m;
		for (int i = 1; i <= m; i++)
			adj2[i].clear(), deg[i] = 0;

		for (int i = 1; i <= m; i++)
			cin>>s[i]>>t[i];

		for (int i = 1; i <= m; i++)
		{
			for (int j = i + 1; j <= m; j++)
			{
				if (intersects(s[i], s[j], t[j]) || intersects(t[j], s[i], t[i])) adj2[i].pb(j), deg[j]++;
				if (intersects(t[i], s[j], t[j]) || intersects(s[j], s[i], t[i])) adj2[j].pb(i), deg[i]++;
			}
		}

		vector<int> done(m + 5, 0);

		queue<int> q;
		for (int i = 1; i <= m; i++)
			if (deg[i] == 0) q.push(i);

		while(!q.empty())
		{
			int top = q.front();
			q.pop();
			done[top] = 1;
			for (auto i : adj2[top])
			{
				deg[i]--;
				if (deg[i] == 0) q.push(i);
			}
		} 

		int flag = 1;
		for (int i = 1; i <= m; i++)
		{
			flag &= done[i];
		}

		if (flag) cout<<"Yes\n";
		else cout<<"No\n";

	}

	cerr<<"time taken : "<<(float)clock() / CLOCKS_PER_SEC<<" seconds\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9812 KB Output is correct
2 Correct 7 ms 9780 KB Output is correct
3 Correct 5 ms 9852 KB Output is correct
4 Correct 13 ms 10104 KB Output is correct
5 Correct 22 ms 10496 KB Output is correct
6 Correct 6 ms 9856 KB Output is correct
7 Correct 6 ms 9884 KB Output is correct
8 Correct 21 ms 9908 KB Output is correct
9 Correct 628 ms 13208 KB Output is correct
10 Correct 62 ms 32980 KB Output is correct
11 Correct 13 ms 10012 KB Output is correct
12 Correct 178 ms 10864 KB Output is correct
13 Execution timed out 5077 ms 33692 KB Time limit exceeded
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 9812 KB Output is correct
2 Correct 5 ms 9940 KB Output is correct
3 Correct 7 ms 9812 KB Output is correct
4 Correct 6 ms 9812 KB Output is correct
5 Correct 6 ms 9864 KB Output is correct
6 Correct 6 ms 9916 KB Output is correct
7 Correct 7 ms 9812 KB Output is correct
8 Correct 7 ms 9860 KB Output is correct
9 Correct 6 ms 9856 KB Output is correct
10 Correct 6 ms 9812 KB Output is correct
11 Correct 6 ms 9812 KB Output is correct
12 Correct 6 ms 9812 KB Output is correct
13 Correct 6 ms 9812 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 9812 KB Output is correct
2 Correct 5 ms 9940 KB Output is correct
3 Correct 7 ms 9812 KB Output is correct
4 Correct 6 ms 9812 KB Output is correct
5 Correct 6 ms 9864 KB Output is correct
6 Correct 6 ms 9916 KB Output is correct
7 Correct 7 ms 9812 KB Output is correct
8 Correct 7 ms 9860 KB Output is correct
9 Correct 6 ms 9856 KB Output is correct
10 Correct 6 ms 9812 KB Output is correct
11 Correct 6 ms 9812 KB Output is correct
12 Correct 6 ms 9812 KB Output is correct
13 Correct 6 ms 9812 KB Output is correct
14 Correct 6 ms 9848 KB Output is correct
15 Correct 5 ms 9812 KB Output is correct
16 Correct 6 ms 9812 KB Output is correct
17 Correct 7 ms 9812 KB Output is correct
18 Correct 7 ms 9860 KB Output is correct
19 Correct 6 ms 9848 KB Output is correct
20 Correct 7 ms 9812 KB Output is correct
21 Correct 6 ms 9872 KB Output is correct
22 Correct 7 ms 9864 KB Output is correct
23 Correct 6 ms 9848 KB Output is correct
24 Correct 6 ms 9780 KB Output is correct
25 Correct 6 ms 9856 KB Output is correct
26 Correct 6 ms 9852 KB Output is correct
27 Correct 6 ms 9812 KB Output is correct
28 Correct 6 ms 9844 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 9812 KB Output is correct
2 Correct 5 ms 9940 KB Output is correct
3 Correct 7 ms 9812 KB Output is correct
4 Correct 6 ms 9812 KB Output is correct
5 Correct 6 ms 9864 KB Output is correct
6 Correct 6 ms 9916 KB Output is correct
7 Correct 7 ms 9812 KB Output is correct
8 Correct 7 ms 9860 KB Output is correct
9 Correct 6 ms 9856 KB Output is correct
10 Correct 6 ms 9812 KB Output is correct
11 Correct 6 ms 9812 KB Output is correct
12 Correct 6 ms 9812 KB Output is correct
13 Correct 6 ms 9812 KB Output is correct
14 Correct 6 ms 9848 KB Output is correct
15 Correct 5 ms 9812 KB Output is correct
16 Correct 6 ms 9812 KB Output is correct
17 Correct 7 ms 9812 KB Output is correct
18 Correct 7 ms 9860 KB Output is correct
19 Correct 6 ms 9848 KB Output is correct
20 Correct 7 ms 9812 KB Output is correct
21 Correct 6 ms 9872 KB Output is correct
22 Correct 7 ms 9864 KB Output is correct
23 Correct 6 ms 9848 KB Output is correct
24 Correct 6 ms 9780 KB Output is correct
25 Correct 6 ms 9856 KB Output is correct
26 Correct 6 ms 9852 KB Output is correct
27 Correct 6 ms 9812 KB Output is correct
28 Correct 6 ms 9844 KB Output is correct
29 Correct 22 ms 9940 KB Output is correct
30 Correct 13 ms 9896 KB Output is correct
31 Correct 15 ms 9956 KB Output is correct
32 Correct 10 ms 9812 KB Output is correct
33 Correct 7 ms 9860 KB Output is correct
34 Correct 14 ms 9820 KB Output is correct
35 Correct 17 ms 9940 KB Output is correct
36 Correct 17 ms 9940 KB Output is correct
37 Correct 13 ms 9856 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 9812 KB Output is correct
2 Correct 5 ms 9940 KB Output is correct
3 Correct 7 ms 9812 KB Output is correct
4 Correct 6 ms 9812 KB Output is correct
5 Correct 6 ms 9864 KB Output is correct
6 Correct 6 ms 9916 KB Output is correct
7 Correct 7 ms 9812 KB Output is correct
8 Correct 7 ms 9860 KB Output is correct
9 Correct 6 ms 9856 KB Output is correct
10 Correct 6 ms 9812 KB Output is correct
11 Correct 6 ms 9812 KB Output is correct
12 Correct 6 ms 9812 KB Output is correct
13 Correct 6 ms 9812 KB Output is correct
14 Correct 6 ms 9848 KB Output is correct
15 Correct 5 ms 9812 KB Output is correct
16 Correct 6 ms 9812 KB Output is correct
17 Correct 7 ms 9812 KB Output is correct
18 Correct 7 ms 9860 KB Output is correct
19 Correct 6 ms 9848 KB Output is correct
20 Correct 7 ms 9812 KB Output is correct
21 Correct 6 ms 9872 KB Output is correct
22 Correct 7 ms 9864 KB Output is correct
23 Correct 6 ms 9848 KB Output is correct
24 Correct 6 ms 9780 KB Output is correct
25 Correct 6 ms 9856 KB Output is correct
26 Correct 6 ms 9852 KB Output is correct
27 Correct 6 ms 9812 KB Output is correct
28 Correct 6 ms 9844 KB Output is correct
29 Correct 22 ms 9940 KB Output is correct
30 Correct 13 ms 9896 KB Output is correct
31 Correct 15 ms 9956 KB Output is correct
32 Correct 10 ms 9812 KB Output is correct
33 Correct 7 ms 9860 KB Output is correct
34 Correct 14 ms 9820 KB Output is correct
35 Correct 17 ms 9940 KB Output is correct
36 Correct 17 ms 9940 KB Output is correct
37 Correct 13 ms 9856 KB Output is correct
38 Correct 643 ms 13176 KB Output is correct
39 Correct 64 ms 32972 KB Output is correct
40 Correct 577 ms 12900 KB Output is correct
41 Correct 373 ms 11680 KB Output is correct
42 Correct 342 ms 13012 KB Output is correct
43 Correct 34 ms 11724 KB Output is correct
44 Correct 211 ms 10488 KB Output is correct
45 Correct 78 ms 24908 KB Output is correct
46 Correct 81 ms 24908 KB Output is correct
47 Correct 138 ms 28616 KB Output is correct
48 Correct 143 ms 28628 KB Output is correct
49 Correct 109 ms 24992 KB Output is correct
50 Correct 109 ms 24960 KB Output is correct
51 Correct 60 ms 26040 KB Output is correct
52 Correct 60 ms 26140 KB Output is correct
53 Correct 225 ms 11116 KB Output is correct
54 Correct 86 ms 24852 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9844 KB Output is correct
2 Correct 6 ms 9760 KB Output is correct
3 Correct 5 ms 9844 KB Output is correct
4 Correct 6 ms 9772 KB Output is correct
5 Correct 13 ms 9960 KB Output is correct
6 Correct 6 ms 9872 KB Output is correct
7 Correct 6 ms 9812 KB Output is correct
8 Correct 6 ms 9844 KB Output is correct
9 Correct 6 ms 9844 KB Output is correct
10 Correct 5 ms 9852 KB Output is correct
11 Correct 6 ms 9812 KB Output is correct
12 Correct 15 ms 9940 KB Output is correct
13 Correct 145 ms 10432 KB Output is correct
14 Correct 77 ms 10608 KB Output is correct
15 Correct 93 ms 10488 KB Output is correct
16 Execution timed out 5056 ms 25508 KB Time limit exceeded
17 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9812 KB Output is correct
2 Correct 7 ms 9780 KB Output is correct
3 Correct 5 ms 9852 KB Output is correct
4 Correct 13 ms 10104 KB Output is correct
5 Correct 22 ms 10496 KB Output is correct
6 Correct 6 ms 9856 KB Output is correct
7 Correct 6 ms 9884 KB Output is correct
8 Correct 21 ms 9908 KB Output is correct
9 Correct 628 ms 13208 KB Output is correct
10 Correct 62 ms 32980 KB Output is correct
11 Correct 13 ms 10012 KB Output is correct
12 Correct 178 ms 10864 KB Output is correct
13 Execution timed out 5077 ms 33692 KB Time limit exceeded
14 Halted 0 ms 0 KB -