# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
792436 |
2023-07-25T04:54:23 Z |
ono_de206 |
Prize (CEOI22_prize) |
C++14 |
|
0 ms |
0 KB |
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define in insert
#define all(x) x.begin(),x.end()
#define pb push_back
#define eb emplace_back
#define ff first
#define ss second
// #define int long long
typedef long long ll;
typedef vector<int> vi;
typedef set<int> si;
typedef multiset<int> msi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
template<typename T, typename U>
ostream & operator << (ostream &out, const pair<T, U> &c) {
out << c.first << ' ' << c.second;
return out;
}
template<typename T>
ostream & operator << (ostream &out, vector<T> &v) {
const int sz = v.size();
for (int i = 0; i < sz; i++) {
if (i) out << ' ';
out << v[i];
}
return out;
}
template<typename T>
istream & operator >> (istream &in, vector<T> &v) {
for (T &x : v) in >> x;
return in;
}
template<typename T>
void mxx(T &a, T b){if(b > a) a = b;}
template<typename T>
void mnn(T &a, T b){if(b < a) a = b;}
const int mxn = 1e6 + 10;
int dis1[mxn], dis2[mxn];
bool vis[mxn];
vector<pair<int, int>> adj1[mxn], adj2[mxn];
void dfs1(int to, int dis) {
dis1[i] = dis;
vis[to] = 1;
for(auto it : adj1[to]) {
if(vis[it.ff]) continue;
dfs1(it.ff, dis + it.ss);
}
}
void dfs2(int to, int dis) {
dis2[i] = dis;
vis[to] = 1;
for(auto it : adj2[to]) {
if(vis[it.ff]) continue;
dfs2(it.ff, dis + it.ss);
}
}
int main() {
fast;
int n, k, q, t; cin >> n >> k >> q >> t;
tree tr1(n), tr2(n);
for(int i = 1; i <= n; i++) {
int x; cin >> x;
if(~x) tr1.add(x, i);
}
for(int i = 1; i <= n; i++) {
int x; cin >> x;
if(~x) tr2.add(x, i);
}
tr1.build(); tr1.buildLca();
tr2.build(); tr2.buildLca();
vector<int> ks(n);
iota(all(ks), 1);
sort(all(ks), [&](int x, int y) {
return tr1.in[x] < tr1.in[y];
});
ks.resize(k);
sort(all(ks), [&](int x, int y) {
return tr2.in[x] < tr2.in[y];
});
for(int i = 0; i < k; i++) {
cout << ks[i] << ' ';
}
cout << endl;
for(int i = 0; i + 1 < k; i++) {
cout << "? " << ks[i] << ' ' << ks[i + 1] << endl;
}
cout << "!" << endl;
for(int i = 0; i + 1 < k; i++) {
int a, b, c, d;
cin >> a >> b >> c >> d;
int lc1 = tr1.lca(ks[i], ks[i + 1]);
int lc2 = tr2.lca(ks[i], ks[i + 1]);
adj1[ks[i]].eb(lc1, -a);
adj1[lc1].eb(ks[i + 1], b);
adj2[ks[i]].eb(lc2, -c);
adj2[lc2].eb(ks[i + 1], d);
}
dfs1(ks[0], 0);
for(int i = 0; i < k; i++) {
vis[ks[i]] = 0;
}
dfs2(ks[0], 0);
vector<pair<int, int>> ans;
for(int i = 0; i < t; i++) {
int x, y; cin >> x >> y;
ans.eb(dis1[x] + dis1[y] - dis1[tr1.lca(x, y)] * 2, dis2[x] + dis2[y] - dis2[tr2.lca(x, y)] * 2);
}
for(auto &it : ans) {
cout << it << endl;
}
return 0;
}
Compilation message
Main.cpp: In function 'void dfs1(int, int)':
Main.cpp:55:7: error: 'i' was not declared in this scope; did you mean 'si'?
55 | dis1[i] = dis;
| ^
| si
Main.cpp: In function 'void dfs2(int, int)':
Main.cpp:64:7: error: 'i' was not declared in this scope; did you mean 'si'?
64 | dis2[i] = dis;
| ^
| si
Main.cpp: In function 'int main()':
Main.cpp:75:2: error: 'tree' was not declared in this scope; did you mean 'free'?
75 | tree tr1(n), tr2(n);
| ^~~~
| free
Main.cpp:78:10: error: 'tr1' was not declared in this scope
78 | if(~x) tr1.add(x, i);
| ^~~
Main.cpp:82:10: error: 'tr2' was not declared in this scope
82 | if(~x) tr2.add(x, i);
| ^~~
Main.cpp:85:2: error: 'tr1' was not declared in this scope
85 | tr1.build(); tr1.buildLca();
| ^~~
Main.cpp:86:2: error: 'tr2' was not declared in this scope
86 | tr2.build(); tr2.buildLca();
| ^~~