Submission #937037

#TimeUsernameProblemLanguageResultExecution timeMemory
937037Beerus13스파이 (JOI13_spy)C++14
100 / 100
114 ms16472 KiB
#include<bits/stdc++.h> using namespace std; #define ll long long const int N = 2e3 + 5; int n, m, root[2]; vector<int> g[2][N]; int dp[N][N]; void dfs1(int u) { for(int v : g[0][u]) { for(int i = 1; i <= n; ++i) { dp[v][i] += dp[u][i]; } dfs1(v); } } void dfs2(int u) { for(int v : g[1][u]) { for(int i = 1; i <= n; ++i) { dp[i][v] += dp[i][u]; } dfs2(v); } } 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[p0][p1]++; } dfs1(root[0]); dfs2(root[1]); for(int i = 1; i <= n; ++i) { cout << dp[i][i] << '\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...