# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1083271 | rayan_bd | Regions (IOI09_regions) | C++17 | 246 ms | 131072 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
const int mxN = 2e5 + 5000;
ll color[mxN][505];
vector<ll> adj[mxN];
ll hd[mxN],out[mxN];
unordered_map<ll,vector<ll>> mp;
void solve(ll tc) {
ll n,r,q,r1,r2,super;cin>>n>>r>>q;
cin>>hd[1];
mp[hd[1]].pb(1);
color[1][hd[1]]=1;
for(ll i=2;i<=n;++i){
cin>>super>>hd[i];
adj[i].pb(super);
mp[hd[i]].pb(i);
color[i][hd[i]]=1;
++out[super];
}
set<ll> st;
for(ll i=1;i<=n;++i){
if(out[i]==0){
st.insert(i);
}
}
while(st.size()){
ll u=*st.begin();
st.erase(u);
for(auto it:adj[u]){
for(ll i=1;i<505;++i){
color[it][i]+=color[u][i];
}
if(--out[it]==0) st.insert(it);
}
}
while(q--){
cin>>r1>>r2;
ll ans=0;
for(auto it:mp[hd[r1]]){
ans+=color[it][r2];
}
cout.flush()<<ans<<'\n';
cout.flush();
}
}
void testing(){
#ifndef ONLINE_JUDGE
freopen("input.in","r",stdin);
freopen("output.out","w",stdout);
#endif
}
int main() {
//testing();
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
solve(0);
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |