제출 #526258

#제출 시각아이디문제언어결과실행 시간메모리
526258alirezasamimi100File Paths (BOI15_fil)C++17
0 / 100
1103 ms115012 KiB
/*#pragma GCC optimize("Ofast,unroll-loops") #pragma comment(linker, "/stack:200000000") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma,tune=native")*/ /*#pragma GCC optimize("O2") #pragma GCC optimize("unroll-loops") #pragma GCC target("avx,avx2,sse,sse2,fma")*/ #include <bits/stdc++.h> using namespace std; using ll=long long int; using ld=long double; using pll=pair<ll,ll>; using pii=pair<int,int>; using point=complex<double>; #define F first #define S second //#define X real() //#define Y imag() #define pb push_back #define mp make_pair #define lc v<<1 #define rc v<<1|1 #define fast_io ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr); #define kill(x) cout << x << '\n';exit(0) #define killshayan kill("done!") #define killmashtali kill("Hello, World!") const int N=3e3+10,LN=19,M=1e6+10,SQ=300,BS=737,inf=1e9,NSQ=N/SQ+1; const ll INF=1e18; const double pi=acos(-1); const ld ep=1e-7; const int MH=1000696969,MD=998244353,MOD=1000000007; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; #define ordered_set tree<pii, null_type,greater<pii>, rb_tree_tag,tree_order_statistics_node_update> ll pow(ll x, ll y, ll mod){ ll ans=1; while (y != 0) { if (y & 1) ans = ans * x % mod; y >>= 1; x = x * x % mod; } return ans; } int n,m,k,s,cnt[M],ans[N],h[N*2],p[N*2],cn[M]; vector<pii> adj[N*2]; vector<int> d[M]; void predfs(int v){ if(v<=n && h[v]+s<=k) cnt[h[v]+s]++; for(auto [u,w] : adj[v]){ h[u]=h[v]+w; p[u]=v; predfs(u); } } void sfd(int v, int c, int t){ if(h[v]-c+s<=k) cn[h[v]-c+s]+=t; for(auto [u,w] : adj[v]){ sfd(u,c,t); } } void dfs(int v){ if(v>n){ int x=p[v]; while(~x){ if(k-(h[v]-h[x])>=0 && cnt[k-(h[v]-h[x])]) ans[v-n]=1; x=p[x]; } x=k-h[v]; if(x==0) ans[v-n]=1; if(x>0){ for(int i : d[x]) if(cn[i]) ans[v-n]=1; } return; } sfd(v,h[v],1); for(auto [u,w] : adj[v]){ dfs(u); } sfd(v,h[v],-1); } int main(){ fast_io; for(int i=1; i<M; i++){ for(int j=i; j<M; j+=i){ d[j].pb(i); } } cin >> n >> m >> k >> s; s++; for(int i=1; i<=n; i++){ int p,v; cin >> p >> v; adj[p].pb({i,v+1}); } for(int i=1; i<=m; i++){ int p,v; cin >> p >> v; adj[p].pb({i+n,v+1}); } p[0]=-1; predfs(0); dfs(0); for(int i=1; i<=m; i++){ if(ans[i]) cout << "YES\n"; else cout << "NO\n"; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...