답안 #685533

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
685533 2023-01-24T13:32:56 Z stanislavpolyn Village (BOI20_village) C++17
6 / 100
700 ms 3572 KB
#include <bits/stdc++.h>

#define fr(i, a, b) for (int i = (a); i <= (b); ++i)
#define rf(i, a, b) for (int i = (a); i >= (b); --i)
#define fe(x, y) for (auto& x : y)

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define mt make_tuple

#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define pw(x) (1LL << (x))

using namespace std;

mt19937_64 rng(228);

#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template <typename T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define fbo find_by_order
#define ook order_of_key

template <typename T>
bool umn(T& a, T b) {
    return a > b ? a = b, 1 : 0;
}
template <typename T>
bool umx(T& a, T b) {
    return a < b ? a = b, 1 : 0;
}

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename T>
using ve = vector<T>;

const int N = 1e5 + 5;

int n;
ve<int> g[N];

int dist[1001][1001];
int start;

void dfs(int v, int p, int dep) {
    dist[start][v] = dep;
    fe (to, g[v]) {
        if (to == p) continue;
        dfs(to, v, dep + 1);
    }
}

int main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
    ios::sync_with_stdio(0);
    cin.tie(0);
#endif
    cin >> n;

    fr (i, 1, n - 1) {
        int a, b;
        cin >> a >> b;

        g[a].pb(b);
        g[b].pb(a);
    }

    if (n <= 1000) {
        for (start = 1; start <= n; start++) {
            dfs(start, 0, 0);
        }
    }

    {
        ll mx = -1e18;
        ve<int> mxP;
        ll mn = 1e18;
        ve<int> mnP;

        ve<int> p;
        fr (i, 1, n) p.pb(i);
        do {
            bool bad = 0;
            fr (i, 0, sz(p) - 1) {
                bad |= p[i] == i + 1;
            }
            if (!bad) {
                ll sum = 0;
                fr (i, 0, sz(p) - 1) {
                    sum += dist[i + 1][p[i]];
                }
                if (umx(mx, sum)) {
                    mxP = p;
                }
                if (umn(mn, sum)) {
                    mnP = p;
                }
            }
        } while (next_permutation(all(p)));

        cout << mn << " " << mx << "\n";
        fe (x, mnP) cout << x << " ";
        cout << "\n";

        fr (i, 0, sz(mnP) - 1) {
            assert(dist[i + 1][mnP[i]] <= 2);
        }

        fr (i, 1, n) cout << 1 << " ";
//        fe (x, mxP) cout << x << " ";
//        cout << "\n";
        cout << "\n";
    }

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Partially correct 1 ms 2644 KB Partially correct
2 Partially correct 2 ms 2700 KB Partially correct
3 Partially correct 1 ms 2644 KB Partially correct
4 Partially correct 1 ms 2644 KB Partially correct
5 Partially correct 2 ms 2644 KB Partially correct
6 Partially correct 2 ms 2644 KB Partially correct
7 Partially correct 1 ms 2644 KB Partially correct
8 Partially correct 2 ms 2644 KB Partially correct
9 Partially correct 8 ms 2644 KB Partially correct
10 Partially correct 70 ms 2696 KB Partially correct
11 Partially correct 67 ms 2692 KB Partially correct
12 Partially correct 60 ms 2644 KB Partially correct
13 Partially correct 58 ms 2644 KB Partially correct
14 Partially correct 63 ms 2708 KB Partially correct
15 Partially correct 60 ms 2644 KB Partially correct
16 Partially correct 63 ms 2700 KB Partially correct
17 Partially correct 66 ms 2644 KB Partially correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1089 ms 3572 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Partially correct 1 ms 2644 KB Partially correct
2 Partially correct 2 ms 2700 KB Partially correct
3 Partially correct 1 ms 2644 KB Partially correct
4 Partially correct 1 ms 2644 KB Partially correct
5 Partially correct 2 ms 2644 KB Partially correct
6 Partially correct 2 ms 2644 KB Partially correct
7 Partially correct 1 ms 2644 KB Partially correct
8 Partially correct 2 ms 2644 KB Partially correct
9 Partially correct 8 ms 2644 KB Partially correct
10 Partially correct 70 ms 2696 KB Partially correct
11 Partially correct 67 ms 2692 KB Partially correct
12 Partially correct 60 ms 2644 KB Partially correct
13 Partially correct 58 ms 2644 KB Partially correct
14 Partially correct 63 ms 2708 KB Partially correct
15 Partially correct 60 ms 2644 KB Partially correct
16 Partially correct 63 ms 2700 KB Partially correct
17 Partially correct 66 ms 2644 KB Partially correct
18 Execution timed out 1089 ms 3572 KB Time limit exceeded
19 Halted 0 ms 0 KB -