Submission #905942

# Submission time Handle Problem Language Result Execution time Memory
905942 2024-01-13T07:34:34 Z Amirreza_Fakhri Factories (JOI14_factories) C++17
Compilation error
0 ms 0 KB
// In the name of the God 
#include <bits/stdc++.h>
#define ll long long
#define int long long
#define pb push_back
#define F first
#define S second
#define mp make_pair
#define pii pair <int, int>
#define smin(x, y) (x) = min((x), (y))
#define smax(x, y) (x) = max((x), (y))
#define all(x) (x).begin(), (x).end()
using namespace std;

const int inf = (1e9+7)*(1e9+7);
const int mod = 998244353;
const int maxn = 5e5+5;

int n, sz[maxn], mn[maxn];
bool mark[maxn];
vector <pii> adj[maxn], c[maxn];

void dfs1(int v, int p) {
    sz[v] = 1;
    for (pii e : adj[v]) {
        int u = e.F;
        if (!mark[u] and u != p) {
            dfs1(u, v); sz[v] += sz[u];
        }
    }
}

int dfs2(int v, int s, int p) {
    for (pii e : adj[v]) {
        int u = e.F;
        if (!mark[u] and u != p and sz[u] > s/2) return dfs2(u, s, v);
    }
    return v;
}

void dfs3(int v, int h, int p, int b) {
    c[v].pb(mp(b, h));
    for (pii e : adj[v]) {
        int u = e.F;
        if (!mark[u] and u != p) dfs3(u, h+e.S, v, b);
    }
}

void cd(int v) {
    dfs1(v, v);
    v = dfs2(v, sz[v], v);
    dfs3(v, 0, v, v);
    mark[v] = 1;
    for (pii e : adj[v]) {
        int u = e.F;
        if (!mark[u]) cd(u);
    }
}

void Init(int N, int A[], int B[], int D[]) {
    n = N;
    for (int i = 0; i < n-1; i++) {
        adj[A[i]].pb(mp(B[i], D[i]));
        adj[B[i]].pb(mp(A[i], D[i]));
    }
    cd(0);
    fill(mn, mn+n, inf);
}

long long Query(int S, int X[], int T, int Y[]) {
    int ans = inf;
    for (int i = 0; i < S; i++) {
        int v = X[i];
        for (pii p : c[v]) smin(mn[p.F], p.S);
    }
    for (int i = 0; i < T; i++) {
        int v = Y[i];
        for (pii p : c[v]) smin(ans, mn[p.F]+p.S);
    }
    for (int i = 0; i < S; i++) {
        int v = X[i];
        for (pii p : c[v]) mn[p.F] = inf;
    }
    return ans;
}

// int32_t main() {
//     ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//     cin >> n >> q;
//     for (int i = 0; i < n-1; i++) {
//         int v, u, w; cin >> v >> u >> w;
//         adj[v].pb(mp(u, w));
//         adj[u].pb(mp(v, w));
//     }
//     cd(0);
//     fill(mn, mn+n, inf);
//     while (q--) {
//         int s, t, ans = inf; cin >> s >> t;
//         while (s--) {
//             int v; cin >> v;
//             for (pii p : c[v]) smin(mn[p.F], p.S);
//             vec.pb(v);
//         }
//         while (t--) {
//             int v; cin >> v;
//             for (pii p : c[v]) smin(ans, mn[p.F]+p.S);
//         }
//         for (int v : vec) {
//             for (pii p : c[v]) mn[p.F] = inf;
//         }
//         vec.clear();
//         cout << ans << '\n';
//     }
//     return 0;
// }

Compilation message

/usr/bin/ld: /tmp/cc4Yx6R1.o: in function `main':
grader.cpp:(.text.startup+0x37d): undefined reference to `Init(int, int*, int*, int*)'
/usr/bin/ld: grader.cpp:(.text.startup+0x412): undefined reference to `Query(int, int*, int, int*)'
collect2: error: ld returned 1 exit status