Submission #807081

# Submission time Handle Problem Language Result Execution time Memory
807081 2023-08-04T13:03:44 Z amine_aroua Crocodile's Underground City (IOI11_crocodile) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")
using namespace std;
#define int long long
#define vi vector<int>
#define vl vector<long long>
#define vii vector<pair<int,int>>
#define vll vector<pair<long long,long long>>
#define pb push_back
#define ll long long
#define ld long double
#define nl '\n'
#define boost ios::sync_with_stdio(false)
#define mp make_pair
#define se second
#define fi first
#define fore(i, y) for(int i = 0; i < y; i++)
#define forr(i,x,y) for(int i = x;i<=y;i++)
#define forn(i,y,x) for(int i = y; i >= x; i--)
#define all(v) v.begin(),v.end()
#define sz(v) v.size()
#define clr(v,k) memset(v,k,sizeof(v))
#define rall(v) v.rbegin() , v.rend()
#define pii pair<int,int>
#define pll pair<ll , ll>

const ll MOD = 1e9 + 7;
const ll INF = 1e18 + 1;
const int inf = 1e9 + 1;

ll gcd(ll a , ll b) {return b ? gcd(b , a % b) : a ;} // greatest common divisor (gcd)
ll lcm(ll a , ll b) {return a * (b / gcd(a , b));} // least common multiple (lcm)

// HERE IS THE SOLUTION
const int N = 100000;
vii adj[N];
vi dp(N , INF);
vector<bool> leaf(N , 0);
vi distEnd , distOne;
vi dijkstra(int n ,vi start)
{
    vi dist(n);
    priority_queue<pii> pq;
    for(auto x : start)
    {
        dist[x] = 0;
        pq.push({0 , x});
    }
    vector<bool> vis(n , 0);
    while(!pq.empty())
    {
        int cur = pq.top().se;
        pq.pop();
        if(vis[cur])
            continue;
        vis[cur] = 1;
        for(auto [u,c] : adj[cur])
        {
            if(dist[u] > dist[cur] + c)
            {
                dist[u] = dist[cur]+ c;
                pq.push({-dist[u] , u});
            }
        }
    }
    return dist;
}
int dfs(int x , int cur)
{
    if(dp[x] != INF)
        return dp[x];
    dp[x] = INF - 1;
    if(leaf[x])
        return cur;
    vector<vi> v;
    for(auto u : adj[x])
    {
        v.pb({distOne[u.fi] , distEnd[u.fi] + u.se , u.fi});
    }
    sort(all(v));
    forr(i , 1 , sz(v) - 1)
    {
        dp[x] = min(dp[x] , dfs(v[i][2] , cur + v[i][1] - distEnd[v[i][2]]));
    }
    return dp[x];
}
vi bfs(int n ,vi start)
{
    vi dist(n);
    queue<int> pq;
    for(auto x : start)
    {
        dist[x] = 0;
        pq.push(x);
    }
    vector<bool> vis(n , 0);
    while(!pq.empty())
    {
        int cur = pq.front();
        pq.pop();
        if(vis[cur])
            continue;
        vis[cur] = 1;
        for(auto [u,c] : adj[cur])
        {
            if(dist[u] > dist[cur] + 1)
            {
                dist[u] = dist[cur]+ 1;
                pq.push(u);
            }
        }
    }
    return dist;
}
int travel_plan(int n , int m , int* r[2] , int* l, int k , int* p)
{
    fore(i , m)
    {
        adj[r[i][0]].pb({r[i][1] , l[i]});
        adj[r[i][1]].pb({r[i][0] , l[i]});
    }
    vi v;
    fore(i  , k)
    {
        leaf[p[i]] = 1;
        v.pb(p[i]);
    }
    distEnd = dijkstra(n,v);
    distOne = bfs(n,v);
    return  dfs(0 , 0);
}
//signed main()
//{
//    cin.tie(0);
//    cout.tie(0);
//    boost;
//    int n , m;
//    vector<vi> r(m);
//    vi l(m);
//    int k;
//    vi p(k);
//    cin>>n>>m>>k;
//    fore(i  , k)
//        cin>>p[i];
//    fore(i , m)
//    {
//        int u , v , c;
//        cin>>u>>v>>c;
//        r[i] = {u , v};
//        l[i] = c;
//    }
//    cout<<travel_plan(n , m , r , l , k , p);
//}

Compilation message

crocodile.cpp: In function 'long long int dfs(long long int, long long int)':
crocodile.cpp:19:36: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::vector<long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   19 | #define forr(i,x,y) for(int i = x;i<=y;i++)
......
   82 |     forr(i , 1 , sz(v) - 1)
      |          ~~~~~~~~~~~~~~~~~          
crocodile.cpp:82:5: note: in expansion of macro 'forr'
   82 |     forr(i , 1 , sz(v) - 1)
      |     ^~~~
/usr/bin/ld: /tmp/ccIFbnGi.o: in function `main':
grader.cpp:(.text.startup+0x36): undefined reference to `travel_plan(int, int, int (*) [2], int*, int, int*)'
collect2: error: ld returned 1 exit status