結果

提出番号 2057
提出者 satanic0258
言語 C++
提出日時 2018-08-04 15:07:19
問題名 (73)観光計画
結果 AC
点数 100%

テストケース

テストケース 結果 得点 実行時間 メモリ使用量
1 AC 100% 51ms 43840KB
2 AC 100% 64ms 50512KB
3 AC 100% 31ms 27424KB
4 AC 100% 77ms 64672KB
5 AC 100% 40ms 38800KB
6 AC 100% 70ms 58080KB
7 AC 100% 82ms 63696KB
8 AC 100% 79ms 64240KB
9 AC 100% 34ms 35328KB
10 AC 100% 105ms 79440KB
11 AC 100% 48ms 38800KB
12 AC 100% 17ms 20144KB
13 AC 100% 45ms 38688KB
14 AC 100% 90ms 69936KB
15 AC 100% 74ms 55760KB
16 AC 100% 61ms 55584KB
17 AC 100% 84ms 70624KB
18 AC 100% 65ms 51072KB
19 AC 100% 18ms 24176KB
20 AC 100% 47ms 41184KB
21 AC 100% 23ms 27536KB
22 AC 100% 42ms 35328KB
23 AC 100% 47ms 37360KB
24 AC 100% 120ms 86560KB
25 AC 100% 93ms 68656KB
26 AC 100% 93ms 73040KB
27 AC 100% 28ms 23840KB
28 AC 100% 24ms 23312KB
29 AC 100% 57ms 48688KB
30 AC 100% 44ms 42336KB
31 AC 100% 95ms 80752KB
32 AC 100% 52ms 51248KB
33 AC 100% 15ms 15584KB
34 AC 100% 83ms 67168KB
35 AC 100% 13ms 15552KB
36 AC 100% 73ms 61840KB
37 AC 100% 40ms 33712KB
38 AC 100% 10ms 12032KB
39 AC 100% 112ms 80064KB
40 AC 100% 14ms 18032KB
41 AC 100% 94ms 73008KB
42 AC 100% 25ms 25872KB
43 AC 100% 102ms 83392KB
44 AC 100% 61ms 49344KB
45 AC 100% 68ms 55392KB
46 AC 100% 61ms 56592KB
47 AC 100% 95ms 74896KB
48 AC 100% 99ms 75792KB
49 AC 100% 54ms 48032KB
50 AC 100% 84ms 62944KB
51 AC 100% 23ms 22256KB
52 AC 100% 53ms 42784KB
53 AC 100% 31ms 28208KB
54 AC 100% 67ms 58560KB
55 AC 100% 21ms 21424KB
56 AC 100% 61ms 47792KB
57 AC 100% 34ms 37088KB
58 AC 100% 38ms 36800KB
59 AC 100% 24ms 27648KB
60 AC 100% 31ms 26480KB
61 AC 100% 38ms 34560KB
62 AC 100% 78ms 64960KB
63 AC 100% 74ms 57888KB
64 AC 100% 91ms 68400KB
65 AC 100% 86ms 61984KB
66 AC 100% 3ms 9584KB
67 AC 100% 52ms 44384KB
68 AC 100% 56ms 46608KB
69 AC 100% 129ms 95776KB
70 AC 100% 62ms 52576KB

ソースコード

// need
#include <iostream>
#include <algorithm>

// data structure
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <complex>
//#include <deque>
#include <valarray>

// stream
//#include <istream>
//#include <sstream>
//#include <ostream>
#include <fstream>

// etc
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <chrono>
#include <random>
#include <numeric>

// input
#define INIT std::ios::sync_with_stdio(false);std::cin.tie(0);
#define VAR(type, ...)type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T& t) { std::cin >> t; }
template<typename First, typename...Rest>void MACRO_VAR_Scan(First& first, Rest&...rest) { std::cin >> first; MACRO_VAR_Scan(rest...); }
#define VEC_ROW(type, n, ...)std::vector<type> __VA_ARGS__;MACRO_VEC_ROW_Init(n, __VA_ARGS__); for(int i=0; i<n; ++i){MACRO_VEC_ROW_Scan(i, __VA_ARGS__);}
template<typename T> void MACRO_VEC_ROW_Init(int n, T& t) { t.resize(n); }
template<typename First, typename...Rest>void MACRO_VEC_ROW_Init(int n, First& first, Rest&...rest) { first.resize(n); MACRO_VEC_ROW_Init(n, rest...); }
template<typename T> void MACRO_VEC_ROW_Scan(int p, T& t) { std::cin >> t[p]; }
template<typename First, typename...Rest>void MACRO_VEC_ROW_Scan(int p, First& first, Rest&...rest) { std::cin >> first[p]; MACRO_VEC_ROW_Scan(p, rest...); }
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define MAT(type, c, m, n) std::vector<std::vector<type>> c(m, std::vector<type>(n));for(auto& r:c)for(auto& i:r)std::cin>>i;

// output
#define OUT(d) std::cout<<(d);
#define FOUT(n, d) std::cout<<std::fixed<<std::setprecision(n)<<(d);
#define SOUT(n, c, d) std::cout<<std::setw(n)<<std::setfill(c)<<(d);
#define SP std::cout<<" ";
#define TAB std::cout<<"\t";
#define BR std::cout<<"\n";
#define SPBR(i, n) std::cout<<(i + 1 == n ? '\n' : ' ');
#define ENDL std::cout<<std::endl;
#define FLUSH std::cout<<std::flush;
#define SHOW(d) {std::cerr << #d << "\t:" << (d) << "\n";}
#define SHOWVECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";}
#define SHOWVECTOR2(v) {std::cerr << #v << "\t:\n";for(const auto& xxx : v){for(const auto& yyy : xxx){std::cerr << yyy << " ";}std::cerr << "\n";}}
#define SHOWQUEUE(a) {auto tmp(a);std::cerr << #a << "\t:";while(!tmp.empty()){std::cerr << tmp.front() << " ";tmp.pop();}std::cerr << "\n";}

// utility
#define ALL(a) (a).begin(),(a).end()
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RFOR(i, a, b) for(int i=(b)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define FORLL(i, a, b) for(ll i=ll(a);i<ll(b);++i)
#define RFORLL(i, a, b) for(ll i=ll(b)-1;i>=ll(a);--i)
#define REPLL(i, n) for(ll i=0;i<ll(n);++i)
#define RREPLL(i, n) for(ll i=ll(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
template<typename T> inline T CHMAX(T& a, const T b) { return a = (a < b) ? b : a; }
template<typename T> inline T CHMIN(T& a, const T b) { return a = (a > b) ? b : a; }
#define EXCEPTION(msg) throw std::string("Exception : " msg " [ in ") + __func__ + " : " + std::to_string(__LINE__) + " lines ]"
#define TRY(cond, msg) try {if (cond) EXCEPTION(msg);}catch (std::string s) {std::cerr << s << std::endl;}
void CHECKTIME(std::function<void()> f) { auto start = std::chrono::system_clock::now(); f(); auto end = std::chrono::system_clock::now(); auto res = std::chrono::duration_cast<std::chrono::nanoseconds>((end - start)).count(); std::cerr << "[Time:" << res << "ns  (" << res / (1.0e9) << "s)]\n"; }

// test
template<class T> std::vector<std::vector<T>> VV(int n, int m, T init = T()) {
	return std::vector<std::vector<T>>(n, std::vector<T>(m, init));
}
template<typename S, typename T>
std::ostream& operator<<(std::ostream& os, std::pair<S, T> p) {
	os << "(" << p.first << ", " << p.second << ")"; return os;
}

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using PAIR = std::pair<int, int>;
using PAIRLL = std::pair<ll, ll>;
constexpr int INFINT = 1 << 30;                          // 1.07x10^ 9
constexpr int INFINT_LIM = (1LL << 31) - 1;              // 2.15x10^ 9
constexpr ll INFLL = 1LL << 60;                          // 1.15x10^18
constexpr ll INFLL_LIM = (1LL << 62) - 1 + (1LL << 62);  // 9.22x10^18
constexpr double EPS = 1e-9;
constexpr int MOD = 1000000007;
constexpr double PI = 3.141592653589793238462643383279;

template<class T, size_t N> void FILL(T(&a)[N], const T& val) { for (auto& x : a) x = val; }
template<class ARY, size_t N, size_t M, class T> void FILL(ARY(&a)[N][M], const T& val) { for (auto& b : a) FILL(b, val); }
template<class T> void FILL(std::vector<T>& a, const T& val) { for (auto& x : a) x = val; }
template<class ARY, class T> void FILL(std::vector<std::vector<ARY>>& a, const T& val) { for (auto& b : a) FILL(b, val); }

// ------------>8------------------------------------->8------------



signed main() {
	INIT;

	VAR(int, n, m, k);
	VEC_ROW(int, m, a, b, c);
	VEC_ROW(int, k, h, d);

	struct Edge {
		int to, cost;
		Edge() {}
		Edge(int to, int cost) : to(to), cost(cost) {}
		bool operator<(const Edge& r) const {
			return cost < r.cost;
		}
	};
	std::vector<std::vector<Edge>> g(n + 1);
	// 辺の追加
	REP(i, m) {
		--a[i]; --b[i];
		g[a[i]].emplace_back(b[i], c[i]);
		g[b[i]].emplace_back(a[i], c[i]);
	}

	int mad = 0;
	REP(i, k) CHMAX(mad, d[i]);
	REP(i, k) {
		--h[i];
		g[n].emplace_back(h[i], mad - d[i]);
	}

	//
	std::vector<int> dist(n + 1);
	std::function<void(int)> Dijkstra = [&](int s) {
		using P = std::pair<int, int>;
		std::priority_queue<P, std::vector<P>, std::greater<P>> pq;
		std::fill(dist.begin(), dist.end(), INFLL);
		dist[s] = 0;
		pq.push(P(0, s));
		while (!pq.empty()) {
			P p = pq.top(); pq.pop();
			int v = p.second;
			if (dist[v] < p.first) continue;
			for (int i = 0; i < g[v].size(); ++i) {
				Edge e = g[v][i];
				if (dist[e.to] > dist[v] + e.cost) {
					dist[e.to] = dist[v] + e.cost;
					pq.push(P(dist[e.to], e.to));
				}
			}
		}
	};
	Dijkstra(n);

	int ans = 0;
	REP(i, n) {
		if (dist[i] <= mad) ++ans;
	}
	OUT(ans)BR;
	return 0;
}