Submission #544521

# Submission time Handle Problem Language Result Execution time Memory
544521 2022-04-02T07:50:25 Z blue Jail (JOI22_jail) C++17
100 / 100
1090 ms 151576 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;

using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vpii = vector<pii>;

const int lg = 17;
const int INF = 1'000'000;

int N;
int M;
vi* edge;

int ct;
vi ord;
vi ordind;

vvi anc;
vi depth;
vi subtree;

void dfs(int u)
{
	ct++;
	ord[ct] = u;
	ordind[u] = ct;

	for(int v : edge[u])
	{
		if(v == anc[u][0]) continue;

		anc[v][0] = u;
		depth[v] = 1 + depth[u];

		dfs(v);

		subtree[u] += subtree[v];
	}
}

int ancestor(int u, int k)
{
	for(int e = 0; e <= lg; e++)
		if(k & (1 << e))
			u = anc[u][e];

	return u;
}

int lca(int u, int v)
{
	if(depth[u] > depth[v]) swap(u, v);

	v = ancestor(v, depth[v] - depth[u]);

	if(u == v) return u;

	for(int e = lg; e >= 0; e--)
	{
		if(anc[u][e] == anc[v][e]) continue;
		u = anc[u][e];
		v = anc[v][e];
	}

	return anc[u][0];
}




struct segtree1
{
	vector< set<pii> > markers;
	vpii bestmark;

	segtree1()
	{
		markers = vector<set<pii>>(1+4*N);
		bestmark = vector<pii>(1+4*N, {INF, -1});
	}

	void insert(int I, pii V, int i = 1, int l = 1, int r = N)
	{
		if(I < l || r < I) return;
		else if(l == r)
		{
			markers[i].insert(V);
			bestmark[i] = min(bestmark[i], V);
		}
		else
		{
			insert(I, V, 2*i, l, (l+r)/2);
			insert(I, V, 2*i+1, (l+r)/2+1, r);
			bestmark[i] = min({bestmark[i], bestmark[2*i], bestmark[2*i+1]});
		}
	}

	void erase(int I, pii V, int i = 1, int l = 1, int r = N)
	{
		if(I < l || r < I) return;
		else if(l == r)
		{
			markers[i].erase(V);
			if(markers[i].empty()) bestmark[i] = {INF, -1};
			else bestmark[i] = *markers[i].begin();

		}
		else
		{
			erase(I, V, 2*i, l, (l+r)/2);
			erase(I, V, 2*i+1, (l+r)/2+1, r);
			bestmark[i] = min(bestmark[2*i], bestmark[2*i+1]);
		}
	}

	pii rangemin(int L, int R, int i = 1, int l = 1, int r = N)
	{
		if(R < l || r < L) return {INF, -1};
		else if(L <= l && r <= R) return bestmark[i];
		else return min(rangemin(L, R, 2*i, l, (l+r)/2), rangemin(L, R, 2*i+1, (l+r)/2+1, r));
	}
};



struct segtree2
{
	vector<set<pii>> markers;

	segtree2()
	{
		markers = vector<set<pii>>(1+4*N);
	}

	void insert(int L, int R, pii V, int i = 1, int l = 1, int r = N)
	{
		if(R < l || r < L) return;
		else if(L <= l && r <= R)
		{
			markers[i].insert(V);
		}
		else
		{
			insert(L, R, V, 2*i, l, (l+r)/2);
			insert(L, R, V, 2*i+1, (l+r)/2+1, r);
		}
	}

	void erase(int L, int R, pii V, int i = 1, int l = 1, int r = N)
	{
		if(R < l || r < L) return;
		else if(L <= l && r <= R)
		{
			markers[i].erase(V);
		}
		else
		{
			erase(L, R, V, 2*i, l, (l+r)/2);
			erase(L, R, V, 2*i+1, (l+r)/2+1, r);
		}
	}

	pii pointmax(int I, int i = 1, int l = 1, int r = N)
	{
		pii curr = markers[i].empty() ? pii{-INF, -1} : *markers[i].rbegin();
		if(l == r) return curr;
		else if(I <= (l+r)/2) return max(curr, pointmax(I, 2*i, l, (l+r)/2));
		else return max(curr, pointmax(I, 2*i+1, (l+r)/2+1, r));
	}
};








vi S, T;
vi A;





segtree1 ST1;
segtree2 ST2;




bool cyclic;


