Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int main(){
- freopen("lca.in","r", stdin);
- freopen("lca.out","w",stdout);
- FastIO::Reader cin;
- FastIO::Writer cout;
- std::string type;
- int a,b;
- cin>>q;
- double tin = (double)clock();
- for(int i=0;i<q;i++){
- cin>>type>>a>>b;
- n = std::max({a,b,n});
- if(type[0] == 'A'){
- g[a-1].push_back(b-1);
- g[b-1].push_back(a-1);
- } else {
- query.push_back(std::make_pair(a-1,b-1));
- }
- }
- double tout = (double)clock();
- double time = (tout - tin) / CLOCKS_PER_SEC;
- assert(time <= 0.1);
- init();
- std::vector<int> answer;
- for(auto [a,b] : query){
- a = kek[a];
- b = kek[b];
- if(a > b) std::swap(a,b);
- answer.push_back(1 + lca(1, a, b, 0, lel.size()-1));
- }
- tin = (double)clock();
- for(int i : answer){
- cout<<i<<"\n";
- }
- tout = (double)clock();
- time = (tout - tin) / CLOCKS_PER_SEC;
- assert(time <= 0.01);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement