From cfdf6c23db2eca20b2fca0f84a191b69f7e596e2 Mon Sep 17 00:00:00 2001 From: Muhammad Faishol Amirul Mukminin Date: Wed, 26 Sep 2018 17:28:20 +0700 Subject: [PATCH] Create L07-1.cpp --- L07-1.cpp | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 L07-1.cpp diff --git a/L07-1.cpp b/L07-1.cpp new file mode 100644 index 0000000..05c20a1 --- /dev/null +++ b/L07-1.cpp @@ -0,0 +1,79 @@ +#include +using namespace std; + +typedef long long ll; +typedef pair pl; + +#define PUB push_back +#define fi first +#define se second + +struct edge{ + int v; + ll d; +}; + +int N, M, Q; +ll dist[2][50005], dist_total = LLONG_MAX; +// dist[0] -> menyimpan distance dari titik 0 ke semua titik +// dist[1] -> menyimpan distance dari titik N-1 ke semua titik + +vector adjL[2][50005]; +// adjL[0] -> menyimpan adjacency list yang asli +// adjL[1] -> menyimpan adjacency list yang telah dibalik + +priority_queue pq; +// first -> nyimpen jarak +// second -> nyimpen pos + +void dijkstra(int source, int id){ + for(int i=0;i d_tmp + nxt.d){ + dist[id][nxt.v] = d_tmp + nxt.d; + pq.push({-dist[id][nxt.v], nxt.v}); + } + } + } +} + +int main(){ + ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); + + cin >> N >> M >> Q; + for(int i=0;i> u >> v >> d; + + adjL[0][u].PUB({v, d}); + adjL[1][v].PUB({u, d}); + } + + dijkstra(0, 0); + dijkstra(N-1, 1); + + dist_total = dist[0][N-1]; + + while(Q--){ + int u, v; + ll d; + + cin >> u >> v >> d; + + if(dist[0][u]+dist[1][v]+d < dist_total) cout << "Ya" << endl; + else cout << "Tidak" << endl; + } + + return 0; +}