Submission #1058161

# Submission time Handle Problem Language Result Execution time Memory
1058161 2024-08-14T08:46:11 Z 123(#11113) Infiltration (CCO24_day2problem1) C++17
18 / 25
9 ms 640 KB
#include <bits/stdc++.h>
using namespace std;

vector<int> adj[105];
int p[105];
int sz[105];

void dfs(int v,int pr) {
    p[v]=pr;
    sz[v]=1;
    for(int i=0;i<adj[v].size();i++) {
        int nt=adj[v][i];
        if (pr!=nt) {
            dfs(nt,v);
            sz[v]+=sz[nt];
        }
    }
}

int getc(int v,int pr,int half) {
    for(int i=0;i<adj[v].size();i++) {
        int nt=adj[v][i];
        if (pr!=nt) {
            if (sz[nt]>half) {
                return getc(nt,v,half);
            }
        }
    }
    return v;
}

int getp(int x) {
    return p[x]==-1?x:p[x];
}

int move0(int v,int x,int y) {
    for(int i=0;i<2*y;i++) {
        if (i%2==0) {
            v=getp(v);
        }
        printf("%d ",v);
    }
    vector<int> vec;
    for(int i=0;i<x*2;i++) {
        if (i%2==0) {
            vec.push_back(v);
            v=getp(v);
        }
        printf("%d ",v);
    }
    for(int i=0;i<x*2;i++) {
        if (i%2==0) {
            v=vec[x-1-i/2];
        }
        printf("%d ",v);
    }
    for(int i=0;i<x*4-2;i++) {
        printf("%d ",v);
    }
    return v;
}

int move1(int v,int x,int y) {
    for(int i=0;i<2*y;i++) {
        if (i%2==1) {
            v=getp(v);
        }
        printf("%d ",v);
    }
    vector<int> vec;
    for(int i=0;i<x*4-2;i++) {
        printf("%d ",v);
    }
    for(int i=0;i<x*2;i++) {
        if (i&1) {
            vec.push_back(v);
            v=getp(v);
        }
        printf("%d ",v);
    }
    for(int i=0;i<x*2;i++) {
        if (i%2==1) {
            v=vec[x-1-i/2];
        }
        printf("%d ",v);
    }
    return v;
}

int main(void) {
    int n;
    scanf("%d",&n);
    if (n!=100) {
        return 0;
    }
    for(int i=1;i<n;i++) {
        int u,v;
        scanf("%d %d",&u,&v);
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    dfs(0,-1);
    int c=getc(0,-1,n/2);
    dfs(c,-1);
    int t=500;
    printf("%d\n",t);
    for(int i=0;i<n;i++) {
        int now=i;
        now=move0(i,2,1);
        now=move0(now,8,3);
        now=move0(now,14,3);
        for(int j=0;j<200;j++) {
            if (j%2==0) {
                now=getp(now);
            }
            printf("%d ",now);
        }
        for(int j=0;j<100;j++) {
            printf("%d ",now);
        }
        printf("\n");
    }
    for(int i=0;i<n;i++) {
        int now=i;
        now=move1(i,2,1);
        now=move1(now,8,3);
        now=move1(now,14,3);
        for(int j=0;j<200;j++) {
            if (j%2==1) {
                now=getp(now);
            }
            printf("%d ",now);
        }
        for(int j=0;j<100;j++) {
            printf("%d ",now);
        }
        printf("\n");
    }
}

Compilation message

Main.cpp: In function 'void dfs(int, int)':
Main.cpp:11:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   11 |     for(int i=0;i<adj[v].size();i++) {
      |                 ~^~~~~~~~~~~~~~
Main.cpp: In function 'int getc(int, int, int)':
Main.cpp:21:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |     for(int i=0;i<adj[v].size();i++) {
      |                 ~^~~~~~~~~~~~~~
Main.cpp: In function 'int main()':
Main.cpp:92:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   92 |     scanf("%d",&n);
      |     ~~~~~^~~~~~~~~
Main.cpp:98:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   98 |         scanf("%d %d",&u,&v);
      |         ~~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Partially correct 5 ms 604 KB Partially correct
2 Partially correct 4 ms 604 KB Partially correct
3 Partially correct 7 ms 640 KB Partially correct
4 Partially correct 9 ms 640 KB Partially correct
5 Partially correct 5 ms 604 KB Partially correct
6 Partially correct 7 ms 604 KB Partially correct
7 Correct 5 ms 604 KB Output is correct
8 Correct 8 ms 604 KB Output is correct
9 Correct 5 ms 604 KB Output is correct
10 Correct 6 ms 604 KB Output is correct
11 Correct 4 ms 604 KB Output is correct
12 Correct 6 ms 604 KB Output is correct
13 Correct 6 ms 444 KB Output is correct
14 Correct 4 ms 516 KB Output is correct
15 Correct 5 ms 628 KB Output is correct
16 Partially correct 7 ms 604 KB Partially correct
17 Partially correct 7 ms 600 KB Partially correct
18 Partially correct 5 ms 544 KB Partially correct
19 Partially correct 4 ms 600 KB Partially correct
20 Partially correct 7 ms 604 KB Partially correct
21 Partially correct 5 ms 604 KB Partially correct
22 Partially correct 5 ms 604 KB Partially correct
23 Partially correct 6 ms 592 KB Partially correct
24 Partially correct 4 ms 524 KB Partially correct
25 Partially correct 8 ms 604 KB Partially correct