QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#402190 | #7103. Red Black Tree | miaokx | Compile Error | / | / | C++17 | 3.3kb | 2024-04-30 06:29:35 | 2024-04-30 06:29:36 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
vector<long long> cost, d;
vector<bool> red;
vector<vector<int>> adj;
vector<vector<pair<int, long long>>> adj2;
// using LCA------------------------------------------------
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
template<class T>
struct RMQ {
vector<vector<T>> jmp;
RMQ(const vector<T>& V) : jmp(1, V) {
for (int pw = 1, k = 1; pw * 2 <= sz(V); pw *= 2, ++k) {
jmp.emplace_back(sz(V) - pw * 2 + 1);
rep(j,0,sz(jmp[k]))
jmp[k][j] = min(jmp[k - 1][j], jmp[k - 1][j + pw]);
}
}
T query(int a, int b) {
assert(a < b); // or return inf if a == b
int dep = 31 - __builtin_clz(b - a);
return min(jmp[dep][a], jmp[dep][b - (1 << dep)]);
}
};
struct LCA {
int T = 0;
vi time, path, ret;
RMQ<int> rmq;
LCA(vector<vi>& C) : time(sz(C)), rmq((dfs(C,0,-1), ret)) {}
void dfs(vector<vi>& C, int v, int par) {
time[v] = T++;
for (int y : C[v]) if (y != par) {
path.push_back(v), ret.push_back(time[v]);
dfs(C, y, v);
}
}
int lca(int a, int b) {
if (a == b) return a;
tie(a, b) = minmax(time[a], time[b]);
return path[rmq.query(a, b)];
}
//dist(a,b){return depth[a] + depth[b] - 2*depth[lca(a,b)];}
};
// ---------------------------------------------------------------
void dfs(int cur, int par) {
for (auto &[v, w] : adj2[cur]) {
if (v == par) continue;
d[v] = d[cur] + w;
if (!red[v]) {
cost[v] = cost[cur] + w;
}
dfs(v, cur);
}
}
void solve() {
int n, r, q;
cin >> n >> r >> q;
adj.assign(n, vector<int>());
adj2.assign(n, vector<pair<int,int>>());
cost.assign(n, 0);
d.assign(n, 0);
red.assign(n, false);
for (int i = 0; i < r; i++) {
int x;
cin >> x;
x--;
red[x] = true;
}
for (int i = 0; i < n-1; i++) {
int u, v, w;
cin >> u >> v >> w;
u--;
v--;
adj[u].push_back(v);
adj[v].push_back(u);
adj2[u].push_back({v, w});
adj2[v].push_back({u, w});
}
dfs(0, -1);
/*
for (int i = 0; i < n; i++) {
cout << cost[i] << " \n"[i==n-1];
}
for (int i = 0; i < n; i++) {
cout << d[i] << " \n"[i==n-1];
}
*/
LCA lca(adj);
while (q--) {
int k;
cin >> k;
vector<int> query(k);
for (int j = 0; j < k; j++) {
cin >> query[j];
query[j]--;
}
query.push_back(0);
sort(begin(query), end(query),
[&](int i, int j) {
return cost[i] > cost[j];
});
int node = query[0];
long long mxd = d[query[0]];
long long ans = cost[query[1]];
for (int i = 1; i + 1 < k; i++) {
node = lca.lca(node, query[i]);
mxd = max(mxd, d[query[i]]);
ans = min(ans, max(mxd - d[node], cost[query[i+1]]));
}
cout << ans << '\n';
}
adj.clear();
adj2.clear();
cost.clear();
d.clear();
red.clear();
}
int main() {
int t;
cin >> t;
while (t--)
solve();
}
Details
answer.code: In function ‘void solve()’: answer.code:76:16: error: no matching function for call to ‘std::vector<std::vector<std::pair<int, long long int> > >::assign(int&, std::vector<std::pair<int, int> >)’ 76 | adj2.assign(n, vector<pair<int,int>>()); | ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~ In file included from /usr/include/c++/13/vector:66, from /usr/include/c++/13/functional:64, from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:53, from answer.code:1: /usr/include/c++/13/bits/stl_vector.h:825:9: note: candidate: ‘template<class _InputIterator, class> void std::vector<_Tp, _Alloc>::assign(_InputIterator, _InputIterator) [with <template-parameter-2-2> = _InputIterator; _Tp = std::vector<std::pair<int, long long int> >; _Alloc = std::allocator<std::vector<std::pair<int, long long int> > >]’ 825 | assign(_InputIterator __first, _InputIterator __last) | ^~~~~~ /usr/include/c++/13/bits/stl_vector.h:825:9: note: template argument deduction/substitution failed: answer.code:76:16: note: deduced conflicting types for parameter ‘_InputIterator’ (‘int’ and ‘std::vector<std::pair<int, int> >’) 76 | adj2.assign(n, vector<pair<int,int>>()); | ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/include/c++/13/bits/stl_vector.h:805:7: note: candidate: ‘void std::vector<_Tp, _Alloc>::assign(size_type, const value_type&) [with _Tp = std::vector<std::pair<int, long long int> >; _Alloc = std::allocator<std::vector<std::pair<int, long long int> > >; size_type = long unsigned int; value_type = std::vector<std::pair<int, long long int> >]’ 805 | assign(size_type __n, const value_type& __val) | ^~~~~~ /usr/include/c++/13/bits/stl_vector.h:805:47: note: no known conversion for argument 2 from ‘std::vector<std::pair<int, int> >’ to ‘const std::vector<std::vector<std::pair<int, long long int> > >::value_type&’ {aka ‘const std::vector<std::pair<int, long long int> >&’} 805 | assign(size_type __n, const value_type& __val) | ~~~~~~~~~~~~~~~~~~^~~~~ /usr/include/c++/13/bits/stl_vector.h:852:7: note: candidate: ‘void std::vector<_Tp, _Alloc>::assign(std::initializer_list<_Tp>) [with _Tp = std::vector<std::pair<int, long long int> >; _Alloc = std::allocator<std::vector<std::pair<int, long long int> > >]’ 852 | assign(initializer_list<value_type> __l) | ^~~~~~ /usr/include/c++/13/bits/stl_vector.h:852:7: note: candidate expects 1 argument, 2 provided