Untitled

mail@pastecode.io avatar
unknown
c_cpp
2 years ago
1.9 kB
2
Indexable
Never
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(a) begin(a),end(a)
#define pb push_back
#define pii pair<int,int>
#define F first
#define S second
#define mp make_pair
const int mod=998244353;
const int inf=1e18;
const int MAXN=1000005;


vector<pii> edge[MAXN];
bool has_antivirus[MAXN],has_virus[MAXN],record_ans[MAXN];

void solve(){
    int n,m,p,q,t,T;
    cin >> n >> m >> p >> q >> t >> T;
    for(int i=0;i<m;i++){
        int a,b,w;
        cin >> a >> b >> w;
        edge[a].pb({b,w});
    }
    queue<pii> virus,antivirus;
    for(int i=0;i<p;i++){
        int x;
        cin >> x;
        virus.push({x,0});
    }
    for(int i=0;i<q;i++){
        int x;
        cin >> x;
        antivirus.push({x,t});
    }
    int ans=0;
    while((!virus.empty() && virus.front().S<=T) || (!antivirus.empty() && antivirus.front().S<=T)){
        if(antivirus.empty() || (!virus.empty() && virus.front().S<antivirus.front().S)){
            int cur=virus.front().F,curT=virus.front().S;
            virus.pop();
            has_virus[cur]=true;
            if(!has_antivirus[cur] && !record_ans[cur]){
                ans++;
                record_ans[cur]=true;
            }
            
            if(has_antivirus[cur]) continue;
            for(auto i:edge[cur]){
                if(!has_virus[i.F]) virus.push({i.F,curT+i.S}); 
            }
            
        }else{
            int cur=antivirus.front().F,curT=antivirus.front().S;
            antivirus.pop();
            has_antivirus[cur]=true;

            if(has_virus[cur]) continue;
            for(auto i:edge[cur]){
                if(!has_antivirus[i.F]) antivirus.push({i.F,curT+1}); 
            }
            
        }
        
    }
    cout << ans << '\n';
}


signed main(){
    cin.sync_with_stdio(0),cin.tie(0);
    int N=1;
    //cin >> N;
    for(int i=1;i<=N;i++){
        solve();
    }
}