답안 #617969

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
617969 2022-08-01T18:18:36 Z patrikpavic2 Jail (JOI22_jail) C++17
72 / 100
3532 ms 1048576 KB
#include <cstdio>
#include <vector>
#include <algorithm>

#define X first
#define Y second
#define PB push_back

using namespace std;

const int N = 120500;
const int LOG = 17;

vector < int > v[N], poc[N], zav[N], sm[3 * N];
int n, q, st[N], en[N], bio[3 * N], dep[N], par[N];
vector < int > put;

void dfs(int x, int lst){
	dep[x] = dep[lst] + 1;
	par[x] = lst;
	for(int y : v[x])
		if(y != lst) dfs(y, x);
}

void napravi_put(int a, int b){
	vector < int > L, R;
	//printf("%d -> %d\n", a, b);
	while(a != b){
		if(dep[a] > dep[b])
			L.PB(a), a = par[a];
		else
			R.PB(b), b = par[b];
	}
	L.PB(a);
	reverse(R.begin(), R.end());
	put.clear();
	for(int x : L) put.PB(x);
	for(int x : R) put.PB(x);
}

int naso = 0;

void ciklus(int x){
	if(bio[x] == 1) { naso = 1; }
	if(bio[x]) return;
	bio[x] = 1;
	for(int y : sm[x]){
	//	printf("(%d %d) -> (%d %d) %d\n", x % N, x / N, y % N, y / N, naso);
		ciklus(y);
	}
	bio[x] = 2;
}

void solve(){
	scanf("%d", &n);
	for(int i = 1;i < n;i++){
		int a, b; scanf("%d%d", &a, &b);
		v[a].PB(b);
		v[b].PB(a);
	}
	dfs(1, 1);
	scanf("%d", &q);
	for(int i = 0;i < q;i++){
		int a, b; scanf("%d%d", &a, &b);
		st[i] = a; en[i] = b;
		poc[a].PB(i); zav[b].PB(i);
	}
	for(int i = 1;i <= n;i++){
		for(int x : poc[i])
			sm[i].PB(2 * N + x);
		for(int x : zav[i])
			sm[2 * N + x].PB(i + N);
	}
	for(int i = 0;i < q;i++){
		napravi_put(st[i], en[i]);
		for(int j = 0;j + 1 < (int)put.size();j++){
			sm[2 * N + i].PB(put[j + 1]);
			sm[N + put[j]].PB(2 * N + i);
		}
	}
	naso = 0;
	for(int i = 1;i <= n;i++) ciklus(i), ciklus(i + N);
	for(int j = 0;j < q;j++) ciklus(2 * N + j);
	printf(naso ? "No\n" : "Yes\n");
	for(int i = 1;i <= n;i++) v[i].clear(), poc[i].clear(), zav[i].clear();
	for(int i = 1;i <= n;i++) sm[i].clear(), sm[i + N].clear(), bio[i] = 0, bio[i + N] = 0;
	for(int j = 0;j < q;j++) sm[2 * N + j].clear(), bio[2 * N + j] = 0;
}

int main(){
	int T; scanf("%d", &T);
	for(;T--;) solve();
	return 0;
}

Compilation message

jail.cpp: In function 'void solve()':
jail.cpp:55:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   55 |  scanf("%d", &n);
      |  ~~~~~^~~~~~~~~~
jail.cpp:57:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   57 |   int a, b; scanf("%d%d", &a, &b);
      |             ~~~~~^~~~~~~~~~~~~~~~
jail.cpp:62:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   62 |  scanf("%d", &q);
      |  ~~~~~^~~~~~~~~~
jail.cpp:64:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   64 |   int a, b; scanf("%d%d", &a, &b);
      |             ~~~~~^~~~~~~~~~~~~~~~
jail.cpp: In function 'int main()':
jail.cpp:91:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   91 |  int T; scanf("%d", &T);
      |         ~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 17236 KB Output is correct
2 Correct 10 ms 17304 KB Output is correct
3 Correct 12 ms 17292 KB Output is correct
4 Correct 28 ms 17356 KB Output is correct
5 Correct 37 ms 17416 KB Output is correct
6 Correct 12 ms 17292 KB Output is correct
7 Correct 11 ms 17364 KB Output is correct
8 Correct 14 ms 17536 KB Output is correct
9 Correct 324 ms 45236 KB Output is correct
10 Correct 2190 ms 507816 KB Output is correct
11 Correct 20 ms 17364 KB Output is correct
12 Correct 68 ms 17572 KB Output is correct
13 Correct 343 ms 108560 KB Output is correct
14 Correct 391 ms 140600 KB Output is correct
15 Runtime error 3532 ms 1048576 KB Execution killed with signal 9
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 17236 KB Output is correct
2 Correct 10 ms 17236 KB Output is correct
3 Correct 10 ms 17292 KB Output is correct
4 Correct 10 ms 17236 KB Output is correct
5 Correct 11 ms 17236 KB Output is correct
6 Correct 10 ms 17236 KB Output is correct
7 Correct 11 ms 17364 KB Output is correct
8 Correct 11 ms 17236 KB Output is correct
9 Correct 11 ms 17236 KB Output is correct
10 Correct 11 ms 17288 KB Output is correct
11 Correct 13 ms 17304 KB Output is correct
12 Correct 11 ms 17236 KB Output is correct
13 Correct 10 ms 17236 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 17236 KB Output is correct
2 Correct 10 ms 17236 KB Output is correct
3 Correct 10 ms 17292 KB Output is correct
4 Correct 10 ms 17236 KB Output is correct
5 Correct 11 ms 17236 KB Output is correct
6 Correct 10 ms 17236 KB Output is correct
7 Correct 11 ms 17364 KB Output is correct
8 Correct 11 ms 17236 KB Output is correct
9 Correct 11 ms 17236 KB Output is correct
10 Correct 11 ms 17288 KB Output is correct
11 Correct 13 ms 17304 KB Output is correct
12 Correct 11 ms 17236 KB Output is correct
13 Correct 10 ms 17236 KB Output is correct
14 Correct 10 ms 17216 KB Output is correct
15 Correct 10 ms 17208 KB Output is correct
16 Correct 12 ms 17364 KB Output is correct
17 Correct 11 ms 17296 KB Output is correct
18 Correct 12 ms 17364 KB Output is correct
19 Correct 10 ms 17272 KB Output is correct
20 Correct 11 ms 17288 KB Output is correct
21 Correct 11 ms 17364 KB Output is correct
22 Correct 10 ms 17372 KB Output is correct
23 Correct 11 ms 17296 KB Output is correct
24 Correct 9 ms 17280 KB Output is correct
25 Correct 12 ms 17364 KB Output is correct
26 Correct 13 ms 17284 KB Output is correct
27 Correct 10 ms 17364 KB Output is correct
28 Correct 9 ms 17236 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 17236 KB Output is correct
2 Correct 10 ms 17236 KB Output is correct
3 Correct 10 ms 17292 KB Output is correct
4 Correct 10 ms 17236 KB Output is correct
5 Correct 11 ms 17236 KB Output is correct
6 Correct 10 ms 17236 KB Output is correct
7 Correct 11 ms 17364 KB Output is correct
8 Correct 11 ms 17236 KB Output is correct
9 Correct 11 ms 17236 KB Output is correct
10 Correct 11 ms 17288 KB Output is correct
11 Correct 13 ms 17304 KB Output is correct
12 Correct 11 ms 17236 KB Output is correct
13 Correct 10 ms 17236 KB Output is correct
14 Correct 10 ms 17216 KB Output is correct
15 Correct 10 ms 17208 KB Output is correct
16 Correct 12 ms 17364 KB Output is correct
17 Correct 11 ms 17296 KB Output is correct
18 Correct 12 ms 17364 KB Output is correct
19 Correct 10 ms 17272 KB Output is correct
20 Correct 11 ms 17288 KB Output is correct
21 Correct 11 ms 17364 KB Output is correct
22 Correct 10 ms 17372 KB Output is correct
23 Correct 11 ms 17296 KB Output is correct
24 Correct 9 ms 17280 KB Output is correct
25 Correct 12 ms 17364 KB Output is correct
26 Correct 13 ms 17284 KB Output is correct
27 Correct 10 ms 17364 KB Output is correct
28 Correct 9 ms 17236 KB Output is correct
29 Correct 14 ms 17612 KB Output is correct
30 Correct 12 ms 17408 KB Output is correct
31 Correct 16 ms 17492 KB Output is correct
32 Correct 11 ms 17364 KB Output is correct
33 Correct 11 ms 17492 KB Output is correct
34 Correct 12 ms 17364 KB Output is correct
35 Correct 14 ms 17364 KB Output is correct
36 Correct 12 ms 17364 KB Output is correct
37 Correct 14 ms 17396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 17236 KB Output is correct
2 Correct 10 ms 17236 KB Output is correct
3 Correct 10 ms 17292 KB Output is correct
4 Correct 10 ms 17236 KB Output is correct
5 Correct 11 ms 17236 KB Output is correct
6 Correct 10 ms 17236 KB Output is correct
7 Correct 11 ms 17364 KB Output is correct
8 Correct 11 ms 17236 KB Output is correct
9 Correct 11 ms 17236 KB Output is correct
10 Correct 11 ms 17288 KB Output is correct
11 Correct 13 ms 17304 KB Output is correct
12 Correct 11 ms 17236 KB Output is correct
13 Correct 10 ms 17236 KB Output is correct
14 Correct 10 ms 17216 KB Output is correct
15 Correct 10 ms 17208 KB Output is correct
16 Correct 12 ms 17364 KB Output is correct
17 Correct 11 ms 17296 KB Output is correct
18 Correct 12 ms 17364 KB Output is correct
19 Correct 10 ms 17272 KB Output is correct
20 Correct 11 ms 17288 KB Output is correct
21 Correct 11 ms 17364 KB Output is correct
22 Correct 10 ms 17372 KB Output is correct
23 Correct 11 ms 17296 KB Output is correct
24 Correct 9 ms 17280 KB Output is correct
25 Correct 12 ms 17364 KB Output is correct
26 Correct 13 ms 17284 KB Output is correct
27 Correct 10 ms 17364 KB Output is correct
28 Correct 9 ms 17236 KB Output is correct
29 Correct 14 ms 17612 KB Output is correct
30 Correct 12 ms 17408 KB Output is correct
31 Correct 16 ms 17492 KB Output is correct
32 Correct 11 ms 17364 KB Output is correct
33 Correct 11 ms 17492 KB Output is correct
34 Correct 12 ms 17364 KB Output is correct
35 Correct 14 ms 17364 KB Output is correct
36 Correct 12 ms 17364 KB Output is correct
37 Correct 14 ms 17396 KB Output is correct
38 Correct 341 ms 46432 KB Output is correct
39 Correct 2277 ms 509220 KB Output is correct
40 Correct 163 ms 30080 KB Output is correct
41 Correct 52 ms 19468 KB Output is correct
42 Correct 123 ms 29064 KB Output is correct
43 Correct 36 ms 18924 KB Output is correct
44 Correct 21 ms 17864 KB Output is correct
45 Correct 71 ms 25356 KB Output is correct
46 Correct 70 ms 25464 KB Output is correct
47 Correct 378 ms 115704 KB Output is correct
48 Correct 388 ms 118428 KB Output is correct
49 Correct 85 ms 30044 KB Output is correct
50 Correct 85 ms 30044 KB Output is correct
51 Correct 65 ms 25256 KB Output is correct
52 Correct 55 ms 25260 KB Output is correct
53 Correct 21 ms 18252 KB Output is correct
54 Correct 88 ms 24708 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 17188 KB Output is correct
2 Correct 9 ms 17236 KB Output is correct
3 Correct 9 ms 17236 KB Output is correct
4 Correct 10 ms 17236 KB Output is correct
5 Correct 16 ms 17312 KB Output is correct
6 Correct 11 ms 17280 KB Output is correct
7 Correct 10 ms 17336 KB Output is correct
8 Correct 9 ms 17276 KB Output is correct
9 Correct 10 ms 17276 KB Output is correct
10 Correct 10 ms 17236 KB Output is correct
11 Correct 12 ms 17236 KB Output is correct
12 Correct 13 ms 17364 KB Output is correct
13 Correct 46 ms 17940 KB Output is correct
14 Correct 54 ms 18084 KB Output is correct
15 Correct 47 ms 17952 KB Output is correct
16 Correct 84 ms 28204 KB Output is correct
17 Correct 260 ms 47020 KB Output is correct
18 Correct 501 ms 76020 KB Output is correct
19 Correct 108 ms 32204 KB Output is correct
20 Correct 133 ms 32296 KB Output is correct
21 Correct 128 ms 32520 KB Output is correct
22 Correct 240 ms 46236 KB Output is correct
23 Correct 178 ms 45300 KB Output is correct
24 Correct 185 ms 46120 KB Output is correct
25 Correct 183 ms 46524 KB Output is correct
26 Correct 184 ms 46368 KB Output is correct
27 Correct 299 ms 57200 KB Output is correct
28 Correct 246 ms 58044 KB Output is correct
29 Correct 268 ms 52108 KB Output is correct
30 Correct 158 ms 40564 KB Output is correct
31 Correct 188 ms 43088 KB Output is correct
32 Correct 170 ms 38376 KB Output is correct
33 Correct 175 ms 41136 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 17236 KB Output is correct
2 Correct 10 ms 17304 KB Output is correct
3 Correct 12 ms 17292 KB Output is correct
4 Correct 28 ms 17356 KB Output is correct
5 Correct 37 ms 17416 KB Output is correct
6 Correct 12 ms 17292 KB Output is correct
7 Correct 11 ms 17364 KB Output is correct
8 Correct 14 ms 17536 KB Output is correct
9 Correct 324 ms 45236 KB Output is correct
10 Correct 2190 ms 507816 KB Output is correct
11 Correct 20 ms 17364 KB Output is correct
12 Correct 68 ms 17572 KB Output is correct
13 Correct 343 ms 108560 KB Output is correct
14 Correct 391 ms 140600 KB Output is correct
15 Runtime error 3532 ms 1048576 KB Execution killed with signal 9
16 Halted 0 ms 0 KB -