Submission #807082

# Submission time Handle Problem Language Result Execution time Memory
807082 2023-08-04T13:05:07 Z amine_aroua Crocodile's Underground City (IOI11_crocodile) C++17
0 / 100
2 ms 3028 KB
#include <bits/stdc++.h>
//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")
using namespace std;
#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:37:11: warning: overflow in conversion from 'long long int' to 'std::vector<int>::value_type' {aka 'int'} changes value from '1000000000000000000' to '-1486618624' [-Woverflow]
   37 | vi dp(N , INF);
      |           ^~~
crocodile.cpp: In function 'int dfs(int, int)':
crocodile.cpp:72:17: warning: overflow in conversion from 'long long int' to '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} changes value from '999999999999999999' to '-1486618625' [-Woverflow]
   72 |     dp[x] = INF - 1;
      |             ~~~~^~~
crocodile.cpp:18:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 | #define forr(i,x,y) for(int i = x;i<=y;i++)
......
   81 |     forr(i , 1 , sz(v) - 1)
      |          ~~~~~~~~~~~~~~~~~          
crocodile.cpp:81:5: note: in expansion of macro 'forr'
   81 |     forr(i , 1 , sz(v) - 1)
      |     ^~~~
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 3028 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 3028 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 3028 KB Output isn't correct
2 Halted 0 ms 0 KB -