Submission #570143

# Submission time Handle Problem Language Result Execution time Memory
570143 2022-05-28T19:16:44 Z SSRS Birthday gift (IZhO18_treearray) C++14
0 / 100
1 ms 212 KB
#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000000;
int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, m;
  cin >> n >> m;
  vector<vector<pair<int, int>>> E(n);
  for (int i = 0; i < m; i++){
    int a, b, w;
    cin >> a >> b >> w;
    a--;
    b--;
    E[a].push_back(make_pair(w, b));
    E[b].push_back(make_pair(w, a));
  }
  int k;
  cin >> k;
  vector<int> g(k);
  for (int i = 0; i < k; i++){
    cin >> g[i];
    g[i]--;
  }
  vector<vector<int>> d(k, vector<int>(n, -1));
  for (int i = 0; i < k; i++){
    priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;
    pq.push(make_pair(0, g[i]));
    while (!pq.empty()){
      int c = pq.top().first;
      int v = pq.top().second;
      pq.pop();
      if (d[i][v] == -1){
        d[i][v] = c;
        for (auto P : E[v]){
          int w = P.second;
          if (d[i][w] == -1){
            pq.push(make_pair(c + P.first, w));
          }
        }
      }
    }
  }
  int Q;
  cin >> Q;
  for (int i = 0; i < Q; i++){
    int s, t;
    cin >> s >> t;
    s--;
    t--;
    int ans = INF;
    for (int j = 0; j < k; j++){
      ans = min(ans, d[j][s]);
      ans = min(ans, d[j][t]);
    }
    cout << ans << endl;
  }
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -