Advertisement
999ms

Untitled

Mar 24th, 2019
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.95 KB | None | 0 0
  1. int main(){
  2.         freopen("lca.in","r", stdin);
  3.         freopen("lca.out","w",stdout);
  4.         FastIO::Reader cin;
  5.         FastIO::Writer cout;
  6.     std::string type;
  7.     int a,b;
  8.     cin>>q;
  9.     double tin = (double)clock();
  10.     for(int i=0;i<q;i++){
  11.         cin>>type>>a>>b;
  12.         n = std::max({a,b,n});
  13.         if(type[0] == 'A'){
  14.             g[a-1].push_back(b-1);
  15.             g[b-1].push_back(a-1);
  16.         } else {
  17.             query.push_back(std::make_pair(a-1,b-1));
  18.         }
  19.     }
  20.     double tout = (double)clock();
  21.         double time = (tout - tin) / CLOCKS_PER_SEC;
  22.         assert(time <= 0.1);
  23.     init();
  24.     std::vector<int> answer;
  25.     for(auto [a,b] : query){
  26.         a = kek[a];
  27.         b = kek[b];
  28.         if(a > b) std::swap(a,b);
  29.         answer.push_back(1 + lca(1, a, b, 0, lel.size()-1));       
  30.     }
  31.         tin = (double)clock();
  32.         for(int i : answer){
  33.                 cout<<i<<"\n";
  34.         }
  35.         tout = (double)clock();
  36.         time = (tout - tin) / CLOCKS_PER_SEC;
  37.         assert(time <= 0.01);
  38.     return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement