답안 #124602

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
124602 2019-07-03T14:51:43 Z deinfreund 관광 (NOI14_sightseeing) C++14
0 / 25
2914 ms 262148 KB
#include <bits/stdc++.h>

using namespace std;

vector<vector<pair<int, int>> > conns;
vector<int> ind;
vector<bool> needed;
vector<int> res;

int remaining;

void dijkstra(int node, int maxcost, int cost){
  //  cerr << "@" << node << " for " << cost << " until " << maxcost << endl;
  if (needed[node]){
    remaining --;
    res[node] = cost;
  }
  for (;ind[node] < conns[node].size() && conns[node][ind[node]].first < maxcost; ind[node]++){
    dijkstra(conns[node][ind[node]].second, ind[node] < (conns[node].size() - 1) ? conns[node][ind[node] + 1].first : 1000000000, max(conns[node][ind[node]].first, cost));
  }
}

int main(){
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  
  int nodes, edges, targets;
  cin >> nodes >> edges >> targets;
  conns.resize(nodes);
  ind.resize(nodes);
  
  
  
  for (int i = 0; i < edges; i++){
    int a, b, c;
    cin >> a >> b>> c;
    a--; b--; c *= -1;
    conns[a].push_back({c,b});
    conns[b].push_back({c, a});
  }
  for (int i = 0 ; i < nodes; i++){
    sort(conns[i].begin(), conns[i].end());
  }

  res.resize(nodes);
  vector<int> trg(targets);
  needed.resize(nodes);
  remaining = targets;
  for (int i = 0; i < targets; i++){
    cin >> trg[i]; trg[i]--;
    needed[trg[i]] = 1;
  }
  dijkstra(0, 1000000000, -1000000000);
  for (int i = 0; i < targets; i++){
    cout << -res[trg[i]] << endl;
  }
}

Compilation message

sightseeing.cpp: In function 'void dijkstra(int, int, int)':
sightseeing.cpp:18:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (;ind[node] < conns[node].size() && conns[node][ind[node]].first < maxcost; ind[node]++){
sightseeing.cpp:19:55: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     dijkstra(conns[node][ind[node]].second, ind[node] < (conns[node].size() - 1) ? conns[node][ind[node] + 1].first : 1000000000, max(conns[node][ind[node]].first, cost));
# 결과 실행 시간 메모리 Grader output
1 Runtime error 285 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 249 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 290 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2914 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -