답안 #617960

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
617960 2022-08-01T18:07:44 Z patrikpavic2 Jail (JOI22_jail) C++17
61 / 100
5000 ms 508384 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];
vector < int > put;

bool dfs(int x, int lst, int zav){
	if(x == zav){
		put.PB(x); return 1;
	}
	for(int y : v[x]){
		if(y == lst) continue;
		if(dfs(y, x, zav)){
			put.PB(x);
			return 1;
		}
	}
	return 0;
}

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);
	}
	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++){
		put.clear();
		dfs(st[i], st[i], en[i]);
		for(int j = 0;j + 1 < (int)put.size();j++){
			sm[2 * N + i].PB(put[j]);
			sm[N + put[j + 1]].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:46:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   46 |  scanf("%d", &n);
      |  ~~~~~^~~~~~~~~~
jail.cpp:48:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 |   int a, b; scanf("%d%d", &a, &b);
      |             ~~~~~^~~~~~~~~~~~~~~~
jail.cpp:52:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   52 |  scanf("%d", &q);
      |  ~~~~~^~~~~~~~~~
jail.cpp:54:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   54 |   int a, b; scanf("%d%d", &a, &b);
      |             ~~~~~^~~~~~~~~~~~~~~~
jail.cpp: In function 'int main()':
jail.cpp:82:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   82 |  int T; scanf("%d", &T);
      |         ~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 17236 KB Output is correct
2 Correct 11 ms 17236 KB Output is correct
3 Correct 9 ms 17236 KB Output is correct
4 Correct 21 ms 17620 KB Output is correct
5 Correct 34 ms 18048 KB Output is correct
6 Correct 12 ms 17364 KB Output is correct
7 Correct 10 ms 17364 KB Output is correct
8 Correct 14 ms 17568 KB Output is correct
9 Correct 404 ms 46200 KB Output is correct
10 Correct 2733 ms 508268 KB Output is correct
11 Correct 16 ms 17364 KB Output is correct
12 Correct 67 ms 18380 KB Output is correct
13 Execution timed out 5106 ms 56844 KB Time limit exceeded
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 17280 KB Output is correct
2 Correct 14 ms 17280 KB Output is correct
3 Correct 12 ms 17296 KB Output is correct
4 Correct 13 ms 17236 KB Output is correct
5 Correct 13 ms 17344 KB Output is correct
6 Correct 11 ms 17236 KB Output is correct
7 Correct 11 ms 17292 KB Output is correct
8 Correct 11 ms 17348 KB Output is correct
9 Correct 12 ms 17352 KB Output is correct
10 Correct 14 ms 17236 KB Output is correct
11 Correct 13 ms 17316 KB Output is correct
12 Correct 12 ms 17328 KB Output is correct
13 Correct 13 ms 17296 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 17280 KB Output is correct
2 Correct 14 ms 17280 KB Output is correct
3 Correct 12 ms 17296 KB Output is correct
4 Correct 13 ms 17236 KB Output is correct
5 Correct 13 ms 17344 KB Output is correct
6 Correct 11 ms 17236 KB Output is correct
7 Correct 11 ms 17292 KB Output is correct
8 Correct 11 ms 17348 KB Output is correct
9 Correct 12 ms 17352 KB Output is correct
10 Correct 14 ms 17236 KB Output is correct
11 Correct 13 ms 17316 KB Output is correct
12 Correct 12 ms 17328 KB Output is correct
13 Correct 13 ms 17296 KB Output is correct
14 Correct 13 ms 17268 KB Output is correct
15 Correct 11 ms 17276 KB Output is correct
16 Correct 12 ms 17296 KB Output is correct
17 Correct 14 ms 17288 KB Output is correct
18 Correct 12 ms 17292 KB Output is correct
19 Correct 13 ms 17260 KB Output is correct
20 Correct 14 ms 17368 KB Output is correct
21 Correct 11 ms 17364 KB Output is correct
22 Correct 14 ms 17356 KB Output is correct
23 Correct 11 ms 17276 KB Output is correct
24 Correct 13 ms 17288 KB Output is correct
25 Correct 13 ms 17236 KB Output is correct
26 Correct 11 ms 17236 KB Output is correct
27 Correct 12 ms 17296 KB Output is correct
28 Correct 11 ms 17268 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 17280 KB Output is correct
2 Correct 14 ms 17280 KB Output is correct
3 Correct 12 ms 17296 KB Output is correct
4 Correct 13 ms 17236 KB Output is correct
5 Correct 13 ms 17344 KB Output is correct
6 Correct 11 ms 17236 KB Output is correct
7 Correct 11 ms 17292 KB Output is correct
8 Correct 11 ms 17348 KB Output is correct
9 Correct 12 ms 17352 KB Output is correct
10 Correct 14 ms 17236 KB Output is correct
11 Correct 13 ms 17316 KB Output is correct
12 Correct 12 ms 17328 KB Output is correct
13 Correct 13 ms 17296 KB Output is correct
14 Correct 13 ms 17268 KB Output is correct
15 Correct 11 ms 17276 KB Output is correct
16 Correct 12 ms 17296 KB Output is correct
17 Correct 14 ms 17288 KB Output is correct
18 Correct 12 ms 17292 KB Output is correct
19 Correct 13 ms 17260 KB Output is correct
20 Correct 14 ms 17368 KB Output is correct
21 Correct 11 ms 17364 KB Output is correct
22 Correct 14 ms 17356 KB Output is correct
23 Correct 11 ms 17276 KB Output is correct
24 Correct 13 ms 17288 KB Output is correct
25 Correct 13 ms 17236 KB Output is correct
26 Correct 11 ms 17236 KB Output is correct
27 Correct 12 ms 17296 KB Output is correct
28 Correct 11 ms 17268 KB Output is correct
29 Correct 15 ms 17492 KB Output is correct
30 Correct 17 ms 17288 KB Output is correct
31 Correct 15 ms 17376 KB Output is correct
32 Correct 15 ms 17412 KB Output is correct
33 Correct 12 ms 17300 KB Output is correct
34 Correct 16 ms 17388 KB Output is correct
35 Correct 16 ms 17420 KB Output is correct
36 Correct 13 ms 17364 KB Output is correct
37 Correct 12 ms 17320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 17280 KB Output is correct
2 Correct 14 ms 17280 KB Output is correct
3 Correct 12 ms 17296 KB Output is correct
4 Correct 13 ms 17236 KB Output is correct
5 Correct 13 ms 17344 KB Output is correct
6 Correct 11 ms 17236 KB Output is correct
7 Correct 11 ms 17292 KB Output is correct
8 Correct 11 ms 17348 KB Output is correct
9 Correct 12 ms 17352 KB Output is correct
10 Correct 14 ms 17236 KB Output is correct
11 Correct 13 ms 17316 KB Output is correct
12 Correct 12 ms 17328 KB Output is correct
13 Correct 13 ms 17296 KB Output is correct
14 Correct 13 ms 17268 KB Output is correct
15 Correct 11 ms 17276 KB Output is correct
16 Correct 12 ms 17296 KB Output is correct
17 Correct 14 ms 17288 KB Output is correct
18 Correct 12 ms 17292 KB Output is correct
19 Correct 13 ms 17260 KB Output is correct
20 Correct 14 ms 17368 KB Output is correct
21 Correct 11 ms 17364 KB Output is correct
22 Correct 14 ms 17356 KB Output is correct
23 Correct 11 ms 17276 KB Output is correct
24 Correct 13 ms 17288 KB Output is correct
25 Correct 13 ms 17236 KB Output is correct
26 Correct 11 ms 17236 KB Output is correct
27 Correct 12 ms 17296 KB Output is correct
28 Correct 11 ms 17268 KB Output is correct
29 Correct 15 ms 17492 KB Output is correct
30 Correct 17 ms 17288 KB Output is correct
31 Correct 15 ms 17376 KB Output is correct
32 Correct 15 ms 17412 KB Output is correct
33 Correct 12 ms 17300 KB Output is correct
34 Correct 16 ms 17388 KB Output is correct
35 Correct 16 ms 17420 KB Output is correct
36 Correct 13 ms 17364 KB Output is correct
37 Correct 12 ms 17320 KB Output is correct
38 Correct 410 ms 46252 KB Output is correct
39 Correct 2856 ms 508384 KB Output is correct
40 Correct 508 ms 29864 KB Output is correct
41 Correct 396 ms 19432 KB Output is correct
42 Correct 243 ms 28752 KB Output is correct
43 Correct 57 ms 18892 KB Output is correct
44 Correct 50 ms 17740 KB Output is correct
45 Correct 1319 ms 24572 KB Output is correct
46 Correct 1515 ms 24624 KB Output is correct
47 Correct 924 ms 115220 KB Output is correct
48 Correct 859 ms 117848 KB Output is correct
49 Correct 998 ms 29104 KB Output is correct
50 Correct 1072 ms 29144 KB Output is correct
51 Correct 212 ms 24748 KB Output is correct
52 Correct 233 ms 24636 KB Output is correct
53 Correct 54 ms 18192 KB Output is correct
54 Correct 1194 ms 23656 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 17272 KB Output is correct
2 Correct 9 ms 17236 KB Output is correct
3 Correct 9 ms 17236 KB Output is correct
4 Correct 11 ms 17200 KB Output is correct
5 Correct 17 ms 17448 KB Output is correct
6 Correct 10 ms 17292 KB Output is correct
7 Correct 10 ms 17220 KB Output is correct
8 Correct 10 ms 17272 KB Output is correct
9 Correct 10 ms 17272 KB Output is correct
10 Correct 11 ms 17260 KB Output is correct
11 Correct 9 ms 17236 KB Output is correct
12 Correct 12 ms 17364 KB Output is correct
13 Correct 42 ms 17824 KB Output is correct
14 Correct 62 ms 18068 KB Output is correct
15 Correct 47 ms 17956 KB Output is correct
16 Execution timed out 5064 ms 24744 KB Time limit exceeded
17 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 17236 KB Output is correct
2 Correct 11 ms 17236 KB Output is correct
3 Correct 9 ms 17236 KB Output is correct
4 Correct 21 ms 17620 KB Output is correct
5 Correct 34 ms 18048 KB Output is correct
6 Correct 12 ms 17364 KB Output is correct
7 Correct 10 ms 17364 KB Output is correct
8 Correct 14 ms 17568 KB Output is correct
9 Correct 404 ms 46200 KB Output is correct
10 Correct 2733 ms 508268 KB Output is correct
11 Correct 16 ms 17364 KB Output is correct
12 Correct 67 ms 18380 KB Output is correct
13 Execution timed out 5106 ms 56844 KB Time limit exceeded
14 Halted 0 ms 0 KB -