Submission #930952

# Submission time Handle Problem Language Result Execution time Memory
930952 2024-02-20T23:06:25 Z idiotcomputer Factories (JOI14_factories) C++11
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long int 
#define pii pair<int,ll>
#define f first 
#define s second 

const int mxN = 5*1e5;
const ll llmax = (ll) 1e17;

vector<pii> adj[mxN];
vector<pii> ctree[mxN];

int ssize[mxN];
ll res[mxN];
bool vis[mxN];

void dfs(int node, int p){
    ssize[node] = 1;
    for (pii next : adj[node]){
        if (next.f == p || vis[next.f]){
            continue;
        }
        dfs(next.f,node);
        ssize[node] += ssize[next.f];
    }
}

void dfs2(int node, int p, int cent, ll cdepth){
    ctree[node].pb({cent,cdepth});
    for (pii next : adj[node]){
        if (next.f == p || vis[next.f]){
            continue;
        }
        dfs2(next.f,node,cent,cdepth+next.s);
    }
}

int gcentroid(int node, int p, int tot){
    for (pii next : adj[node]){
        if (next.f == p || vis[next.f]){
            continue;
        }
        if (ssize[next.f] > tot){
            return gcentroid(next.f,node,tot);
        }
    }
    return node;
}

void cdecomp(int node){
    dfs(node,-1);
    int centroid = gcentroid(node,-1,ssize[node]/2);
    dfs2(centroid,-1,centroid,0);
    vis[centroid] = 1;
    for (pii next : adj[centroid]){
        if (!vis[next.f]){
            cdecomp(next.f);
        }
    }
}

void upd(int node, bool w){
    for (pii next : ctree[node]){
        if (w){
            res[next.f] = min(res[next.f],next.s);
        } else {
            res[next.f] = llmax;
        }
    }
}

ll query(int node){
    ll tot = llmax;
    for (pii next : ctree[node]){
        tot = min(tot, next.s + res[next.f]);
    }
    return tot;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int n,q;
    cin >> n >> q;
    
    int a,b,d;
    for (int i =0; i < n-1; i++){
        cin >> a >> b >> d;
        adj[a].pb({b,d});
        adj[b].pb({a,d});
    }
   
    memset(vis,0,sizeof(vis));
    cdecomp(0);
    for (int i = 0; i < n; i++){
        res[i] = llmax;
    }

    int s,t;
    ll tot;
    vector<int> temp;
    for (int i =0; i < q; i++){
        cin >> s >> t;
        tot = llmax;
        temp.clear();
        for (int j = 0; j < s; j++){
            cin >> a;
            upd(a,true);
            temp.pb(a);
        }
        for (int j = 0; j < t; j++){
            cin >> a;
            tot = min(tot, query(a));
        }
        for (int j =0; j < s; j++){
            upd(temp[j],false);
        }
        cout << tot << '\n';
    }
    
    
    return 0;
}

Compilation message

/usr/bin/ld: /tmp/ccKTSLGl.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccb9Abel.o:factories.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/ccKTSLGl.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