Submission #1081328

# Submission time Handle Problem Language Result Execution time Memory
1081328 2024-08-29T22:46:22 Z Dennis_Jason Regions (IOI09_regions) C++14
26 / 100
3256 ms 131072 KB
#include <bits/stdc++.h>
#define NMAX 200001
#define pb push_back
#define eb emplace_back
#define MOD 100003
#define nl '\n'
#define INF  2147483647
#define LLONG_MAX 9223372036854775807
#define pii pair<int,int>
#define tpl tuple<int,int,int>
//#pragma GCC optimize("O3")
using namespace std;
ifstream fin("aib.in");
ofstream fout("aib.out");
/*
 *
 *
    ================DEMONSTRATION===================


    =====================END========================
 */

int n,r,q;
int r1,r2;
vector<int>tin(NMAX),tout(NMAX);
vector<int>h(NMAX),s(NMAX);
vector<vector<int>>G(NMAX);
vector<int>used(25001);
vector<vector<int>>ans(25001);
vector<vector<int>>reg(25001);
vector<int>R;
int timp;
void read_query()
{
    cin>>r1>>r2;
}
void dfs(int node,int parent)
{
    tin[node]=++timp;
    used[h[node]]++;
    for (auto x: G[node])
    {
        if (x != parent)
        {
            dfs(x, node);
        }
    }
    for(auto x:R)
        ans[x][h[node]]+=used[x];
    used[h[node]]--;
    tout[node]=timp;
}

signed main() {

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin>>n>>r>>q;
    cin>>h[1];
    reg[h[1]].pb(1);
    for(int i=2;i<=n;++i)
    {
        cin>>s[i]>>h[i];
        reg[h[i]].pb(i);
        G[i].pb(s[i]);
        G[s[i]].pb(i);
    }
    for(int i=1;i<=r;++i)
    {
        if(reg[i].size())
        {
            R.pb(i);
            ans[i].resize(r+1,0);
        }
    }
    dfs(1,-1);

    while(q--)
    {
        read_query();
        cout.flush()<<ans[r1][r2]<<nl;
        cout.flush();
    }

    return 0;
}

Compilation message

regions.cpp:8: warning: "LLONG_MAX" redefined
    8 | #define LLONG_MAX 9223372036854775807
      | 
In file included from /usr/lib/gcc/x86_64-linux-gnu/10/include/limits.h:195,
                 from /usr/lib/gcc/x86_64-linux-gnu/10/include/syslimits.h:7,
                 from /usr/lib/gcc/x86_64-linux-gnu/10/include/limits.h:34,
                 from /usr/include/c++/10/climits:42,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:39,
                 from regions.cpp:1:
/usr/include/limits.h:135: note: this is the location of the previous definition
  135 | #  define LLONG_MAX __LONG_LONG_MAX__
      |
# Verdict Execution time Memory Grader output
1 Runtime error 11 ms 19032 KB Execution killed with signal 11
2 Runtime error 11 ms 19032 KB Execution killed with signal 11
3 Runtime error 11 ms 19032 KB Execution killed with signal 11
4 Correct 6 ms 9580 KB Output is correct
5 Correct 7 ms 9560 KB Output is correct
6 Runtime error 12 ms 19656 KB Execution killed with signal 11
7 Correct 20 ms 9816 KB Output is correct
8 Correct 24 ms 10064 KB Output is correct
9 Correct 34 ms 10440 KB Output is correct
10 Correct 48 ms 10584 KB Output is correct
11 Correct 66 ms 10284 KB Output is correct
12 Correct 90 ms 11412 KB Output is correct
13 Correct 98 ms 10976 KB Output is correct
14 Correct 111 ms 10908 KB Output is correct
15 Correct 140 ms 13648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 535 ms 13400 KB Output is correct
2 Correct 666 ms 12916 KB Output is correct
3 Correct 858 ms 15292 KB Output is correct
4 Runtime error 3176 ms 131072 KB Execution killed with signal 9
5 Runtime error 3256 ms 131072 KB Execution killed with signal 9
6 Runtime error 89 ms 131072 KB Execution killed with signal 9
7 Runtime error 73 ms 131072 KB Execution killed with signal 9
8 Runtime error 90 ms 131072 KB Execution killed with signal 9
9 Runtime error 94 ms 131072 KB Execution killed with signal 9
10 Runtime error 118 ms 131072 KB Execution killed with signal 9
11 Runtime error 94 ms 131072 KB Execution killed with signal 9
12 Runtime error 116 ms 131072 KB Execution killed with signal 9
13 Runtime error 92 ms 131072 KB Execution killed with signal 9
14 Runtime error 123 ms 131072 KB Execution killed with signal 9
15 Runtime error 95 ms 131072 KB Execution killed with signal 9
16 Runtime error 99 ms 131072 KB Execution killed with signal 9
17 Runtime error 91 ms 131072 KB Execution killed with signal 9