# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
559611 | Codurr | Regions (IOI09_regions) | C++14 | 8093 ms | 33416 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "bits/stdc++.h"
using namespace std;
#define int long long //Avoid if time complexity very close to limit
#define ll long long
#define sz(x) (int)((x).size())
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define f first
#define s second
void setIO(string s = "") {
ios_base::sync_with_stdio(0); cin.tie(0);
if (sz(s)) {
freopen((s + ".in").c_str(), "r", stdin);
freopen((s + ".out").c_str(), "w", stdout);
}
}
//Imp consts
const int MOD = 1e9 + 7;
const int MAXN = 2e5 + 1;
const int MAXN1 = 3e4 + 1;
const int INF = 1e18 + 5;
const double pi = 3.14159265358979323846;
const double ep = 1e-20;
vector<int> reg[MAXN1], adj[MAXN];
vector<vector<int>> sub(MAXN1);
vector<int> R(MAXN);
int timer, en[MAXN], st[MAXN];
void dfs(int s, int e) {
st[s] = timer++;
reg[R[s]].push_back(timer - 1);
for (auto u : adj[s])
if (u != e)
dfs(u, s);
en[s] = timer - 1;
}
signed main() {
setIO();
int n, r, q;
cin >> n >> r >> q;
cin >> R[1];
sub[R[1]].push_back(1);
for (int i = 2; i <= n; i++) {
int x;
cin >> x >> R[i];
sub[R[i]].push_back(i);
adj[x].push_back(i);
adj[i].push_back(x);
}
dfs(1, 0);
while (q--) {
int r1, r2;
cin >> r1 >> r2;
int ans = 0;
for (auto u : sub[r1])
ans += upper_bound(all(reg[r2]), en[u]) - lower_bound(all(reg[r2]), st[u]);
cout << ans << endl;
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |