This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define fi first
#define se second
#define all(v) (v).begin(), (v).end()
#define eb emplace_back
#define fastio ios::sync_with_stdio(false); cin.tie(NULL)
#define INF 2000000000;
#define LINF 1000000000000000000LL
#define mod 1000000007
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
int dp[2020][2020], cnt[2020][2020], pj[2020], pi[2020];
bool chk[2020][2020];
int f(int i, int j) {
if(i == 0 || j == 0) return 0;
if(chk[i][j]) return dp[i][j];
chk[i][j] = true;
int temp = pj[j];
dp[i][j] += f(pi[i], j);
dp[i][j] += f(i, pj[j]);
dp[i][j] -= f(pi[i], pj[j]);
dp[i][j] += cnt[i][j];
return dp[i][j];
}
int main() {
fastio;
int n, m;
cin >> n >> m;
for(int i = 1, u, v; i <= n; i++) {
cin >> u >> v;
pj[i] = u;
pi[i] = v;
}
for(int i = 1; i <= m; i++) {
int r, s;
cin >> r >> s;
cnt[s][r]++;
}
for(int i = 1; i <= n; i++) {
cout << f(i, i) << '\n';
}
}
Compilation message (stderr)
spy.cpp: In function 'int f(int, int)':
spy.cpp:23:6: warning: unused variable 'temp' [-Wunused-variable]
int temp = pj[j];
^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |