Submission #34945

#TimeUsernameProblemLanguageResultExecution timeMemory
34945wan2000스파이 (JOI13_spy)C++14
10 / 100
346 ms246768 KiB
#include <bits/stdc++.h> using namespace std; template<typename T> inline void read(T &x){ x = 0; char ch; while(!isdigit(ch=getchar())); do{x=10*x+ch-'0';}while(isdigit(ch=getchar())); } const int N = 2001; const int M = 5e5+1; int n, m, ra, rb; bitset<M> Da[N], Db[N], cur; vector<int> Ga[N], Gb[N]; void DFSa(int u){ for(int i = 0; i < (int)Ga[u].size(); i++){ int v = Ga[u][i]; Da[v] |= Da[u]; DFSa(v); } } void DFSb(int u){ for(int i = 0; i < (int)Gb[u].size(); i++){ int v = Gb[u][i]; Db[v] |= Db[u]; DFSb(v); } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); read(n); read(m); for(int i = 1; i <= n; i++){ int x; read(x); if(x==0) ra = i; else Ga[x].push_back(i); read(x); if(x==0) rb = i; else Gb[x].push_back(i); } for(int i = 0; i < m; i++){ int x; read(x); Da[x].set(i); read(x); Db[x].set(i); } DFSa(ra); DFSb(rb); for(int i = 1; i <= n; i++){ cur = Da[i]&Db[i]; cout<<cur.count()<<'\n'; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...