Submission #1058223

# Submission time Handle Problem Language Result Execution time Memory
1058223 2024-08-14T09:00:03 Z 김은성(#11075) Infiltration (CCO24_day2problem1) C++17
0 / 25
10 ms 860 KB
#include <bits/stdc++.h>
using namespace std;
vector<int> graph[109];
int depth[109];
int par[109], sz[109];
bool ch[109];
void getsize(int v){
	ch[v] = 1;
	sz[v] = 1;
	for(int u: graph[v]){
		if(!ch[u]){
			getsize(u);
			sz[v] += sz[u];
		}
	}
}
int centroid(int v, int totsz){
	ch[v] = 1;
	for(int u: graph[v]){
		if(!ch[u] && sz[u] > totsz/2)
			return centroid(u, totsz);
	}
	return v;
}
void dfs(int v){
	ch[v] = 1;
	for(int u: graph[v]){
		if(!ch[u]){
			depth[u] = depth[v] + 1;
			par[u] = v;
			dfs(u);
		}
	}
}
int main(){
	int n, i, j, u, v;
	int ans = 1200;
	scanf("%d", &n);
	for(i=1; i<n; i++){
		scanf("%d %d", &u, &v);
		graph[u].push_back(v);
		graph[v].push_back(u);
	}
	getsize(0);
	memset(ch, 0, sizeof(ch));
	int c = centroid(0, n);
	//printf("c=%d\n", c);
	par[c] = -1;
	dfs(c);
	par[c] = c;
	printf("%d\n", ans);
	for(i=0; i<n; i++){
		int wait = 7 - depth[i]%7;
		for(j=0; j<wait; j++)
			printf("%d ", i);
		int v = i;
		for(j=wait; j<ans; j++){
			printf("%d ", par[v]);
			v = par[v];
		}
		printf("\n");
	}
	for(i=0; i<n; i++){
		int wait = 7 - depth[i]%7;
		for(j=0; j<wait; j++)
			printf("%d ", i);
		int v = i;
		for(j=wait; j<ans; j++){
			printf("%d ", par[v]);
			v = par[v];
		}
		printf("\n");
	}
	return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:38:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |  scanf("%d", &n);
      |  ~~~~~^~~~~~~~~~
Main.cpp:40:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |   scanf("%d %d", &u, &v);
      |   ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 10 ms 860 KB Cannot move
2 Halted 0 ms 0 KB -