Submission #765161

# Submission time Handle Problem Language Result Execution time Memory
765161 2023-06-24T08:56:42 Z ymm Jail (JOI22_jail) C++17
72 / 100
4233 ms 1048576 KB
#include <bits/stdc++.h>
#define Loop(x,l,r) for (ll x = (l); x < (ll)(r); ++x)
#define LoopR(x,l,r) for (ll x = (r)-1; x >= (ll)(l); --x)
typedef long long ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll , ll > pll;
using namespace std;

const int N = 200'010;
vector<int> A[N];
vector<int> A0[N];
int st[N], ft[N];
int par[N];
int n, m;

void dfs(int v, int p, int &t)
{
	st[v] = t++;
	par[v] = p;
	for (int u : A0[v])
		if (u != p)
			dfs(u, v, t);
	ft[v] = t;
}

void add_edge(int i, int j)
{
	if (i == j)
		return;
	A[i].push_back(j);
}

vector<int> path(int i, int j)
{
	vector<int> ans;
	while (!(st[i] <= st[j] && st[j] < ft[i])) {
		ans.push_back(i);
		i = par[i];
	}
	ans.push_back(i);
	while (j != i) {
		ans.push_back(j);
		j = par[j];
	}
	return ans;
}

bool vis[N], anc[N];
bool dfs_cycle(int v)
{
	anc[v] = vis[v] = 1;
	for (int u : A[v]) {
		if (anc[u])
			return 1;
		if (vis[u])
			continue;
		if (dfs_cycle(u))
			return 1;
	}
	anc[v] = 0;
	return 0;
}

bool has_cycle()
{
	Loop (i,0,m)
		if (!vis[i] && dfs_cycle(i))
			return 1;
	return 0;
}

int s[N], t[N];
int sp[N], tp[N];

void traverse(int i)
{
	for (int u : path(s[i], t[i])) {
		if (sp[u] != -1)
			add_edge(sp[u], i);
		if (tp[u] != -1)
			add_edge(i, tp[u]);
	}
}

void init()
{
	cin >> n;
	memset(sp, -1, n*sizeof(*sp));
	memset(tp, -1, n*sizeof(*tp));
	memset(vis, 0, n*sizeof(*vis));
	memset(anc, 0, n*sizeof(*anc));
	Loop (i,0,n)
		A0[i].clear();
	Loop (i,1,n) {
		int v, u;
		cin >> v >> u;
		--v; --u;
		A0[v].push_back(u);
		A0[u].push_back(v);
	}
	cin >> m;
	Loop (i,0,m)
		A[i].clear();
	Loop (i,0,m) {
		cin >> s[i] >> t[i];
		--s[i]; --t[i];
		sp[s[i]] = i;
		tp[t[i]] = i;
	}
}

void solve()
{
	init();
	int dard = 0;
	dfs(0, -1, dard);
	Loop (i,0,m)
		traverse(i);
	cout << (has_cycle()? "No": "Yes") << '\n';
}

