#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()));
}
template<typename T> inline void write(T x){
if(x<=9){
putchar(x+'0');
return;
}
write(x/10);
putchar(x%10+'0');
}
template<typename T> inline void writeln(T x){
write(x); putchar('\n');
}
const int N = 2001;
const int M = 5e5+1;
int n, m;
bitset<M> D[2][N], cur;
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++){
cur = D[0][i]&D[1][i];
writeln(cur.count());
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
246608 KB |
Output is correct |
2 |
Correct |
16 ms |
246608 KB |
Output is correct |
3 |
Correct |
16 ms |
246608 KB |
Output is correct |
4 |
Correct |
23 ms |
246608 KB |
Output is correct |
5 |
Correct |
33 ms |
246608 KB |
Output is correct |
6 |
Correct |
23 ms |
246608 KB |
Output is correct |
7 |
Correct |
16 ms |
246608 KB |
Output is correct |
8 |
Correct |
13 ms |
246608 KB |
Output is correct |
9 |
Correct |
0 ms |
246608 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
149 ms |
246828 KB |
Output is correct |
2 |
Correct |
153 ms |
246828 KB |
Output is correct |
3 |
Correct |
159 ms |
246608 KB |
Output is correct |
4 |
Correct |
173 ms |
246608 KB |
Output is correct |
5 |
Correct |
169 ms |
246608 KB |
Output is correct |
6 |
Correct |
159 ms |
246608 KB |
Output is correct |
7 |
Correct |
146 ms |
246740 KB |
Output is correct |
8 |
Correct |
179 ms |
246740 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
329 ms |
246836 KB |
Output is correct |
2 |
Correct |
213 ms |
246832 KB |
Output is correct |
3 |
Correct |
289 ms |
246608 KB |
Output is correct |
4 |
Correct |
286 ms |
246608 KB |
Output is correct |
5 |
Correct |
323 ms |
246608 KB |
Output is correct |
6 |
Correct |
223 ms |
246608 KB |
Output is correct |
7 |
Correct |
336 ms |
246740 KB |
Output is correct |
8 |
Correct |
333 ms |
246740 KB |
Output is correct |