Submission #60974630


Source Code Expand

# include <iostream>
# include <vector>
# include <algorithm>
using namespace std;

const int MAX=3e5+11;

int n;
vector<int> adj[MAX];
int sz[MAX];

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);

    cin>>n;
    for(int i=1;i<n;i++)
    {
        int u,v;
        cin>>u>>v;

        adj[u].push_back(v);
        adj[v].push_back(u);
        sz[u]++;
        sz[v]++;
    }

    int ans=0;
    for(int u=1;u<=n;u++)
    {
        vector<int> v;
        int cnt=sz[u];
        for(int x: adj[u]) v.push_back(sz[x]-1);

        sort(v.begin(),v.end());
        for(int i=0;i<cnt;i++)
        {
            int x=cnt-i;
            int y=v[i];
            ans=max(ans,1+x+x*y);
        }
    }

    cout<<n-ans<<"\n";

    return 0;
}

Submission Info

Submission Time
Task E - Snowflake Tree
User denislav
Language C++ 20 (Clang 16.0.6)
Score 450
Code Size 810 Byte
Status AC
Exec Time 109 ms
Memory 24872 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 450 / 450
Status
AC × 3
AC × 29
Set Name Test Cases
Sample 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt
All 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 02_handmade_01.txt, 02_handmade_02.txt, 02_handmade_03.txt, 02_handmade_04.txt, 02_handmade_05.txt, 02_handmade_06.txt
Case Name Status Exec Time Memory
00_sample_01.txt AC 2 ms 3636 KiB
00_sample_02.txt AC 2 ms 3512 KiB
00_sample_03.txt AC 2 ms 3432 KiB
01_random_01.txt AC 109 ms 21356 KiB
01_random_02.txt AC 50 ms 13720 KiB
01_random_03.txt AC 99 ms 21484 KiB
01_random_04.txt AC 35 ms 10936 KiB
01_random_05.txt AC 99 ms 21420 KiB
01_random_06.txt AC 10 ms 5416 KiB
01_random_07.txt AC 106 ms 21288 KiB
01_random_08.txt AC 44 ms 12768 KiB
01_random_09.txt AC 96 ms 21404 KiB
01_random_10.txt AC 77 ms 18488 KiB
01_random_11.txt AC 88 ms 21688 KiB
01_random_12.txt AC 76 ms 18576 KiB
01_random_13.txt AC 101 ms 22208 KiB
01_random_14.txt AC 88 ms 18320 KiB
01_random_15.txt AC 92 ms 21480 KiB
01_random_16.txt AC 66 ms 18536 KiB
01_random_17.txt AC 88 ms 22052 KiB
01_random_18.txt AC 98 ms 19648 KiB
01_random_19.txt AC 103 ms 21408 KiB
01_random_20.txt AC 69 ms 17120 KiB
02_handmade_01.txt AC 94 ms 24872 KiB
02_handmade_02.txt AC 86 ms 22772 KiB
02_handmade_03.txt AC 86 ms 24768 KiB
02_handmade_04.txt AC 74 ms 24832 KiB
02_handmade_05.txt AC 92 ms 21088 KiB
02_handmade_06.txt AC 103 ms 21112 KiB