답안 #701412

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
701412 2023-02-21T08:02:52 Z Chal1shkan Papričice (COCI20_papricice) C++14
15 / 110
1000 ms 5032 KB
# include <bits/stdc++.h>

# define pb push_back
# define ff first
# define ss second
# define nl "\n"
# define sz(x) ((int)(x).size())
# define deb(x) cerr << #x  << " = " << x << endl; 

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const ll maxn = 2e5 + 25;
const ll inf = 1e18 + 0;
const ll mod = 1e9 + 7;
const ll dx[] = {-1, 1, 0, 0};
const ll dy[] = {0, 0, -1, 1};

using namespace std;

int n, cnt;
vector <int> g[maxn];
vector <pair <int, int> > qwe;
bool used[maxn];

void dfs (int v)
{
    cnt++;
    used[v] = 1;
    for (int to : g[v])
    {
        if (!used[to])
        {
            dfs(to);
        }
    }
}

void ma1n (/* SABR */)
{
    cin >> n;
    for (int i = 1, u, v; i < n; ++i)
    {
        cin >> u >> v;
        qwe.pb({u, v});
    }
    int ans = n;
    for (int i = 0; i < sz(qwe); ++i)
    {
        for (int j = i + 1; j < sz(qwe); ++j)
        {
            for (int i = 1; i <= n; ++i)
            {
                g[i].clear();
                used[i] = 0;
            }
            for (int k = 0; k < sz(qwe); ++k)
            {
                if (k == i || k == j) continue;
                int u = qwe[k].ff, v = qwe[k].ss;
                g[u].pb(v);
                g[v].pb(u);
            }
            vector <int> x;
            for (int i = 1; i <= n; ++i)
            {
                if (!used[i])
                {
                    cnt = 0;
                    dfs(i);
                    x.pb(cnt);
                }
            }
            sort(x.begin(), x.end());
            ans = min(ans, x.back() - x[0]);
        }
    }
    cout << ans;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
//  freopen("file.in", "r", stdin);
//  freopen("file.out", "w", stdout);
    int ttt = 1;
//  cin >> ttt;
    for (int test = 1; test <= ttt; ++test)
    {
//      cout << "Case " << test << ":" << ' ';
        ma1n();
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 82 ms 5016 KB Output is correct
2 Correct 76 ms 4948 KB Output is correct
3 Correct 91 ms 5012 KB Output is correct
4 Correct 86 ms 5020 KB Output is correct
5 Correct 85 ms 5008 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 82 ms 5016 KB Output is correct
2 Correct 76 ms 4948 KB Output is correct
3 Correct 91 ms 5012 KB Output is correct
4 Correct 86 ms 5020 KB Output is correct
5 Correct 85 ms 5008 KB Output is correct
6 Execution timed out 1074 ms 5032 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 82 ms 5016 KB Output is correct
2 Correct 76 ms 4948 KB Output is correct
3 Correct 91 ms 5012 KB Output is correct
4 Correct 86 ms 5020 KB Output is correct
5 Correct 85 ms 5008 KB Output is correct
6 Execution timed out 1074 ms 5032 KB Time limit exceeded
7 Halted 0 ms 0 KB -