Submission #1001697

# Submission time Handle Problem Language Result Execution time Memory
1001697 2024-06-19T07:04:06 Z nomuluun Race (IOI11_race) C++14
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;
int k, mn = INT_MAX;
vector<vector<int>> dp(200001, vector<int>(101, INT_MAX)); // sum I and ends at node v is the minimum of the paths
vector<pair<int, int>> adj[200001];                        // save edges
vector<vector<pair<int, int>>> path; 
bool vis[200005]={0};
vector<pair<int,int>>v[200005];
ll mi=INT_MAX;                      // keep the best paths of each weights
void DFS(int q, int dis, int hi, int ka){
    int m=v[q].size();
    if(dis==ka){
        if(hi<mi)mi=hi;
    }
    for(int i=0; i<m; i++){
        int k=v[q][i].first;
        ll cost=v[q][i].second;
        if(!vis[k]){
            vis[k]=1;
            DFS(k,dis+cost,hi+1,ka);
        }
    }
}
void dfs(int v, int p)
{
  dp[v][0] = 0;
  for (auto [i, w] : adj[v])
    if (i != p)
      dfs(i, v);
  path.assign(k + 1, {});
  for (auto [i, w] : adj[v])
  {
    if (i == p)
      continue;
    for (int j = w; j <= k; j++)
    {
      if (dp[i][j - w] == INT_MAX)
        continue;
      if (path[j].size() < 2)
        path[j].push_back({dp[i][j - w] + 1, i}); // keep best two paths
      else if (dp[i][j - w] + 1 < path[j][1].first)
        path[j][1] = {dp[i][j - w] + 1, i}; // keep current path
      if (path[j].size() == 2 && path[j][0].first > path[j][1].first)
        swap(path[j][0], path[j][1]); // swap shortest path
      dp[v][j] = min(dp[v][j], dp[i][j - w] + 1);
    }
  }
  if (!path[k].empty())
    mn = min(mn, path[k][0].first); // if there is any path which is exactly K
  for (int i = 1; i < k; i++)
  {
    if (path[i].empty() || path[k - i].empty())
      continue;
    if (path[i][0].second != path[k - i][0].second)
      mn = min(mn, path[i][0].first + path[k - i][0].first); // compare 2 best paths
    else if (1 < path[k - i].size())
      mn = min(mn, path[i][0].first + path[k - i][1].first); // compare 2 best paths if there is path over 1.
  }
}
int best_path(int N, int K, int H[][2], int L[])
{
  
  if(K<=100){
  	k = K;
  	for (int i = 0; i < N - 1; i++)
  {
    adj[H[i][0]].push_back({H[i][1], L[i]});
    adj[H[i][1]].push_back({H[i][0], L[i]});
  }
  dfs(0, -1);
  if (mn == INT_MAX)
    return -1;
  else
    return mn;
  }
  else{
  	for(int i=0; i<N-1; i++){
        v[H[i][0]].push_back({H[i][1], L[i]});
        v[H[i][1]].push_back({H[i][0], L[i]});
    }
    for(int i=0; i<=N-1; i++){
        for(int i=0; i<N; i++){
            vis[i]=0;
        }
        vis[i]=1;
        DFS(i,0,0,K); //ehleh oroi distance highway
    }
    if(mi==INT_MAX)return -1;
    else return mi;
  }
  
}
#define MAX_N 500000

static int N, K;
static int H[MAX_N][2];
static int L[MAX_N];
static int solution;

//inline void my_assert(int e)
//{
//  if (!e)
//    abort();
//}
//
//void read_input()
//{
//  int i;
//  my_assert(2 == scanf("%d %d", &N, &K));
//  for (i = 0; i < N - 1; i++)
//    my_assert(3 == scanf("%d %d %d", &H[i][0], &H[i][1], &L[i]));
//  my_assert(1 == scanf("%d", &solution));
//}
//
//int main()
//{
//  int ans;
//  read_input();
//  ans = best_path(N, K, H, L);
//  if (ans == solution)
//    printf("Correct.\n");
//  else
//    printf("Incorrect. Returned %d, Expected %d.\n", ans, solution);
//
//  return 0;
//}

Compilation message

race.cpp:9:1: error: 'll' does not name a type
    9 | ll mi=INT_MAX;                      // keep the best paths of each weights
      | ^~
race.cpp: In function 'void DFS(int, int, int, int)':
race.cpp:13:15: error: 'mi' was not declared in this scope; did you mean 'm'?
   13 |         if(hi<mi)mi=hi;
      |               ^~
      |               m
race.cpp:17:9: error: 'll' was not declared in this scope
   17 |         ll cost=v[q][i].second;
      |         ^~
race.cpp:20:23: error: 'cost' was not declared in this scope; did you mean 'cosl'?
   20 |             DFS(k,dis+cost,hi+1,ka);
      |                       ^~~~
      |                       cosl
race.cpp: In function 'void dfs(int, int)':
race.cpp:27:13: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   27 |   for (auto [i, w] : adj[v])
      |             ^
race.cpp:31:13: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   31 |   for (auto [i, w] : adj[v])
      |             ^
race.cpp: In function 'int best_path(int, int, int (*)[2], int*)':
race.cpp:88:8: error: 'mi' was not declared in this scope; did you mean 'mn'?
   88 |     if(mi==INT_MAX)return -1;
      |        ^~
      |        mn
race.cpp: At global scope:
race.cpp:98:12: warning: 'solution' defined but not used [-Wunused-variable]
   98 | static int solution;
      |            ^~~~~~~~
race.cpp:97:12: warning: 'L' defined but not used [-Wunused-variable]
   97 | static int L[MAX_N];
      |            ^
race.cpp:96:12: warning: 'H' defined but not used [-Wunused-variable]
   96 | static int H[MAX_N][2];
      |            ^
race.cpp:95:15: warning: 'K' defined but not used [-Wunused-variable]
   95 | static int N, K;
      |               ^
race.cpp:95:12: warning: 'N' defined but not used [-Wunused-variable]
   95 | static int N, K;
      |            ^