# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
937025 |
2024-03-03T09:04:09 Z |
Beerus13 |
스파이 (JOI13_spy) |
C++14 |
|
256 ms |
250176 KB |
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 2e3 + 5;
const int maxn = 5e5 + 5;
int n, m, root[2];
vector<int> g[2][N];
bitset<maxn> dp[2][N], intersect;
void dfs(int u, int t) {
for(int v : g[t][u]) {
dp[t][v] |= dp[t][u];
dfs(v, t);
}
}
void solve() {
cin >> n >> m;
for(int i = 1, p0, p1; i <= n; ++i) {
cin >> p0 >> p1;
if(p0 == 0) root[0] = i;
else g[0][p0].push_back(i);
if(p1 == 0) root[1] = i;
else g[1][p1].push_back(i);
}
for(int i = 0, p0, p1; i < m; ++i) {
cin >> p0 >> p1;
dp[0][p0][i] = 1;
dp[1][p1][i] = 1;
}
dfs(root[0], 0); dfs(root[1], 1);
for(int i = 1; i <= n; ++i) {
intersect = dp[0][i] & dp[1][i];
cout << intersect.count() << '\n';
}
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int test = 1;
// cin >> test;
while(test--) solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
27228 KB |
Output is correct |
2 |
Correct |
11 ms |
27228 KB |
Output is correct |
3 |
Correct |
12 ms |
27228 KB |
Output is correct |
4 |
Correct |
11 ms |
27228 KB |
Output is correct |
5 |
Correct |
12 ms |
27432 KB |
Output is correct |
6 |
Correct |
11 ms |
27228 KB |
Output is correct |
7 |
Correct |
11 ms |
27224 KB |
Output is correct |
8 |
Correct |
10 ms |
27228 KB |
Output is correct |
9 |
Correct |
1 ms |
2652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
156 ms |
245364 KB |
Output is correct |
2 |
Correct |
133 ms |
245344 KB |
Output is correct |
3 |
Correct |
132 ms |
245356 KB |
Output is correct |
4 |
Correct |
132 ms |
245336 KB |
Output is correct |
5 |
Correct |
138 ms |
245548 KB |
Output is correct |
6 |
Correct |
133 ms |
245588 KB |
Output is correct |
7 |
Correct |
133 ms |
245332 KB |
Output is correct |
8 |
Correct |
140 ms |
245304 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
256 ms |
249684 KB |
Output is correct |
2 |
Correct |
186 ms |
250176 KB |
Output is correct |
3 |
Correct |
242 ms |
249680 KB |
Output is correct |
4 |
Correct |
216 ms |
249940 KB |
Output is correct |
5 |
Correct |
241 ms |
249768 KB |
Output is correct |
6 |
Correct |
183 ms |
249424 KB |
Output is correct |
7 |
Correct |
256 ms |
249684 KB |
Output is correct |
8 |
Correct |
254 ms |
249776 KB |
Output is correct |