Submission #1057736

# Submission time Handle Problem Language Result Execution time Memory
1057736 2024-08-14T04:39:09 Z 123(#11113) Infiltration (CCO24_day2problem1) C++17
0 / 25
4 ms 344 KB
#include <bits/stdc++.h>
using namespace std;

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

void dfs(int v,int pr) {
    p[v]=pr;
    for(int i=0;i<adj[v].size();i++) {
        int nt=adj[v][i];
        if (pr!=nt) {
            dfs(nt,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 t=n*3;
    printf("%d\n",t);
    for(int i=0;i<n;i++) {
        int now=i;
        int pr;
        int pr2;
        for(int j=0;j<t;j++) {
            if (j%2==0) {
                if (j/2==0) {
                    if (p[now]!=-1)
                        now=p[now];
                }
                if (j/2==1) {
                    pr2=now;
                    if (p[now]!=-1) {
                        now=p[now];
                    }
                }
                if (j/2==2) {
                    pr=now;
                    if (p[now]!=-1) {
                        now=p[now];
                    }
                }
                if (j/2==3) {
                    now=pr;
                }
                if (j/2==4) {
                    now=pr2;
                }
                if (j/2>=6) {
                    if (p[now]!=-1) {
                        now=p[now];
                    }
                }
            }
            printf("%d",now);
            if (j!=t-1) {
                printf(" ");
            }
        }
        printf("\n");
    }
    for(int i=0;i<n;i++) {
        int now=i;
        for(int j=0;j<t;j++) {
            if (j%2==0) {
                if (j/2==0) {
                    if (p[now]!=-1)
                        now=p[now];
                }
                if (j/2==4) {
                    if (p[now]!=-1) {
                        now=p[now];
                    }
                }
                if (j/2==5) {
                    if (p[now]!=-1) {
                        now=p[now];
                    }
                }
                if (j/2>=6) {
                    if (p[now]!=-1) {
                        now=p[now];
                    }
                }
            }
            printf("%d",now);
            if (j!=t-1) {
                printf(" ");
            }
        }
        printf("\n");
    }
}

Compilation message

Main.cpp: In function 'void dfs(int, int)':
Main.cpp:9:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    9 |     for(int i=0;i<adj[v].size();i++) {
      |                 ~^~~~~~~~~~~~~~
Main.cpp: In function 'int main()':
Main.cpp:19:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |     scanf("%d",&n);
      |     ~~~~~^~~~~~~~~
Main.cpp:25:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |         scanf("%d %d",&u,&v);
      |         ~~~~~^~~~~~~~~~~~~~~
Main.cpp:50:30: warning: 'now' may be used uninitialized in this function [-Wmaybe-uninitialized]
   50 |                     if (p[now]!=-1) {
      |                         ~~~~~^
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 344 KB Cannot move
2 Halted 0 ms 0 KB -