# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
698191 |
2023-02-12T19:24:12 Z |
pls33 |
Regions (IOI09_regions) |
C++17 |
|
0 ms |
0 KB |
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#pragma region dalykai
using p32 = pair<int, int>;
using p32u = pair<uint32_t, uint32_t>;
using p64 = pair<int64_t, int64_t>;
using p64u = pair<uint64_t, uint64_t>;
using vi16 = vector<int16_t>;
using vi16u = vector<uint16_t>;
using vi32 = vector<int>;
using vi32u = vector<uint32_t>;
using vi64 = vector<int64_t>;
using vi64u = vector<uint64_t>;
using vp32 = vector<p32>;
using vp32u = vector<p32u>;
using vp64 = vector<p64>;
using vp64u = vector<p64u>;
using vvi32 = vector<vi32>;
using vvi32u = vector<vi32u>;
using vvi64 = vector<vi64>;
using vvi64u = vector<vi64u>;
using vvp32 = vector<vp32>;
using vvp32u = vector<vp32u>;
using vvp64 = vector<vp64>;
using vvp64u = vector<vp64u>;
#pragma endregion
using map_t = map<int, int>;
void merge_region(map_t ®ion, map_t &manager)
{
for (auto &[color, count] : manager)
{
region[color] += count;
}
}
void merge_manager(map_t &manager, map_t &employee)
{
if (employee.size() > manager.size())
{
swap(employee, manager);
}
merge_region(manager, employee);
}
void find_regions(int v, int p,
vector<map_t> &count, vector<map_t> &employee,
vi32 ®ion, vvi32 &adj)
{
employee[v][region[v]]++;
for (auto &next : adj[v])
{
if (next == p)
{
continue;
}
find_regions(next, v, count, employee, region, adj);
merge_manager(employee[v], employee[next]);
}
merge_region(count[region[v]], employee[v]);
}
int main()
{
#ifndef _AAAAAAAAA
ios_base::sync_with_stdio(false);
cin.tie(0);
#else
freopen("region.in", "r", stdin);
#ifndef __linux__
atexit([]()
{
freopen("con", "r", stdin);
system("pause"); });
#endif
#endif
int n, r, q;
cin >> n >> r >> q;
vi32 region(n);
vvi32 adj(n);
cin >> region[0];
region[0]--;
for (int i = 1; i < n; i++)
{
int parent;
cin >> parent >> region[i];
parent--;
region[i]--;
adj[i].push_back(parent);
adj[parent].push_back(i);
}
vector<map_t> count(r), employee(n);
find_regions(0, -1, count, employee, region, adj);
for (int i = 0; i < q; i++)
{
int a, b;
cin >> a >> b;
a--;
b--;
if (!count[a].contains(b))
{
cout << 0 << endl;
continue;
}
cout << count[a][b] << endl;
}
return 0;
}
Compilation message
regions.cpp:8: warning: ignoring '#pragma region dalykai' [-Wunknown-pragmas]
8 | #pragma region dalykai
|
regions.cpp:31: warning: ignoring '#pragma endregion ' [-Wunknown-pragmas]
31 | #pragma endregion
|
regions.cpp: In function 'int main()':
regions.cpp:119:23: error: '__gnu_cxx::__alloc_traits<std::allocator<std::map<int, int> >, std::map<int, int> >::value_type' {aka 'class std::map<int, int>'} has no member named 'contains'
119 | if (!count[a].contains(b))
| ^~~~~~~~