void insert_prisoner(int j)
{
	// cerr << "insert prisoner " << j << '\n';
	ST1.insert(ordind[S[j]], {depth[A[j]], j});	
	ST1.insert(ordind[T[j]], {depth[A[j]], j});

	ST2.insert(ordind[T[j]], ordind[T[j]] + subtree[T[j]] - 1, {depth[T[j]], j});
}

void erase_prisoner(int j)
{
	// cerr << "erase prisoner " << j << '\n';
	ST1.erase(ordind[S[j]], {depth[A[j]], j});	
	ST1.erase(ordind[T[j]], {depth[A[j]], j});

	ST2.erase(ordind[T[j]], ordind[T[j]] + subtree[T[j]] - 1, {depth[T[j]], j});
}

vi dfsenter;
vi dfsexit;



void prisonerdfs(int u)
{
	dfsenter[u] = 1;

	bool usedfirst = 0;
	bool usedS = 0;


	erase_prisoner(u);

	while(1)
	{
		pii vp;
		if(!usedfirst)
		{
			// cerr << "type = 1\n";
			vp = ST1.rangemin(ordind[S[u]], ordind[S[u]] + subtree[S[u]] - 1);
			if(vp.first > depth[S[u]])
			{
				usedfirst = 1;
				// cerr << "continuing\n";
				continue;
			}
		}
		else if(!usedS)
		{
			// cerr << "type = 2\n";
			vp = ST2.pointmax(ordind[S[u]]);
			if(vp.first < depth[A[u]])
			{
				usedS = 1;
				// cerr << "continuing\n";
				continue;
			} 
		}
		else
		{
			// cerr << "type = 3\n";
			vp = ST2.pointmax(ordind[T[u]]);
			if(vp.first < depth[A[u]])
			{
				// cerr << "breaking\n";
				break;
			}
		}

		int v = vp.second;

		// cerr << "edge = " << u << " -> " << v << '\n';

		if(dfsenter[v] && !dfsexit[v])
		{
			cyclic = 1;
			return;
		}
		else if(dfsenter[v] && dfsexit[v])
		{
			;
		}
		else
		{	
			insert_prisoner(u);
			prisonerdfs(v);
			erase_prisoner(u);
			if(cyclic) return;
		}
	}




	erase_prisoner(u);
	dfsexit[u] = 1;
}



