제출 #1045518

#제출 시각아이디문제언어결과실행 시간메모리
1045518juicy스파이 (JOI13_spy)C++17
100 / 100
94 ms20304 KiB
#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif

const int N = 2e3 + 5;

int n, m;
int a[N], b[N], dp[N][N];
bool vis[N][N];

int f(int i, int j) {
    if (i == 0 || j == 0) {
        return 0;
    } 
    int &res = dp[i][j];
    if (vis[i][j]) {
        return res;
    }
    vis[i][j] = 1;
    return res += f(a[i], j) + f(i, b[j]) - f(a[i], b[j]);
}

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);

    cin >> n >> m;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i] >> b[i];
    }
    while (m--) {
        int a, b; cin >> a >> b;
        ++dp[a][b];
    }
    for (int i = 1; i <= n; ++i) {
        cout << f(i, i) << "\n";
    }
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...