Submission #380433

# Submission time Handle Problem Language Result Execution time Memory
380433 2021-03-21T18:44:45 Z ruadhan Traffic (IOI10_traffic) C++14
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;

const ll INF = 2e12 + 2;
const int MAXN = 1e6 + 1;
ll congestion = 0;
// vector<int> adj[MAXN];
pair<int, vector<int>> adj[MAXN]; // population, adjacent cities
vector<int> population;
vector<bool> visited;

void dfs(int node)
{
    // cout << ", dfs on " << node << "\t";
    for (auto u : adj[node].second)
    {
        if (!visited[u])
        {
            // cout << ", processing " << u << " ";
            // congestion += population[u];
            congestion += adj[u].first;
            // cout << " it has weight " << adj[u].first << ", ";
            visited[u] = true;
            dfs(u);
        }
    }
    // cout << endl;
}

// int LocateCentre(int N, vector<int> P, vector<int> S, vector<int> D)
int LocateCentre(int N, int P[], int S[], int D[])
{
    ll ans = INF;
    // population = P;
    // population.insert(P, P + N);
    for (int i = 0; i < N - 1; i++)
    {
        adj[i].first = P[i];
        adj[S[i]].second.push_back(D[i]);
        adj[D[i]].second.push_back(S[i]);
    }
    adj[N - 1].first = P[N - 1];
    // for (int i = 0; i < N; i++)
    // {
    //     cout << adj[i].first << " ";
    // }

    // for (int i = 0; i < N; i++)
    // {
    //     cout << "i = " << i << ", ";
    //     for (auto u : adj[i].second)
    //         cout << u << " ";
    //     cout << endl;
    // }

    for (int i = 0; i < N; i++) // try city i
    {
        // cout << "i = " << i << ", ";
        visited.assign(N, false);
        visited[i] = true;
        ll currentWorst = 0;
        for (auto u : adj[i].second) // all outgoing edges have different congestion
        {
            congestion = adj[u].first;
            visited[u] = true;
            dfs(u);
            // cout << congestion << " ";
            currentWorst = max(currentWorst, congestion);
        }
        ans = min(ans, currentWorst);
        // cout << endl;
    }
    return ans;
}

int main()
{
    // int n = 5;
    // vector<int> p = {10, 10, 10, 20, 20};
    // vector<int> s = {0, 1, 2, 3}; // edges
    // vector<int> d = {2, 2, 3, 4};
    // cout << LocateCentre(n, p, s, d) << endl;
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    // vector<int> p(n), s(n - 1), d(n - 1);
    int p[n], s[n - 1], d[n - 1];
    for (auto &x : p)
        cin >> x;
    for (int i = 0; i < n - 1; i++)
        cin >> s[i] >> d[i];

    // cout << n << endl;
    // for (int i = 0; i < n; i++)
    //     cout << p[i] << " ";
    // cout << endl;
    // for (int i = 0; i < n - 1; i++)
    //     cout << s[i] << " " << d[i] << endl;
    cout << LocateCentre(n, p, s, d) << endl;
    return 0;
}

Compilation message

/tmp/cc5a73Ve.o: In function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'
/tmp/cchtBfBM.o:traffic.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status