This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <cmath>
#include <cstdio>
#include <vector>
#include <bitset>
using namespace std;
template<typename T> inline void read(T &x) {
char c;
bool neg = false;
while (!isdigit(c = getchar()) && c != '-');
x = 0;
if (c == '-') {
neg = true;
c = getchar();
}
do {
x = x * 10 + c - '0';
} while (isdigit(c = getchar()));
if (neg) x = -x;
}
template<typename T> inline void write(T x) {
if (x < 0) {
putchar('-');
write(-x);return;
}
if (x < 10) {
putchar(char(x + 48));
}
else {
write(x/10);
putchar(char(48 + x%10));
}
}
template<typename T> inline void writeln(T x) {
write(x);
putchar('\n');
}
int n,m;
vector <int> aj[2005],ai[2005];
bitset<500005> p[2005],q[2005];
void Enter()
{
read(n);read(m);
for (int i=1;i<=n;i++)
{
int u,v;
read(u);read(v);
aj[u].push_back(i);
ai[v].push_back(i);
}
}
void DFS1(int u)
{
for (int v:aj[u])
{
p[v]|=p[u];
DFS1(v);
}
}
void DFS2(int u)
{
for (int v:ai[u])
{
q[v]|=q[u];
DFS2(v);
}
}
void Solve()
{
for (int i=0;i<m;i++)
{
int u,v;read(u);read(v);
p[u].set(i);
q[v].set(i);
}
DFS1(aj[0][0]);
DFS2(ai[0][0]);
for (int i=1;i<=n;i++)
{
int kq=(p[i]&q[i]).count();
writeln(kq);
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
Enter();
Solve();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |