Submission #937025

#TimeUsernameProblemLanguageResultExecution timeMemory
937025Beerus13스파이 (JOI13_spy)C++14
100 / 100
256 ms250176 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...