#include <bits/stdc++.h>// "i will win voi25"
using namespace std;
#define fi first
#define se second
#define Forv(v, h) for(auto &v : h)
#define For(i, a, b) for(int i = a; i <= b; ++i)
#define Ford(i, a, b) for(int i = a; i >= b; --i)
#define all(h) h.begin(), h.end()
#define reset(h, v) (memset(h, v, sizeof(h)))
#define c_bit(i) __builtin_popcountll(i)
#define Bit(mask, i) ((mask >> i) & 1)
#define onbit(mask, i) ((mask) bitor (1LL << i))
#define offbit(mask, i) ((mask) &~ (1LL << i))
using ll = long long;
using ii = pair<ll, ll>;
using vi = vector<ll>;
using vvi = vector<vi>;
using vii = vector<ii>;
template <class X, class Y> bool maximize(X &a, const Y &b)
{
if(a < b) return a = b, true;
return false;
}
template <class X, class Y> bool minimize(X &a, const Y &b)
{
if(a > b) return a = b, true;
return false;
}
// #define int long long
const int dx[] = {0, -1, +1, 0}, dy[] = {-1, 0, 0, +1};
const ll oo = 1e18 + 1, base = 311, block = 500;
const ll MOD = 1e9 + 7;
const int MAXN = 3e3 + 5;
int n, m;
int a[MAXN], b[MAXN], cnt[MAXN][MAXN], dp[MAXN][MAXN];
int solve (int i, int j)
{
if (!i || !j) return 0ll;
if (~dp[i][j]) return dp[i][j];
int res = cnt[i][j];
res += solve(a[i], j) + solve(i, b[j]) - solve(a[i], b[j]);
return dp[i][j] = res;
}
void process()
{
cin >> n >> m;
For (i, 1, n) {
cin >> a[i] >> b[i];
}
reset(dp, -1);
For (i, 1, m) {
int x, y;
cin >> x >> y;
cnt[x][y]++;
}
For (i, 1, n) cout << solve(i, i) << '\n';
}
int32_t main()
{
ios_base::sync_with_stdio(false); cin.tie(nullptr);
#define name "a"
if (fopen(name".inp", "r")) {
freopen(name".inp", "r", stdin);
freopen(name".out", "w", stdout);
}
//int tc = 1; cin >> tc; while (tc--)
process(); // -> ac
cerr << "\nTime elapsed: " << (1.0 * clock() / CLOCKS_PER_SEC) << " s.\n";
return 0;
}
Compilation message
spy.cpp: In function 'int32_t main()':
spy.cpp:74:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
74 | freopen(name".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
spy.cpp:75:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
75 | freopen(name".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
39516 KB |
Output is correct |
2 |
Correct |
4 ms |
37468 KB |
Output is correct |
3 |
Correct |
4 ms |
39516 KB |
Output is correct |
4 |
Correct |
4 ms |
39580 KB |
Output is correct |
5 |
Correct |
4 ms |
39444 KB |
Output is correct |
6 |
Correct |
4 ms |
39516 KB |
Output is correct |
7 |
Correct |
4 ms |
39568 KB |
Output is correct |
8 |
Correct |
4 ms |
39636 KB |
Output is correct |
9 |
Correct |
4 ms |
37580 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
56 ms |
60368 KB |
Output is correct |
2 |
Correct |
57 ms |
46100 KB |
Output is correct |
3 |
Correct |
7 ms |
59992 KB |
Output is correct |
4 |
Correct |
7 ms |
59996 KB |
Output is correct |
5 |
Correct |
9 ms |
59996 KB |
Output is correct |
6 |
Correct |
10 ms |
53852 KB |
Output is correct |
7 |
Correct |
45 ms |
60176 KB |
Output is correct |
8 |
Correct |
12 ms |
59996 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
105 ms |
64492 KB |
Output is correct |
2 |
Correct |
100 ms |
60500 KB |
Output is correct |
3 |
Correct |
42 ms |
64396 KB |
Output is correct |
4 |
Correct |
59 ms |
64852 KB |
Output is correct |
5 |
Correct |
51 ms |
64340 KB |
Output is correct |
6 |
Correct |
49 ms |
63828 KB |
Output is correct |
7 |
Correct |
150 ms |
64356 KB |
Output is correct |
8 |
Correct |
88 ms |
64340 KB |
Output is correct |