int main()
{
	cin.tie(0) -> sync_with_stdio(false);
	int q;
	cin >> q;
	while (q--)
		solve();
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 5 ms 9684 KB Output is correct
3 Correct 6 ms 9684 KB Output is correct
4 Correct 13 ms 9772 KB Output is correct
5 Correct 17 ms 9684 KB Output is correct
6 Correct 5 ms 9684 KB Output is correct
7 Correct 7 ms 9684 KB Output is correct
8 Correct 6 ms 9792 KB Output is correct
9 Correct 91 ms 12396 KB Output is correct
10 Correct 424 ms 27396 KB Output is correct
11 Correct 8 ms 9876 KB Output is correct
12 Correct 32 ms 10828 KB Output is correct
13 Correct 150 ms 55624 KB Output is correct
14 Correct 140 ms 70132 KB Output is correct
15 Runtime error 4233 ms 1048576 KB Execution killed with signal 9
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9704 KB Output is correct
2 Correct 5 ms 9724 KB Output is correct
3 Correct 6 ms 9812 KB Output is correct
4 Correct 6 ms 9736 KB Output is correct
5 Correct 8 ms 9712 KB Output is correct
6 Correct 5 ms 9764 KB Output is correct
7 Correct 8 ms 9816 KB Output is correct
8 Correct 8 ms 9740 KB Output is correct
9 Correct 7 ms 9688 KB Output is correct
10 Correct 6 ms 9812 KB Output is correct
11 Correct 6 ms 9684 KB Output is correct
12 Correct 6 ms 9736 KB Output is correct
13 Correct 5 ms 9664 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9704 KB Output is correct
2 Correct 5 ms 9724 KB Output is correct
3 Correct 6 ms 9812 KB Output is correct
4 Correct 6 ms 9736 KB Output is correct
5 Correct 8 ms 9712 KB Output is correct
6 Correct 5 ms 9764 KB Output is correct
7 Correct 8 ms 9816 KB Output is correct
8 Correct 8 ms 9740 KB Output is correct
9 Correct 7 ms 9688 KB Output is correct
10 Correct 6 ms 9812 KB Output is correct
11 Correct 6 ms 9684 KB Output is correct
12 Correct 6 ms 9736 KB Output is correct
13 Correct 5 ms 9664 KB Output is correct
14 Correct 6 ms 9724 KB Output is correct
15 Correct 5 ms 9684 KB Output is correct
16 Correct 5 ms 9812 KB Output is correct
17 Correct 6 ms 9684 KB Output is correct
18 Correct 5 ms 9736 KB Output is correct
19 Correct 5 ms 9756 KB Output is correct
20 Correct 6 ms 9804 KB Output is correct
21 Correct 7 ms 9732 KB Output is correct
22 Correct 5 ms 9740 KB Output is correct
23 Correct 5 ms 9684 KB Output is correct
24 Correct 5 ms 9728 KB Output is correct
25 Correct 5 ms 9732 KB Output is correct
26 Correct 5 ms 9684 KB Output is correct
27 Correct 5 ms 9736 KB Output is correct
28 Correct 4 ms 9684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9704 KB Output is correct
2 Correct 5 ms 9724 KB Output is correct
3 Correct 6 ms 9812 KB Output is correct
4 Correct 6 ms 9736 KB Output is correct
5 Correct 8 ms 9712 KB Output is correct
6 Correct 5 ms 9764 KB Output is correct
7 Correct 8 ms 9816 KB Output is correct
8 Correct 8 ms 9740 KB Output is correct
9 Correct 7 ms 9688 KB Output is correct
10 Correct 6 ms 9812 KB Output is correct
11 Correct 6 ms 9684 KB Output is correct
12 Correct 6 ms 9736 KB Output is correct
13 Correct 5 ms 9664 KB Output is correct
14 Correct 6 ms 9724 KB Output is correct
15 Correct 5 ms 9684 KB Output is correct
16 Correct 5 ms 9812 KB Output is correct
17 Correct 6 ms 9684 KB Output is correct
18 Correct 5 ms 9736 KB Output is correct
19 Correct 5 ms 9756 KB Output is correct
20 Correct 6 ms 9804 KB Output is correct
21 Correct 7 ms 9732 KB Output is correct
22 Correct 5 ms 9740 KB Output is correct
23 Correct 5 ms 9684 KB Output is correct
24 Correct 5 ms 9728 KB Output is correct
25 Correct 5 ms 9732 KB Output is correct
26 Correct 5 ms 9684 KB Output is correct
27 Correct 5 ms 9736 KB Output is correct
28 Correct 4 ms 9684 KB Output is correct
29 Correct 7 ms 9812 KB Output is correct
30 Correct 7 ms 9796 KB Output is correct
31 Correct 9 ms 9884 KB Output is correct
32 Correct 8 ms 9736 KB Output is correct
33 Correct 6 ms 9812 KB Output is correct
34 Correct 7 ms 9736 KB Output is correct
35 Correct 7 ms 9864 KB Output is correct
36 Correct 5 ms 9812 KB Output is correct
37 Correct 6 ms 9736 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9704 KB Output is correct
2 Correct 5 ms 9724 KB Output is correct
3 Correct 6 ms 9812 KB Output is correct
4 Correct 6 ms 9736 KB Output is correct
5 Correct 8 ms 9712 KB Output is correct
6 Correct 5 ms 9764 KB Output is correct
7 Correct 8 ms 9816 KB Output is correct
8 Correct 8 ms 9740 KB Output is correct
9 Correct 7 ms 9688 KB Output is correct
10 Correct 6 ms 9812 KB Output is correct
11 Correct 6 ms 9684 KB Output is correct
12 Correct 6 ms 9736 KB Output is correct
13 Correct 5 ms 9664 KB Output is correct
14 Correct 6 ms 9724 KB Output is correct
15 Correct 5 ms 9684 KB Output is correct
16 Correct 5 ms 9812 KB Output is correct
17 Correct 6 ms 9684 KB Output is correct
18 Correct 5 ms 9736 KB Output is correct
19 Correct 5 ms 9756 KB Output is correct
20 Correct 6 ms 9804 KB Output is correct
21 Correct 7 ms 9732 KB Output is correct
22 Correct 5 ms 9740 KB Output is correct
23 Correct 5 ms 9684 KB Output is correct
24 Correct 5 ms 9728 KB Output is correct
25 Correct 5 ms 9732 KB Output is correct
26 Correct 5 ms 9684 KB Output is correct
27 Correct 5 ms 9736 KB Output is correct
28 Correct 4 ms 9684 KB Output is correct
29 Correct 7 ms 9812 KB Output is correct
30 Correct 7 ms 9796 KB Output is correct
31 Correct 9 ms 9884 KB Output is correct
32 Correct 8 ms 9736 KB Output is correct
33 Correct 6 ms 9812 KB Output is correct
34 Correct 7 ms 9736 KB Output is correct
35 Correct 7 ms 9864 KB Output is correct
36 Correct 5 ms 9812 KB Output is correct
37 Correct 6 ms 9736 KB Output is correct
38 Correct 99 ms 13704 KB Output is correct
39 Correct 464 ms 27488 KB Output is correct
40 Correct 49 ms 12564 KB Output is correct
41 Correct 24 ms 11260 KB Output is correct
42 Correct 42 ms 12660 KB Output is correct
43 Correct 20 ms 11372 KB Output is correct
44 Correct 12 ms 10164 KB Output is correct
45 Correct 36 ms 17528 KB Output is correct
46 Correct 54 ms 17532 KB Output is correct
47 Correct 100 ms 21744 KB Output is correct
48 Correct 93 ms 21744 KB Output is correct
49 Correct 41 ms 17692 KB Output is correct
50 Correct 46 ms 17712 KB Output is correct
51 Correct 39 ms 18760 KB Output is correct
52 Correct 48 ms 18760 KB Output is correct
53 Correct 12 ms 10560 KB Output is correct
54 Correct 60 ms 17480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 9684 KB Output is correct
2 Correct 5 ms 9684 KB Output is correct
3 Correct 5 ms 9684 KB Output is correct
4 Correct 6 ms 9764 KB Output is correct
5 Correct 8 ms 9868 KB Output is correct
6 Correct 4 ms 9684 KB Output is correct
7 Correct 6 ms 9684 KB Output is correct
8 Correct 6 ms 9720 KB Output is correct
9 Correct 7 ms 9764 KB Output is correct
10 Correct 5 ms 9684 KB Output is correct
11 Correct 5 ms 9712 KB Output is correct
12 Correct 5 ms 9812 KB Output is correct
13 Correct 18 ms 10244 KB Output is correct
14 Correct 24 ms 10580 KB Output is correct
15 Correct 21 ms 10452 KB Output is correct
16 Correct 39 ms 18052 KB Output is correct
17 Correct 93 ms 24108 KB Output is correct
18 Correct 228 ms 44056 KB Output is correct
19 Correct 47 ms 18124 KB Output is correct
20 Correct 44 ms 18268 KB Output is correct
21 Correct 43 ms 18176 KB Output is correct
22 Correct 83 ms 24564 KB Output is correct
23 Correct 73 ms 25092 KB Output is correct
24 Correct 77 ms 24616 KB Output is correct
25 Correct 79 ms 24824 KB Output is correct
26 Correct 73 ms 24640 KB Output is correct
27 Correct 81 ms 25424 KB Output is correct
28 Correct 84 ms 29692 KB Output is correct
29 Correct 89 ms 26628 KB Output is correct
30 Correct 61 ms 23032 KB Output is correct
31 Correct 56 ms 23500 KB Output is correct
32 Correct 58 ms 22176 KB Output is correct
33 Correct 61 ms 23560 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 5 ms 9684 KB Output is correct
3 Correct 6 ms 9684 KB Output is correct
4 Correct 13 ms 9772 KB Output is correct
5 Correct 17 ms 9684 KB Output is correct
6 Correct 5 ms 9684 KB Output is correct
7 Correct 7 ms 9684 KB Output is correct
8 Correct 6 ms 9792 KB Output is correct
9 Correct 91 ms 12396 KB Output is correct
10 Correct 424 ms 27396 KB Output is correct
11 Correct 8 ms 9876 KB Output is correct
12 Correct 32 ms 10828 KB Output is correct
13 Correct 150 ms 55624 KB Output is correct
14 Correct 140 ms 70132 KB Output is correct
15 Runtime error 4233 ms 1048576 KB Execution killed with signal 9
16 Halted 0 ms 0 KB -