답안 #649619

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
649619 2022-10-11T06:32:10 Z mychecksedad Regions (IOI09_regions) C++17
25 / 100
1002 ms 131072 KB
/* Author : Mychecksdead */
#include<bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long int ll;
typedef long double ld;
#define MOD (1000000000+7)
#define MOD1 (998244353)
#define PI 3.1415926535
#define pb push_back
#define setp() cout << setprecision(15)
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " is " << x << '\n';
const int N = 1e6+100, M = 1e5+10, F = 2147483646, K = 20;


int n, q, r, a[N], ans[1000][1000];
vector<int> g[N], R[N];

void dfs(int v, int p){
    R[v].resize(r + 5);
    for(int u: g[v]){
        if(u == p) continue;
        dfs(u, v);
        for(int j = 1; j <= r; ++j) R[v][j] += R[u][j];
    }
    for(int j = 1; j <= r; ++j) ans[a[v]][j] += R[v][j];
    R[v][a[v]]++;    
}

void solve(){
    cin >> n >> r >> q;
    cin >> a[1];
    for(int i = 2; i <= n; ++i){
        int x; cin >> x >> a[i];
        g[x].pb(i);
        g[i].pb(x);
    }
    for(int i = 0; i <= r; ++i) for(int j = 0; j <= r; ++j) ans[i][j] = 0;
    dfs(1, 1);
    for(;q--;){
        int a, b; cin >> a >> b;
        cout << ans[a][b] << endl;
    }
}





int main(){
    cin.tie(0); ios::sync_with_stdio(0);
    int T = 1, aa;
    // cin >> T;aa=T;
    while(T--){
        // cout << "Case #" << aa-T << ": ";
        solve();
        // cout << '\n';
    }
    return 0;
 
}

Compilation message

regions.cpp: In function 'int main()':
regions.cpp:54:16: warning: unused variable 'aa' [-Wunused-variable]
   54 |     int T = 1, aa;
      |                ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 47312 KB Output is correct
2 Correct 23 ms 47312 KB Output is correct
3 Correct 24 ms 47300 KB Output is correct
4 Correct 25 ms 47440 KB Output is correct
5 Correct 29 ms 47568 KB Output is correct
6 Correct 38 ms 49104 KB Output is correct
7 Correct 36 ms 48848 KB Output is correct
8 Correct 58 ms 49792 KB Output is correct
9 Correct 75 ms 55068 KB Output is correct
10 Correct 112 ms 66044 KB Output is correct
11 Correct 99 ms 65360 KB Output is correct
12 Correct 167 ms 86016 KB Output is correct
13 Correct 183 ms 82180 KB Output is correct
14 Correct 207 ms 73616 KB Output is correct
15 Correct 156 ms 91528 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 653 ms 112932 KB Output is correct
2 Correct 1002 ms 122604 KB Output is correct
3 Runtime error 105 ms 131072 KB Execution killed with signal 9
4 Runtime error 81 ms 113484 KB Execution killed with signal 11
5 Runtime error 81 ms 113868 KB Execution killed with signal 11
6 Runtime error 91 ms 114760 KB Execution killed with signal 11
7 Runtime error 94 ms 115956 KB Execution killed with signal 11
8 Runtime error 99 ms 117992 KB Execution killed with signal 11
9 Runtime error 112 ms 121104 KB Execution killed with signal 11
10 Runtime error 118 ms 122264 KB Execution killed with signal 11
11 Runtime error 123 ms 124900 KB Execution killed with signal 11
12 Runtime error 125 ms 123604 KB Execution killed with signal 11
13 Runtime error 126 ms 123672 KB Execution killed with signal 11
14 Runtime error 130 ms 124232 KB Execution killed with signal 11
15 Runtime error 128 ms 124200 KB Execution killed with signal 11
16 Runtime error 132 ms 124204 KB Execution killed with signal 11
17 Runtime error 126 ms 124132 KB Execution killed with signal 11