void run()
{
	cin >> N;
	edge = new vi[1+N];

	for(int e = 1; e <= N-1; e++)
	{
		int a, b;
		cin >> a >> b;
		edge[a].push_back(b);
		edge[b].push_back(a);
	}

	ct = 0;
	ord = vi(1+N, 0);
	ordind = vi(1+N, 0);

	depth = vi(1+N, 0);
	anc = vvi(1+N, vi(1+lg, 0));
	subtree = vi(1+N, 1);

	anc[1][0] = 0;
	depth[1] = 1;

	dfs(1);

	for(int e = 1; e <= lg; e++)
	{
		for(int i = 0; i <= N; i++)
		{
			anc[i][e] = anc[ anc[i][e-1] ][e-1];
		}
	}

	ST1 = segtree1();
	ST2 = segtree2();

	cyclic = 0;

	cin >> M;

	S = T = vi(1+M);
	A = vi(1+M);


	for(int j = 1; j <= M; j++)
	{
		cin >> S[j] >> T[j];

		A[j] = lca(S[j], T[j]);

		insert_prisoner(j);
	}

	dfsenter = dfsexit = vi(1+M, 0);

	for(int i = 1; i <= M; i++)
	{
		if(dfsenter[i]) continue;
		prisonerdfs(i);
		if(cyclic) break;
	}

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

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int T;
	cin >> T;

	for(int t = 1; t <= T; t++)
	{
		run();
	}
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 24 ms 3460 KB Output is correct
5 Correct 50 ms 7052 KB Output is correct
6 Correct 2 ms 724 KB Output is correct
7 Correct 3 ms 724 KB Output is correct
8 Correct 6 ms 848 KB Output is correct
9 Correct 77 ms 12300 KB Output is correct
10 Correct 83 ms 77412 KB Output is correct
11 Correct 18 ms 1524 KB Output is correct
12 Correct 114 ms 7180 KB Output is correct
13 Correct 325 ms 103224 KB Output is correct
14 Correct 238 ms 103120 KB Output is correct
15 Correct 428 ms 103124 KB Output is correct
16 Correct 1027 ms 139416 KB Output is correct
17 Correct 326 ms 106984 KB Output is correct
18 Correct 580 ms 139428 KB Output is correct
19 Correct 323 ms 107788 KB Output is correct
20 Correct 296 ms 107924 KB Output is correct
21 Correct 290 ms 108396 KB Output is correct
22 Correct 244 ms 108276 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 3 ms 724 KB Output is correct
4 Correct 3 ms 724 KB Output is correct
5 Correct 4 ms 724 KB Output is correct
6 Correct 3 ms 724 KB Output is correct
7 Correct 3 ms 724 KB Output is correct
8 Correct 4 ms 792 KB Output is correct
9 Correct 2 ms 724 KB Output is correct
10 Correct 3 ms 724 KB Output is correct
11 Correct 2 ms 724 KB Output is correct
12 Correct 2 ms 596 KB Output is correct
13 Correct 1 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 3 ms 724 KB Output is correct
4 Correct 3 ms 724 KB Output is correct
5 Correct 4 ms 724 KB Output is correct
6 Correct 3 ms 724 KB Output is correct
7 Correct 3 ms 724 KB Output is correct
8 Correct 4 ms 792 KB Output is correct
9 Correct 2 ms 724 KB Output is correct
10 Correct 3 ms 724 KB Output is correct
11 Correct 2 ms 724 KB Output is correct
12 Correct 2 ms 596 KB Output is correct
13 Correct 1 ms 596 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 3 ms 724 KB Output is correct
17 Correct 3 ms 708 KB Output is correct
18 Correct 3 ms 724 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 3 ms 724 KB Output is correct
21 Correct 3 ms 724 KB Output is correct
22 Correct 3 ms 724 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 3 ms 724 KB Output is correct
26 Correct 1 ms 468 KB Output is correct
27 Correct 3 ms 724 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 3 ms 724 KB Output is correct
4 Correct 3 ms 724 KB Output is correct
5 Correct 4 ms 724 KB Output is correct
6 Correct 3 ms 724 KB Output is correct
7 Correct 3 ms 724 KB Output is correct
8 Correct 4 ms 792 KB Output is correct
9 Correct 2 ms 724 KB Output is correct
10 Correct 3 ms 724 KB Output is correct
11 Correct 2 ms 724 KB Output is correct
12 Correct 2 ms 596 KB Output is correct
13 Correct 1 ms 596 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 3 ms 724 KB Output is correct
17 Correct 3 ms 708 KB Output is correct
18 Correct 3 ms 724 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 3 ms 724 KB Output is correct
21 Correct 3 ms 724 KB Output is correct
22 Correct 3 ms 724 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 3 ms 724 KB Output is correct
26 Correct 1 ms 468 KB Output is correct
27 Correct 3 ms 724 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 6 ms 840 KB Output is correct
30 Correct 5 ms 800 KB Output is correct
31 Correct 4 ms 724 KB Output is correct
32 Correct 4 ms 724 KB Output is correct
33 Correct 3 ms 768 KB Output is correct
34 Correct 6 ms 608 KB Output is correct
35 Correct 6 ms 724 KB Output is correct
36 Correct 6 ms 608 KB Output is correct
37 Correct 5 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 3 ms 724 KB Output is correct
4 Correct 3 ms 724 KB Output is correct
5 Correct 4 ms 724 KB Output is correct
6 Correct 3 ms 724 KB Output is correct
7 Correct 3 ms 724 KB Output is correct
8 Correct 4 ms 792 KB Output is correct
9 Correct 2 ms 724 KB Output is correct
10 Correct 3 ms 724 KB Output is correct
11 Correct 2 ms 724 KB Output is correct
12 Correct 2 ms 596 KB Output is correct
13 Correct 1 ms 596 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 3 ms 724 KB Output is correct
17 Correct 3 ms 708 KB Output is correct
18 Correct 3 ms 724 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 3 ms 724 KB Output is correct
21 Correct 3 ms 724 KB Output is correct
22 Correct 3 ms 724 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 3 ms 724 KB Output is correct
26 Correct 1 ms 468 KB Output is correct
27 Correct 3 ms 724 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 6 ms 840 KB Output is correct
30 Correct 5 ms 800 KB Output is correct
31 Correct 4 ms 724 KB Output is correct
32 Correct 4 ms 724 KB Output is correct
33 Correct 3 ms 768 KB Output is correct
34 Correct 6 ms 608 KB Output is correct
35 Correct 6 ms 724 KB Output is correct
36 Correct 6 ms 608 KB Output is correct
37 Correct 5 ms 604 KB Output is correct
38 Correct 90 ms 12272 KB Output is correct
39 Correct 99 ms 77460 KB Output is correct
40 Correct 75 ms 12236 KB Output is correct
41 Correct 81 ms 12600 KB Output is correct
42 Correct 91 ms 13112 KB Output is correct
43 Correct 58 ms 12016 KB Output is correct
44 Correct 31 ms 2484 KB Output is correct
45 Correct 99 ms 69964 KB Output is correct
46 Correct 102 ms 69936 KB Output is correct
47 Correct 86 ms 73564 KB Output is correct
48 Correct 87 ms 73628 KB Output is correct
49 Correct 91 ms 70112 KB Output is correct
50 Correct 91 ms 70100 KB Output is correct
51 Correct 82 ms 71112 KB Output is correct
52 Correct 81 ms 71172 KB Output is correct
53 Correct 39 ms 7240 KB Output is correct
54 Correct 112 ms 69836 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 16 ms 1500 KB Output is correct
6 Correct 1 ms 596 KB Output is correct
7 Correct 2 ms 596 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 6 ms 596 KB Output is correct
13 Correct 55 ms 4068 KB Output is correct
14 Correct 105 ms 7136 KB Output is correct
15 Correct 84 ms 5444 KB Output is correct
16 Correct 122 ms 71888 KB Output is correct
17 Correct 253 ms 81396 KB Output is correct
18 Correct 468 ms 93092 KB Output is correct
19 Correct 204 ms 73176 KB Output is correct
20 Correct 150 ms 73272 KB Output is correct
21 Correct 206 ms 73228 KB Output is correct
22 Correct 234 ms 81488 KB Output is correct
23 Correct 205 ms 81492 KB Output is correct
24 Correct 433 ms 81444 KB Output is correct
25 Correct 238 ms 81300 KB Output is correct
26 Correct 432 ms 81396 KB Output is correct
27 Correct 976 ms 94916 KB Output is correct
28 Correct 836 ms 110148 KB Output is correct
29 Correct 598 ms 99424 KB Output is correct
30 Correct 556 ms 89656 KB Output is correct
31 Correct 492 ms 91624 KB Output is correct
32 Correct 554 ms 84796 KB Output is correct
33 Correct 457 ms 89928 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 24 ms 3460 KB Output is correct
5 Correct 50 ms 7052 KB Output is correct
6 Correct 2 ms 724 KB Output is correct
7 Correct 3 ms 724 KB Output is correct
8 Correct 6 ms 848 KB Output is correct
9 Correct 77 ms 12300 KB Output is correct
10 Correct 83 ms 77412 KB Output is correct
11 Correct 18 ms 1524 KB Output is correct
12 Correct 114 ms 7180 KB Output is correct
13 Correct 325 ms 103224 KB Output is correct
14 Correct 238 ms 103120 KB Output is correct
15 Correct 428 ms 103124 KB Output is correct
16 Correct 1027 ms 139416 KB Output is correct
17 Correct 326 ms 106984 KB Output is correct
18 Correct 580 ms 139428 KB Output is correct
19 Correct 323 ms 107788 KB Output is correct
20 Correct 296 ms 107924 KB Output is correct
21 Correct 290 ms 108396 KB Output is correct
22 Correct 244 ms 108276 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 3 ms 724 KB Output is correct
26 Correct 3 ms 724 KB Output is correct
27 Correct 4 ms 724 KB Output is correct
28 Correct 3 ms 724 KB Output is correct
29 Correct 3 ms 724 KB Output is correct
30 Correct 4 ms 792 KB Output is correct
31 Correct 2 ms 724 KB Output is correct
32 Correct 3 ms 724 KB Output is correct
33 Correct 2 ms 724 KB Output is correct
34 Correct 2 ms 596 KB Output is correct
35 Correct 1 ms 596 KB Output is correct
36 Correct 0 ms 212 KB Output is correct
37 Correct 0 ms 212 KB Output is correct
38 Correct 3 ms 724 KB Output is correct
39 Correct 3 ms 708 KB Output is correct
40 Correct 3 ms 724 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 3 ms 724 KB Output is correct
43 Correct 3 ms 724 KB Output is correct
44 Correct 3 ms 724 KB Output is correct
45 Correct 1 ms 340 KB Output is correct
46 Correct 1 ms 340 KB Output is correct
47 Correct 3 ms 724 KB Output is correct
48 Correct 1 ms 468 KB Output is correct
49 Correct 3 ms 724 KB Output is correct
50 Correct 1 ms 340 KB Output is correct
51 Correct 6 ms 840 KB Output is correct
52 Correct 5 ms 800 KB Output is correct
53 Correct 4 ms 724 KB Output is correct
54 Correct 4 ms 724 KB Output is correct
55 Correct 3 ms 768 KB Output is correct
56 Correct 6 ms 608 KB Output is correct
57 Correct 6 ms 724 KB Output is correct
58 Correct 6 ms 608 KB Output is correct
59 Correct 5 ms 604 KB Output is correct
60 Correct 90 ms 12272 KB Output is correct
61 Correct 99 ms 77460 KB Output is correct
62 Correct 75 ms 12236 KB Output is correct
63 Correct 81 ms 12600 KB Output is correct
64 Correct 91 ms 13112 KB Output is correct
65 Correct 58 ms 12016 KB Output is correct
66 Correct 31 ms 2484 KB Output is correct
67 Correct 99 ms 69964 KB Output is correct
68 Correct 102 ms 69936 KB Output is correct
69 Correct 86 ms 73564 KB Output is correct
70 Correct 87 ms 73628 KB Output is correct
71 Correct 91 ms 70112 KB Output is correct
72 Correct 91 ms 70100 KB Output is correct
73 Correct 82 ms 71112 KB Output is correct
74 Correct 81 ms 71172 KB Output is correct
75 Correct 39 ms 7240 KB Output is correct
76 Correct 112 ms 69836 KB Output is correct
77 Correct 1 ms 212 KB Output is correct
78 Correct 0 ms 212 KB Output is correct
79 Correct 0 ms 212 KB Output is correct
80 Correct 0 ms 212 KB Output is correct
81 Correct 16 ms 1500 KB Output is correct
82 Correct 1 ms 596 KB Output is correct
83 Correct 2 ms 596 KB Output is correct
84 Correct 0 ms 340 KB Output is correct
85 Correct 1 ms 340 KB Output is correct
86 Correct 1 ms 340 KB Output is correct
87 Correct 1 ms 340 KB Output is correct
88 Correct 6 ms 596 KB Output is correct
89 Correct 55 ms 4068 KB Output is correct
90 Correct 105 ms 7136 KB Output is correct
91 Correct 84 ms 5444 KB Output is correct
92 Correct 122 ms 71888 KB Output is correct
93 Correct 253 ms 81396 KB Output is correct
94 Correct 468 ms 93092 KB Output is correct
95 Correct 204 ms 73176 KB Output is correct
96 Correct 150 ms 73272 KB Output is correct
97 Correct 206 ms 73228 KB Output is correct
98 Correct 234 ms 81488 KB Output is correct
99 Correct 205 ms 81492 KB Output is correct
100 Correct 433 ms 81444 KB Output is correct
101 Correct 238 ms 81300 KB Output is correct
102 Correct 432 ms 81396 KB Output is correct
103 Correct 976 ms 94916 KB Output is correct
104 Correct 836 ms 110148 KB Output is correct
105 Correct 598 ms 99424 KB Output is correct
106 Correct 556 ms 89656 KB Output is correct
107 Correct 492 ms 91624 KB Output is correct
108 Correct 554 ms 84796 KB Output is correct
109 Correct 457 ms 89928 KB Output is correct
110 Correct 77 ms 7248 KB Output is correct
111 Correct 57 ms 5808 KB Output is correct
112 Correct 474 ms 105076 KB Output is correct
113 Correct 206 ms 76812 KB Output is correct
114 Correct 328 ms 93464 KB Output is correct
115 Correct 101 ms 71132 KB Output is correct
116 Correct 450 ms 83052 KB Output is correct
117 Correct 496 ms 94796 KB Output is correct
118 Correct 110 ms 70016 KB Output is correct
119 Correct 119 ms 70104 KB Output is correct
120 Correct 32 ms 7468 KB Output is correct
121 Correct 546 ms 85648 KB Output is correct
122 Correct 552 ms 85576 KB Output is correct
123 Correct 243 ms 78668 KB Output is correct
124 Correct 164 ms 78752 KB Output is correct
125 Correct 249 ms 79200 KB Output is correct
126 Correct 1090 ms 151576 KB Output is correct
127 Correct 493 ms 108628 KB Output is correct
128 Correct 306 ms 108700 KB Output is correct
129 Correct 672 ms 114124 KB Output is correct
130 Correct 358 ms 108748 KB Output is correct