답안 #1057997

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1057997 2024-08-14T07:54:12 Z 123(#11113) Infiltration (CCO24_day2problem1) C++17
0 / 25
1 ms 348 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 getp(int x) {
    return p[x]==-1?x:p[x];
}

int move0(int v,int x) {
    v=getp(v);
    for(int i=0;i<2;i++) {
        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*2-2;i++) {
        printf("%d ",v);
    }
    return v;
}

int move1(int v,int x) {
    printf("%d %d ",v,getp(v));
    v=getp(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) {
            v=getp(v);
        }
        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 t=190;
    printf("%d\n",t);
    for(int i=0;i<n;i++) {
        int now=i;
        now=move0(i,2);
        now=move0(now,5);
        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);
        now=move1(now,5);
        for(int j=0;j<100;j++) {
            printf("%d ",now);
        }
        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:64:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   64 |     scanf("%d",&n);
      |     ~~~~~^~~~~~~~~
Main.cpp:70:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   70 |         scanf("%d %d",&u,&v);
      |         ~~~~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB Invalid table value
2 Halted 0 ms 0 KB -