Submission #489234

#TimeUsernameProblemLanguageResultExecution timeMemory
489234SlavicG꿈 (IOI13_dreaming)C++17
Compilation error
0 ms0 KiB
#include "dreaming.h"
#include "bits/stdc++.h"
using namespace std;
 
#define ll long long
 
#define       forn(i,n)              for(int i=0;i<n;i++)
#define          all(v)              v.begin(), v.end()
#define         rall(v)              v.rbegin(),v.rend()
 
#define            pb                push_back
#define          sz(a)               (int)a.size()

const int N = 1e5 + 10;
vector<pair<int,int>> adj[N];
    
vector<int> component;
int farthest;
bool vis[N];
int dist[N];
bool pushed[N];
vector<int> bfs(int u)
{
    dist[u] = 0;
    pushed[u] = true;
    queue<int> q;
    q.push(u);
    int mx = 0;
    while(!q.empty())
    {
        int i = q.front();
        vis[i] = true;
        component.pb(i);
        q.pop();
        for(auto x : adj[i])
        {
            if(!pushed[x.first])
            {
                dist[x.first] = dist[i] + x.second;
                q.push(x.first);
                pushed[x.first] = true;
                if(mx < dist[x.first]){
                    mx = dist[x.first];
                    farthest = x.first;
                }
            }
        }
    }
    return dist;
}

int travelTime(int n, int m, int l, int a[], int b[], int t[]){
    for(int i = 0;i < n; ++i){
        adj[i].clear();
        vis[i] = false;
    }
    for(int i = 0;i < m; ++i){
        adj[a[i]].pb({b[i], t[i]});
        adj[b[i]].pb({a[i], t[i]});
    }
    
    vector<pair<int,int>> v;
    for(int i = 0;i < n; ++i)
    {
        if(vis[i])continue;
        farthest = i;
        for(auto x: component)dist[i] = 0, pushed[x]=false;
        component.clear();  
        bfs(i);
        for(auto x: component)dist[i] = 0, pushed[x]=false;
        component.clear();  
        vector<int> A = bfs(farthest);
        for(auto x: component)dist[i] = 0, pushed[x]=false;
        component.clear();  
        vector<int> B = bfs(farthest);

        
        int ans = farthest, mx = max(B[ans], A[ans]);
        
        for(auto x: component){
            if(max(B[x], A[x]) < mx){
                mx = max(B[x], A[x]);
                ans = x;
            }
        }
        for(auto x: component)dist[i] = 0, pushed[x]=false;
        
        v.pb({mx, ans});
    }

    sort(rall(v));
    
    for(int i = 1;i < sz(v); ++i){
        adj[v[i].second].pb({v[0].second, l});
        adj[v[0].second].pb({v[i].second, l});
    }
    

    farthest = 0;
    bfs(0);
    component.clear();  
    vector<int> A = bfs(farthest);
    component.clear();  
    vector<int> B = bfs(farthest);
    component.clear();  
    int ans = 0;
    for(int i = 0;i < n; ++i){
        ans = max({ans, A[i], B[i]});
    }
    return ans;
}
/*
void solve()
{ 
    int n, m, l;
    cin >> n >> m >> l;
    int a[m], b[m], t[m];
    forn(i, m)cin >> a[i] >> b[i] >> t[i];

    cout << travelTime(n, m, l, a, b, t);
}   
 
int32_t main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t = 1;
    //cin >> t;
    while(t--)
    {
        solve();
    }
}
*/

Compilation message (stderr)

dreaming.cpp: In function 'std::vector<int> bfs(int)':
dreaming.cpp:49:12: error: could not convert 'dist' from 'int [100010]' to 'std::vector<int>'
   49 |     return dist;
      |            ^~~~
      |            |
      |            int [100010]