ソースコード
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>
auto& in = std::cin;
auto& out = std::cout;
#define all_range(C) std::begin(C), std::end(C)
const double PI = 3.141592653589793238462643383279502884197169399375105820974944;
int32_t N,M,K;
#include <queue>
#include <vector>
#include <functional>
#include <utility>
#include <algorithm>
#include <iterator>
using COST_T = uint64_t;
constexpr uint32_t N_MAX = 100100;
constexpr COST_T INF = 100000100000;//std::numeric_limits<double>::infinity()
#if defined(_MSC_VER) && defined(_DEBUG)
//static_assert(false, "リリースでコンパイルしないと遅いよ!!");
#endif
struct edge {
uint32_t to;
COST_T cost;
edge() {}
edge(uint32_t to_, COST_T cost_)
:to(to_), cost(cost_) {}
};
std::vector<edge> graph[N_MAX];
//ダイクストラ
COST_T D[N_MAX];
void Dijkstra(uint32_t s)
{
using P = std::pair<COST_T, uint32_t>;//cost pos
std::priority_queue<P, std::vector<P>, std::greater<P>> que;
std::fill(std::begin(D), std::end(D), INF);
D[s] = 0;
que.emplace(0, s);
while (!que.empty())
{
auto p = que.top(); que.pop();
const auto& nowpos = p.second;
const auto& nowcost = p.first;
if (D[nowpos] < nowcost) { continue; }
//for (int32_t to = 0; to < N; ++to)
//{
// auto cost = nowcost + graph[nowpos][to];
// if (cost < D[to]) {
// D[to] = cost;
// que.emplace(D[to], to);
// }
//}
for (const auto& e : graph[nowpos])
{
auto cost = nowcost + e.cost;
if (cost < D[e.to]) {
D[e.to] = cost;
que.emplace(cost, e.to);
}
}
}
}
int main()
{
using std::endl;
in.sync_with_stdio(false);
out.sync_with_stdio(false);
in.tie(nullptr);
out.tie(nullptr);
in >> N>>M>>K;
for (int32_t i = 0; i < M; i++)
{
int32_t a, b, c;
in >> a >> b >> c;
graph[a].emplace_back(b, c);
graph[b].emplace_back(a, c);
}
const COST_T INF2 = 100000;
for (int32_t i = 0; i < K; i++)
{
int32_t a, c;
in >> a >> c;
graph[a].emplace_back(0, INF2 - c);
graph[0].emplace_back(a, INF2 - c);
}
Dijkstra(0);
int32_t res = 0;
for (size_t i = 1; i <= N; i++)
{
if (D[i] <= INF2) {
++res;
}
}
out << res << endl;
return 0;
}
#endif