# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1057902 |
2024-08-14T07:14:10 Z |
김은성(#11075) |
Infiltration (CCO24_day2problem1) |
C++17 |
|
10 ms |
1112 KB |
#define TEST 1200
#include <bits/stdc++.h>
using namespace std;
vector<int> graph[109];
vector<int> routea[109], routeb[109];
bool ch[109];
int sz[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 p, int v){
ch[v] = 1;
//printf("p=%d v=%d\n", p, v);
if(p != -1){
routea[v].push_back(p);
routeb[v].push_back(p);
for(int u: routea[p]){
routea[v].push_back(u);
routeb[v].push_back(u);
}
}
for(int u: graph[v]){
if(!ch[u]){
dfs(v, u);
}
}
}
void printanswer(int 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)/2;
if(temp >= routeb[j].size())
printf("%d ", routeb[j].empty() ? j : routeb[j].back());
else
printf("%d ", routeb[j][temp]);
}
printf("\n");
}
}
int main(){
int n, 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=1; i<=n; i++){
routea[i].push_back(i);
routeb[i].push_back(i);
}
getsize(1);
memset(ch, 0, sizeof(ch));
int c = centroid(1, n);
memset(ch, 0, sizeof(ch));
dfs(-1, c);
printanswer(n);
return 0;
}
Compilation message
Main.cpp: In function 'void printanswer(int)':
Main.cpp:49:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
49 | if(temp >= routea[j].size())
| ~~~~~^~~~~~~~~~~~~~~~~~~
Main.cpp:60:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
60 | if(temp >= routeb[j].size())
| ~~~~~^~~~~~~~~~~~~~~~~~~
Main.cpp: In function 'int main()':
Main.cpp:70:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
70 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
Main.cpp:72:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
72 | scanf("%d %d", &u, &v);
| ~~~~~^~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
10 ms |
1112 KB |
Cannot move |
2 |
Halted |
0 ms |
0 KB |
- |