# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
35018 |
2017-11-17T10:00:07 Z |
luongduydat |
스파이 (JOI13_spy) |
C++14 |
|
366 ms |
247172 KB |
#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 |
1 |
Correct |
19 ms |
247040 KB |
Output is correct |
2 |
Correct |
16 ms |
247040 KB |
Output is correct |
3 |
Correct |
23 ms |
247040 KB |
Output is correct |
4 |
Correct |
23 ms |
247040 KB |
Output is correct |
5 |
Correct |
13 ms |
247040 KB |
Output is correct |
6 |
Correct |
19 ms |
247040 KB |
Output is correct |
7 |
Correct |
19 ms |
247040 KB |
Output is correct |
8 |
Correct |
16 ms |
247040 KB |
Output is correct |
9 |
Correct |
0 ms |
247040 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
166 ms |
247172 KB |
Output is correct |
2 |
Correct |
176 ms |
247172 KB |
Output is correct |
3 |
Correct |
146 ms |
247040 KB |
Output is correct |
4 |
Correct |
183 ms |
247040 KB |
Output is correct |
5 |
Correct |
179 ms |
247040 KB |
Output is correct |
6 |
Correct |
153 ms |
247040 KB |
Output is correct |
7 |
Correct |
146 ms |
247172 KB |
Output is correct |
8 |
Correct |
176 ms |
247172 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
366 ms |
247172 KB |
Output is correct |
2 |
Correct |
233 ms |
247172 KB |
Output is correct |
3 |
Correct |
283 ms |
247040 KB |
Output is correct |
4 |
Correct |
296 ms |
247040 KB |
Output is correct |
5 |
Correct |
343 ms |
247040 KB |
Output is correct |
6 |
Correct |
199 ms |
247040 KB |
Output is correct |
7 |
Correct |
333 ms |
247172 KB |
Output is correct |
8 |
Correct |
366 ms |
247172 KB |
Output is correct |