Submission #1063249

# Submission time Handle Problem Language Result Execution time Memory
1063249 2024-08-17T15:47:49 Z vjudge1 Factories (JOI14_factories) C++17
0 / 100
7 ms 14680 KB
#include "factories.h"
#include <bits/stdc++.h>
#define pb push_back

using namespace std;

void dijkstra();

int inf = INT_MAX;
int n;
vector<vector<pair<int, int>>> adj(500005);
vector<bool> vis(500005, 0);
vector<int> dis(500005, inf);
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;

void Init(int N, int A[], int B[], int D[])
{
  n = N;
  for (int i = 0; i < N - 1; i++)
  {
    adj[A[i]].pb({B[i], D[i]});
    adj[B[i]].pb({A[i], D[i]});
  }
}

long long Query(int S, int X[], int T, int Y[])
{
  for (int i = 0; i < n; i++)
  {
    vis[i] = 0;
    dis[i] = inf;
  }
  for (int i = 0; i < T; i++)
  {
    vis[Y[i]] = 1;
    dis[Y[i]] = 0;
    pq.push({0, Y[i]});
  }

  dijkstra();

  int ans = inf;
  for (int i = 0; i < S; i++)
  {
    ans = min(ans, dis[X[i]]);
  }

  return ans;
}

void dijkstra()
{
  while (!pq.empty())
  {
    int a = pq.top().second;
    pq.pop();

    if (vis[a])
      continue;

    for (auto [b, w] : adj[a])
    {
      if (dis[b] > dis[a] + w)
      {
        dis[b] = dis[a] + w;
        pq.push({dis[b], b});
      }
    }
  }
}
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 14680 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 14172 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 14680 KB Output isn't correct
2 Halted 0 ms 0 KB -