# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
871478 | 2023-11-11T02:25:03 Z | 1075508020060209tc | File Paths (BOI15_fil) | C++14 | 17 ms | 16172 KB |
//#pragma GCC optimize ("O3") #include<bits/stdc++.h> //#include <bits/extc++.h> //using namespace __gnu_pbds; using namespace std; #define int long long #define X first #define Y second int n;int Q;int S;int K; vector<pair<int,int>>e[500005]; int dph[500005]; int dis[500005]; int fa[500005]; int wf[500005]; map<int,int>mp; void dfs(int nw){ for(int i=0;i<e[nw].size();i++){ int v=e[nw][i].first; dph[v]=dph[nw]+1; dis[v]=dis[nw]+e[nw][i].second; dfs(v); } mp[dis[nw]]++; } signed main(){ cin>>n>>Q>>K>>S; n++; S++; for(int i=2;i<=n;i++){ cin>>fa[i]>>wf[i]; fa[i]++; wf[i]++; e[fa[i]].push_back({i,wf[i]}); } dfs(1); while(Q--){ int v;int len; cin>>v>>len; len++; v++; int ok=0; if(dis[v]+len==K){ cout<<"YES\n"; continue; } int nwd=len; int nw=v; while(1){ mp[dis[nw]]--; int nd=K-nwd-len; if(mp[nd]){ mp[dis[nw]]++; ok=1;break; } mp[dis[nw]]++; if(nw==1){break;} nwd=nwd+wf[nw]; nw=fa[nw]; } if(ok){ cout<<"YES\n";continue; }cout<<"NO\n"; } }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 4 ms | 15196 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 17 ms | 16172 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 4 ms | 15196 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |