Submission #299108

# Submission time Handle Problem Language Result Execution time Memory
299108 2020-09-14T13:41:37 Z mat_v Regions (IOI09_regions) C++14
12 / 100
8000 ms 103156 KB
#include <bits/stdc++.h>
#define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
#define pb push_back
#define maxn 200005

using namespace std;
typedef long long ll;

int n,r,q;
int dlt;
int niz[maxn];
bool veci[maxn];
int cale[maxn];
vector<int> graf[maxn];
vector<int> boja[maxn];

int disc[maxn];
int out[maxn];
int gde[maxn];
int slika[505];


int kolko[505][25005][2];

int tajm = 1;
void dfs(int x){
    disc[x] = tajm;
    for(auto c:graf[x]){
        if(c == cale[x])continue;
        tajm++;
        dfs(c);
    }
    out[x] = tajm;
}

void color(int x, int last, int root, int idx){
    kolko[root][niz[x]][idx]++;
    for(auto c:graf[x]){
        if(c == last)continue;
        color(c,x,root,idx);
    }
}

bool cmp(int x, int y){
    if(out[x] == out[y])return disc[x] < disc[y];
    return out[x] < out[y];
}


int subtr[maxn];


int main()
{
    ios_base::sync_with_stdio(false);

    cin >> n >> r >> q;
    while(dlt * dlt < n)dlt++;
    ff(i,1,n){
        if(i == 1){
            cin >> niz[i];
            boja[niz[i]].pb(i);
            continue;
        }
        cin >> cale[i];
        cin >> niz[i];
        graf[i].pb(cale[i]);
        boja[niz[i]].pb(i);
        graf[cale[i]].pb(i);
    }
    int br = 1;
    ff(i,1,r){
        int sta = boja[i].size();
        if(sta >= 0)veci[i] = 1;
        if(veci[i]){
            slika[br] = i;
            gde[i] = br;
            for(auto c:boja[i]){
                color(cale[c],c,br,1);
                color(c,cale[c],br,0);
                kolko[br][i][0]--;
            }
            br++;
        }
        else{

        }

    }
    dfs(1);
    while(q--){
        int r1,r2;
        cin >> r1 >> r2;
        if(veci[r1] || veci[r2]){
            if(veci[r1]){
                cout << kolko[gde[r1]][r2][0] << endl;
            }
            else{
                cout << kolko[gde[r2]][r1][1] << endl;
            }
        }
        else{
            int p1 = 0;
            int p2 = 0;
        }
    }
    return 0;
}

Compilation message

regions.cpp: In function 'int main()':
regions.cpp:2:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    2 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
regions.cpp:59:5: note: in expansion of macro 'ff'
   59 |     ff(i,1,n){
      |     ^~
regions.cpp:2:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    2 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
regions.cpp:72:5: note: in expansion of macro 'ff'
   72 |     ff(i,1,r){
      |     ^~
regions.cpp:103:17: warning: unused variable 'p1' [-Wunused-variable]
  103 |             int p1 = 0;
      |                 ^~
regions.cpp:104:17: warning: unused variable 'p2' [-Wunused-variable]
  104 |             int p2 = 0;
      |                 ^~
# Verdict Execution time Memory Grader output
1 Correct 7 ms 9728 KB Output is correct
2 Correct 7 ms 9728 KB Output is correct
3 Correct 9 ms 9856 KB Output is correct
4 Correct 11 ms 9984 KB Output is correct
5 Correct 16 ms 9984 KB Output is correct
6 Correct 36 ms 11392 KB Output is correct
7 Correct 67 ms 10616 KB Output is correct
8 Correct 96 ms 11128 KB Output is correct
9 Correct 359 ms 12408 KB Output is correct
10 Correct 2372 ms 13552 KB Output is correct
11 Correct 5479 ms 12592 KB Output is correct
12 Correct 7942 ms 14868 KB Output is correct
13 Execution timed out 8071 ms 12476 KB Time limit exceeded
14 Execution timed out 8076 ms 11568 KB Time limit exceeded
15 Execution timed out 8073 ms 15096 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Execution timed out 8042 ms 14704 KB Time limit exceeded
2 Execution timed out 8084 ms 13796 KB Time limit exceeded
3 Execution timed out 8099 ms 17272 KB Time limit exceeded
4 Runtime error 3400 ms 56088 KB Execution killed with signal 11 (could be triggered by violating memory limits)
5 Runtime error 1872 ms 52024 KB Execution killed with signal 11 (could be triggered by violating memory limits)
6 Runtime error 4699 ms 81656 KB Execution killed with signal 11 (could be triggered by violating memory limits)
7 Execution timed out 8087 ms 37408 KB Time limit exceeded
8 Execution timed out 8092 ms 52128 KB Time limit exceeded
9 Execution timed out 8038 ms 25080 KB Time limit exceeded
10 Execution timed out 8022 ms 103156 KB Time limit exceeded
11 Execution timed out 8063 ms 55464 KB Time limit exceeded
12 Execution timed out 8071 ms 24852 KB Time limit exceeded
13 Execution timed out 8095 ms 27000 KB Time limit exceeded
14 Execution timed out 8069 ms 23888 KB Time limit exceeded
15 Execution timed out 8021 ms 47716 KB Time limit exceeded
16 Execution timed out 8020 ms 62392 KB Time limit exceeded
17 Execution timed out 8090 ms 34452 KB Time limit exceeded