답안 #1057774

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1057774 2024-08-14T05:53:50 Z 정희우(#11078) Infiltration (CCO24_day2problem1) C++17
0 / 25
1 ms 344 KB
#include<iostream>
#include<algorithm>
#include<vector>

using namespace std;
using lint = long long;
using vint = vector<int>;
using pii = pair<int,int>;

const int MAX_N=105;

int n;
vint edge[MAX_N];
int pa[MAX_N];

vector<pii> moves[2]={
{{3,1},{13,0},{57,1}},
{{3,0},{13,1},{20,0},{37,1}}};

int dep(int v,int p,int d)
{
    int mxd=d;
    pa[v]=p;
    for(auto v0 : edge[v])
        if(v0!=p)
            mxd=max(mxd,dep(v0,v,d+1));
    return mxd;
}

int main()
{
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    cin >> n;
    if(n!=100)return 1;
    for(int i=1;i<n;i++)
    {
        int u,v;
        cin >> u >> v;
        edge[u].push_back(v);
        edge[v].push_back(u);
    }
    /*dep(0,0,0);
    cout << 200 << '\n';
    for(int k=0;k<2;k++)
    {
        for(int i=0;i<n;i++)
        {
            int v=i;
            for(int j=0;j<100;j++)
            {
                if(k)cout << v << ' ';
                v=pa[v];
                cout << v << ' ';
                if(!k)cout << v << ' ';
            }
            cout << '\n';
        }
    }*/
    int root=0,d=dep(0,0,0);
    for(int i=0;i<n;i++)
    {
        int cd=dep(i,i,0);
        if(cd>=d)continue;
        root=i;d=cd;
    }
    dep(root,root,0);
    cout << 146 << '\n';
    for(int k=0;k<2;k++)
    {
        for(int i=0;i<n;i++)
        {
            int v=i;
            for(auto p : moves[k])
                for(int j=0;j<p.first;j++)
                {
                    if(k)cout << v << ' ';
                    if(p.second)v=pa[v];
                    if(p.second==2)v=root;
                    cout << v << ' ';
                    if(!k)cout << v << ' ';
                }
            cout << '\n';
        }
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 344 KB For some pair of nodes Ondrej and Edward do not meet each other
2 Halted 0 ms 0 KB -