답안 #1057962

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1057962 2024-08-14T07:40:52 Z 김은성(#11075) Infiltration (CCO24_day2problem1) C++17
8 / 25
11 ms 3164 KB
#include <bits/stdc++.h>
using namespace std;
vector<int> graph[109];
vector<int> routea[109], routeb[109];
vector<int> route[109][109];
bool ch[109];
bool chc[109];
int n, sz[109];
void getsize(int v){
	ch[v] = 1;
	sz[v] = 1;
	for(int u: graph[v]){
		if(!ch[u] && !chc[u]){
			getsize(u);
			sz[v] += sz[u];
		}
	}
}
int centroid(int v, int totsz){
	ch[v] = 1;
	for(int u: graph[v]){
		if(!ch[u] &&  !chc[u] && sz[u] > totsz/2)
			return centroid(u, totsz);
	}
	return v;
}
void printanswer(int n){
	int TEST = 8*n;
	printf("%d\n", TEST);
	int i, j;
	for(j=0; j<n; j++){
		for(i=1; i<=TEST; i++){
			int temp = (i+1)/2;
			if(temp >= routea[j].size())
				printf("%d ", routea[j].empty() ? j : routea[j].back());
			else
				printf("%d ", routea[j][temp]);
		}
		printf("\n");
	}
	
	for(j=0; j<n; j++){
		for(i=1; i<=TEST; i++){
			int temp = i/2;
			if(temp >= routeb[j].size())
				printf("%d ", routeb[j].empty() ? j : routeb[j].back());
			else
				printf("%d ", routeb[j][temp]);
		}
		printf("\n");
	}
}
void solve(int p, int v){
	memset(ch, 0, sizeof(ch));
	getsize(v);
	memset(ch, 0, sizeof(ch));
	int c = centroid(v, sz[v]);
	chc[c] = 1;
	memset(ch, 0, sizeof(ch));
	if(p != -1){
		for(int u: route[c][p]){
			//printf("c=%d p=%d u=%d\n", c, p, u);
			routea[c].push_back(u);
		}
		for(int i=1; i<routea[p].size(); i++)
			routea[c].push_back(routea[p][i]);
		routeb[c] = routea[c];
	}
	else
		routea[c].push_back(c), routeb[c].push_back(c);
	for(int u: graph[c]){
		if(chc[u]) continue;
		solve(c, u);
	}
}
void init_dfs(int source, int p, int v){
	ch[v] = 1;
	if(p != -1){
		route[v][source].push_back(p);
		for(int u: route[p][source])
			route[v][source].push_back(u);
	}
	for(int u: graph[v]){
		if(!ch[u])
			init_dfs(source, v, u);
	}
}
int main(){
	int u, v, i;
	scanf("%d", &n);
	for(i=1; i<n; i++){
		scanf("%d %d", &u, &v);
		graph[u].push_back(v);
		graph[v].push_back(u);
	}
	for(i=0; i<n; i++){
		routea[i].push_back(i);
		routeb[i].push_back(i);
	}
	for(i=0; i<n; i++){
		memset(ch, 0, sizeof(ch));
		init_dfs(i, -1, i);
	}
	solve(-1, 0);
	printanswer(n);
	return 0;
}

Compilation message

Main.cpp: In function 'void printanswer(int)':
Main.cpp:34:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |    if(temp >= routea[j].size())
      |       ~~~~~^~~~~~~~~~~~~~~~~~~
Main.cpp:45:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |    if(temp >= routeb[j].size())
      |       ~~~~~^~~~~~~~~~~~~~~~~~~
Main.cpp: In function 'void solve(int, int)':
Main.cpp:65:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   65 |   for(int i=1; i<routea[p].size(); i++)
      |                ~^~~~~~~~~~~~~~~~~
Main.cpp: In function 'int main()':
Main.cpp:90:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   90 |  scanf("%d", &n);
      |  ~~~~~^~~~~~~~~~
Main.cpp:92:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   92 |   scanf("%d %d", &u, &v);
      |   ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Partially correct 9 ms 3164 KB Partially correct
2 Partially correct 8 ms 2684 KB Partially correct
3 Partially correct 8 ms 2652 KB Partially correct
4 Partially correct 9 ms 3164 KB Partially correct
5 Partially correct 9 ms 3164 KB Partially correct
6 Partially correct 9 ms 3164 KB Partially correct
7 Correct 7 ms 1520 KB Output is correct
8 Correct 7 ms 1372 KB Output is correct
9 Correct 7 ms 1372 KB Output is correct
10 Correct 7 ms 1368 KB Output is correct
11 Correct 7 ms 1368 KB Output is correct
12 Correct 7 ms 1372 KB Output is correct
13 Correct 8 ms 1112 KB Output is correct
14 Correct 7 ms 1372 KB Output is correct
15 Correct 7 ms 1336 KB Output is correct
16 Partially correct 8 ms 1624 KB Partially correct
17 Partially correct 8 ms 1628 KB Partially correct
18 Partially correct 8 ms 1892 KB Partially correct
19 Partially correct 8 ms 1880 KB Partially correct
20 Partially correct 8 ms 1884 KB Partially correct
21 Partially correct 8 ms 1940 KB Partially correct
22 Partially correct 8 ms 1880 KB Partially correct
23 Partially correct 8 ms 1884 KB Partially correct
24 Partially correct 11 ms 3164 KB Partially correct
25 Partially correct 10 ms 2908 KB Partially correct