Submission #839693

#TimeUsernameProblemLanguageResultExecution timeMemory
839693AlfraganusRace (IOI11_race)C++17
Compilation error
0 ms0 KiB
#include "race.h"
#include "grader.cpp"
#include <bits/stdc++.h>
using namespace std;

struct node {
  int sum = 0, node = 0, nodes = 0;
};

int best_path(int n, int k, int h[][2], int l[])
{
    vector<vector<pair<int, int>>> graph(n);
    vector<int> cnt(n);
    for(int i = 0; i < n - 1; i ++){
        graph[h[i][0]].push_back({h[i][1], l[i]});
        graph[h[i][1]].push_back({h[i][0], l[i]});
        cnt[h[i][0]] ++;
        cnt[h[i][1]] ++;
    }
    int ans = 1e7;
    for(int i = 0; i < n; i ++){
      if(cnt[i] == 1){
        queue<node> q;
        vector<bool> used(n);
        vector<vector<int>> a(n);
        q.push({0, i, 0});
        used[i] = true;
        while (!q.empty())
        {
          node x = q.front();
          q.pop();
          while (x.sum >= k)
          {
            if (x.sum == k)
              ans = min(ans, x.nodes);
            int cur = x.node, y = x.nodes, j = 0, cur1 = x.node;
            while (y)
            {
              if ((y & 1))
                cur = a[cur][j];
              y /= 2;
              j++;
            }
            y = x.nodes - 1;
            j = 0;
            while (y)
            {
              if ((y & 1))
                cur1 = a[cur1][j];
              y /= 2;
              j++;
            }
            for (auto n : graph[cur])
            {
              if (n.first == cur1)
              {
                x.sum -= n.second;
                break;
              }
            }
            x.nodes--;
          }
          for (auto neighbour : graph[x.node])
          {
            if (!used[neighbour.first])
            {
              q.push({x.sum + neighbour.second, neighbour.first, x.nodes + 1});
              used[neighbour.first] = true;
              a[neighbour.first].push_back(x.node);
              for (int i = 1, y = 2; y <= x.nodes + 1; i++, y <<= 1)
              {
                a[neighbour.first].push_back(a[a[neighbour.first][i - 1]][i - 1]);
              }
            }
          }
        }
        a.clear();
        used.clear();
      }
    }
    if(ans == 1e7)
      return -1;
    else
      return ans;
}

Compilation message (stderr)

/usr/bin/ld: /tmp/ccZRMKiI.o: in function `read_input()':
race.cpp:(.text+0x240): multiple definition of `read_input()'; /tmp/ccVJhHiI.o:grader.cpp:(.text+0x0): first defined here
/usr/bin/ld: /tmp/ccZRMKiI.o: in function `main':
race.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccVJhHiI.o:grader.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status