Submission #34941

#TimeUsernameProblemLanguageResultExecution timeMemory
34941wan2000스파이 (JOI13_spy)C++14
10 / 100
309 ms246836 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, mx; bitset<M> D[2][N], B; vector<int> Adj[2][N]; void DFS(int u, int tp){ for(int i = 0; i < (int)Adj[tp][u].size(); i++){ int v = Adj[tp][u][i]; D[tp][v] |= D[tp][u]; DFS(v,tp); } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); read(n); read(m); for(int i = 1; i <= n; i++){ int x, y; read(x); read(y); Adj[0][x].push_back(i); Adj[1][y].push_back(i); } for(int i = 0; i < m; i++){ int x, y; read(x); read(y); D[0][x].set(i); D[1][y].set(i); } DFS(0,0); DFS(0,1); for(int i = 1; i <= n; i++){ B = D[0][i]&D[1][i]; cout<<B.count()<<'\n'; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...