From 834a103aa28275211f2ed04ccdd6ca82ce933a69 Mon Sep 17 00:00:00 2001 From: oncsr Date: Thu, 9 Oct 2025 21:43:01 +0900 Subject: [PATCH] =?UTF-8?q?[20251009]=20BOJ=20/=20G1=20/=20Doomsday=20/=20?= =?UTF-8?q?=EA=B6=8C=ED=98=81=EC=A4=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- khj20006/202510/09 BOJ G1 Doomsday.md | 45 +++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 khj20006/202510/09 BOJ G1 Doomsday.md diff --git a/khj20006/202510/09 BOJ G1 Doomsday.md b/khj20006/202510/09 BOJ G1 Doomsday.md new file mode 100644 index 00000000..96c65875 --- /dev/null +++ b/khj20006/202510/09 BOJ G1 Doomsday.md @@ -0,0 +1,45 @@ +```cpp +#include +using namespace std; + +int N, M, W, F, t[50000]{}, d[50000][4]{}; +vector>> v(50000); + +int main(){ + cin.tie(0)->sync_with_stdio(0); + + cin>>N>>M>>W>>F; + for(int i=1,a;i<=W;i++) { + cin>>a; + t[a] |= 1; + } + for(int i=1,a;i<=F;i++) { + cin>>a; + t[a] |= 2; + } + + for(int a,b,c;M--;) { + cin>>a>>b>>c; + v[a].emplace_back(b,c); + v[b].emplace_back(a,c); + } + + for(int i=0;i, vector>, greater<>> q; + q.emplace(0,0,t[0]); + while(!q.empty()) { + auto [s, n, k] = q.top(); q.pop(); + if(s > d[n][k]) continue; + for(auto [i,c]:v[n]) { + int r = k | t[i]; + if(d[i][r] > s+c) { + d[i][r] = s+c; + q.emplace(s+c,i,r); + } + } + } + cout<