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<