結果

問題 No.2431 Viral Hotel
ユーザー fumofumofunifumofumofuni
提出日時 2023-08-18 22:40:06
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
AC  
実行時間 195 ms / 2,000 ms
コード長 2,514 bytes
コンパイル時間 2,289 ms
コンパイル使用メモリ 214,116 KB
実行使用メモリ 16,852 KB
最終ジャッジ日時 2024-11-28 08:43:36
合計ジャッジ時間 7,778 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 42
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
//#pragma GCC optimize("Ofast")
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=(n)-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[9]={0,1,-1,0,1,1,-1,-1,0};
const ll dx[9]={1,0,0,-1,1,-1,1,-1,0};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

int main(){
    ll n,k,m,P;cin >> n >> k >> m >> P;
    vvl g(n);
    rep(i,m){
        ll a,b;cin >> a >> b;a--;b--;
        g[a].emplace_back(b);
        g[b].emplace_back(a);
    }
    vl s(n);rep(i,n)cin >> s[i];
    vl state(n);//0なら何も持ってない、1なら感染、2なら免疫、3なら検疫
    priority_queue<tuple<ll,ll,ll>,vector<tuple<ll,ll,ll>>,greater<tuple<ll,ll,ll>>> event;
    //時刻、イベント=0なら、免疫獲得、1なら感染、2なら検疫、idx
    rep(i,k){
        ll a;cin >> a;a--;
        state[a]=1;
        event.push({P,0,a});
        event.push({s[a],1,a});
    }
   // ll time=-1;
    while(event.size()){
        auto [t,ev,id]=event.top();event.pop();
        /*if(time!=t){
            for(auto p:state)cout << p <<" ";cout << endl;
            time=t;
        }*/
        if(ev==0){
            if(state[id]!=3)state[id]=2;
        }
        else if(ev==1){
            if(state[id]==3)continue;
            for(auto p:g[id]){
                if(state[p]==0){
                    state[p]=1;
                    event.push({t+P,0,p});
                    event.push({t+s[p],1,p});
                }
                else if(state[p]==1){
                    event.push({t,2,p});
                }
            }
        }
        else {
            state[id]=3;
        }
        
    }
    ll ans=0;
    rep(i,n)if(state[i]==3)ans++;
    cout << ans << endl;
}



0