Language: C++

#include<bits/stdc++.h>
using namespace std;
using Int = long long;
 
template<typename T,typename E>
struct LinkCutTree{
  struct Node{
    Node *l,*r,*p;
    size_t cnt;
    int idx;
    bool rev;
    T val,dat;
    E laz;
    Node():cnt(0){}
    Node(int idx,T val,E laz):
      cnt(1),idx(idx),rev(0),val(val),dat(val),laz(laz){l=r=p=nullptr;}
    bool is_root(){
      return !p||(p->l!=this&&p->r!=this);
    }
  };
   
  using F = function<T(T,T)>;
  using G = function<T(T,E)>;
  using H = function<E(E,E)>;
  using P = function<E(E,size_t)>;
  F f;
  G g;
  H h;
  P p;
  T ti;
  E ei;
   
  const size_t LIM = 1e6;
  vector<Node> pool;
  size_t ptr;
   
  LinkCutTree(F f,G g,H h,P p,T ti,E ei):
    f(f),g(g),h(h),p(p),ti(ti),ei(ei),pool(LIM),ptr(0){}
   
  inline Node* create(){
    return &pool[ptr++];
  }
   
  inline Node* create(int idx,T v){
    return &(pool[ptr++]=Node(idx,v,ei));
  }
 
  void propagate(Node *t,E v){
    t->laz=h(t->laz,v);
    t->val=g(t->val,v);
    t->dat=g(t->dat,p(v,t->cnt));
  }
 
  void toggle(Node *t){
    swap(t->l,t->r);
    t->rev^=1;
  }
 
  void eval(Node *t){
    if(t->laz!=ei){
      if(t->l) propagate(t->l,t->laz);
      if(t->r) propagate(t->r,t->laz);
      t->laz=ei;
    }
    if(t->rev){
      if(t->l) toggle(t->l);
      if(t->r) toggle(t->r);
      t->rev=false;
    }
  }
 
  void update(Node *t){
    t->cnt=1;
    t->dat=t->val;
    if(t->l) t->cnt+=t->l->cnt,t->dat=f(t->l->dat,t->dat);
    if(t->r) t->cnt+=t->r->cnt,t->dat=f(t->dat,t->r->dat);
  }
 
  void rotR(Node *t){
    Node *x=t->p,*y=x->p;
    if((x->l=t->r)) t->r->p=x;
    t->r=x;x->p=t;
    update(x);update(t);
    if((t->p=y)){
      if(y->l==x) y->l=t;
      if(y->r==x) y->r=t;
      update(y);
    }
  }
   
  void rotL(Node *t){
    Node *x=t->p,*y=x->p;
    if((x->r=t->l)) t->l->p=x;
    t->l=x;x->p=t;
    update(x);update(t);
    if((t->p=y)){
      if(y->l==x) y->l=t;
      if(y->r==x) y->r=t;
      update(y);
    }
  }
 
  void splay(Node *t){
    eval(t);
    while(!t->is_root()){
      Node *q=t->p;
      if(q->is_root()){
    eval(q);eval(t);
    if(q->l==t) rotR(t);
    else rotL(t);
      }else{
    auto *r=q->p;
    eval(r);eval(q);eval(t);
    if(r->l==q){
      if(q->l==t) rotR(q),rotR(t);
      else rotL(t),rotR(t);
    }else{  
      if(q->r==t) rotL(q),rotL(t);
      else rotR(t),rotL(t);
    }
      }
    }
  }
 
  Node* expose(Node *t){
    Node *rp=nullptr;
    for(Node *c=t;c;c=c->p){
      splay(c);
      c->r=rp;
      update(c);
      rp=c;
    }
    splay(t);
    return rp;
  }
 
  void link(Node *par,Node *c){
    expose(c);
    expose(par);
    c->p=par;
    par->r=c;
  }
 
  void cut(Node *c){
    expose(c);
    Node *par=c->l;
    c->l=nullptr;
    par->p=nullptr;
  }
 
  void evert(Node *t){
    expose(t);
    toggle(t);
    eval(t);
  }
 
  Node *lca(Node *a,Node *b){
    expose(a);
    return expose(b);
  }
 
  void set_propagate(Node *t,E v){
    expose(t);
    propagate(t,v);
    eval(t);
  }
};
 
signed GRL_5_C(){
  int n;
  cin>>n;
  using LCT = LinkCutTree<int,int>;
  LCT::F f=[](int a,int b){return min(a,b);};
  LCT::P p=[](int a,size_t b){b++;return a;};
  LCT lc(f,f,f,p,0,0);
 
  vector<LCT::Node*> v(n);
  for(int i=0;i<n;i++) v[i]=lc.create(i,0);
  for(int i=0;i<n;i++){
    int k;
    cin>>k;
    for(int j=0;j<k;j++){
      int c;
      cin>>c;
      lc.link(v[i],v[c]);
    }
  }
   
  int q;
  cin>>q;
  for(int i=0;i<q;i++){
    int a,b;
    cin>>a>>b;
    cout<<lc.lca(v[a],v[b])->idx<<endl;
  }
   
  return 0;
}
 
//INSERT ABOVE HERE
signed main(){
  int n,q;
  scanf("%d %d",&n,&q);
 
  using T = tuple<int,int,int,int,int,int,int>;
  using P = pair<int,int>;
  using LCT = LinkCutTree<T, P>;
 
  vector<vector<int> > G(n); 
  T d1(-1,-1,-1,-1,-1,-1,-1);
  P d0(-1,-114514);
   
  vector<LCT::Node* > vs(n);     
  auto con=[&](int a,int b){return binary_search(G[a].begin(),G[a].end(),b);};
   
  auto f=[&](T a,T b){
    if(a>b) swap(a,b);
     
    if(get<0>(a)<0) return b;
    if(con(get<0>(a),get<1>(b))) swap(a,b);
    
    int al,ar,as,ava,avi,avl,avr;
    tie(al,ar,as,ava,avi,avl,avr)=a;
    int bl,br,bs,bva,bvi,bvl,bvr;
    tie(bl,br,bs,bva,bvi,bvl,bvr)=b;
     
    if(!con(ar,bl)){
      if(con(ar,br)){
    swap(bl,br);
    swap(bvl,bvr);
      }else if(con(al,bl)){
    swap(al,ar);
    swap(avl,avr);
      }else{
    return d1;
      }
    }
    int cl=al,cr=br,cs=as+bs;
    int cva=ava+bva,cvi=max(avi,bvi),cvl=avl,cvr=bvr;
    cvi=max(cvi,avr+bvl);
    cvl=max(cvl,ava+bvl);
    cvr=max(cvr,avr+bva);
     
    return T(cl,cr,cs,cva,cvi,cvl,cvr);
  };
   
  auto g=[&](T a,P p){
    if(p==d0) return a;
    int al,ar,as,ava,avi,avl,avr;
    tie(al,ar,as,ava,avi,avl,avr)=a;
    int v=p.first,b=p.second;
    if(~v) al=ar=v,as=1;
    if(b>=0) return T(al,ar,as,b*as,b*as,b*as,b*as);
    return T(al,ar,as,b*as,b,b,b);
  };
   
  auto h=[&](P a,P b){a.first++;return b;};
  auto p=[&](P a,size_t b){b++;return a;};
  LCT lct(f,g,h,p,d1,d0);
   
   
  vector<int> w(n);
  for(int i=0;i<n;i++) scanf("%d",&w[i]);
  for(int i=0;i<n;i++) vs[i]=lct.create(i,g(d1,P(i,w[i])));
   
  for(int i=0;i<n-1;i++){
    int a,b;
    scanf("%d %d",&a,&b);
    a--;b--;
    G[a].emplace_back(b);
    G[b].emplace_back(a);
    lct.evert(vs[a]);
    lct.link(vs[a],vs[b]);
  }
   
  for(int i=0;i<n;i++)
    sort(G[i].begin(),G[i].end());
   
  while(q--){
    int t,a,b,c;
    scanf("%d %d %d %d",&t,&a,&b,&c);
    a--;b--;
    if(t==1){
      lct.evert(vs[a]);
      lct.set_propagate(vs[b],P(-1,c));      
    }
    if(t==2){
      lct.evert(vs[a]);
      lct.expose(vs[b]);
      int vva,vvi,vvl,vvr;
      tie(ignore,ignore,ignore,vva,vvi,vvl,vvr)=vs[b]->dat;
      printf("%d\n",max({vva,vvi,vvl,vvr}));
    }
  }
   
  return 0;
}


Compiler output:
a.cc:4:1: error: extended character   is not valid in an identifier
    4 |  
      | ^
a.cc:7:1: error: extended character   is not valid in an identifier
    7 |   struct Node{
      | ^
a.cc:7:1: error: extended character   is not valid in an identifier
a.cc:8:1: error: extended character   is not valid in an identifier
    8 |     Node *l,*r,*p;
      | ^
a.cc:8:1: error: extended character   is not valid in an identifier
a.cc:8:1: error: extended character   is not valid in an identifier
a.cc:8:1: error: extended character   is not valid in an identifier
a.cc:9:1: error: extended character   is not valid in an identifier
    9 |     size_t cnt;
      | ^
a.cc:9:1: error: extended character   is not valid in an identifier
a.cc:9:1: error: extended character   is not valid in an identifier
a.cc:9:1: error: extended character   is not valid in an identifier
a.cc:10:1: error: extended character   is not valid in an identifier
   10 |     int idx;
      | ^
a.cc:10:1: error: extended character   is not valid in an identifier
a.cc:10:1: error: extended character   is not valid in an identifier
a.cc:10:1: error: extended character   is not valid in an identifier
a.cc:11:1: error: extended character   is not valid in an identifier
   11 |     bool rev;
      | ^
a.cc:11:1: error: extended character   is not valid in an identifier
a.cc:11:1: error: extended character   is not valid in an identifier
a.cc:11:1: error: extended character   is not valid in an identifier
a.cc:12:1: error: extended character   is not valid in an identifier
   12 |     T val,dat;
      | ^
a.cc:12:1: error: extended character   is not valid in an identifier
a.cc:12:1: error: extended character   is not valid in an identifier
a.cc:12:1: error: extended character   is not valid in an identifier
a.cc:13:1: error: extended character   is not valid in an identifier
   13 |     E laz;
      | ^
a.cc:13:1: error: extended character   is not valid in an identifier
a.cc:13:1: error: extended character   is not valid in an identifier
a.cc:13:1: error: extended character   is not valid in an identifier
a.cc:14:1: error: extended character   is not valid in an identifier
   14 |     Node():cnt(0){}
      | ^
a.cc:14:1: error: extended character   is not valid in an identifier
a.cc:14:1: error: extended character   is not valid in an identifier
a.cc:14:1: error: extended character   is not valid in an identifier
a.cc:15:1: error: extended character   is not valid in an identifier
   15 |     Node(int idx,T val,E laz):
      | ^
a.cc:15:1: error: extended character   is not valid in an identifier
a.cc:15:1: error: extended character   is not valid in an identifier
a.cc:15:1: error: extended character   is not valid in an identifier
a.cc:16:1: error: extended character   is not valid in an identifier
   16 |       cnt(1),idx(idx),rev(0),val(val),dat(val),laz(laz){l=r=p=nullptr;}
      | ^
a.cc:16:1: error: extended character   is not valid in an identifier
a.cc:16:1: error: extended character   is not valid in an identifier
a.cc:16:1: error: extended character   is not valid in an identifier
a.cc:16:1: error: extended character   is not valid in an identifier
a.cc:16:1: error: extended character   is not valid in an identifier
a.cc:17:1: error: extended character   is not valid in an identifier
   17 |     bool is_root(){
      | ^
a.cc:17:1: error: extended character   is not valid in an identifier
a.cc:17:1: error: extended character   is not valid in an identifier
a.cc:17:1: error: extended character   is not valid in an identifier
a.cc:18:1: error: extended character   is not valid in an identifier
   18 |       return !p||(p->l!=this&&p->r!=this);
      | ^
a.cc:18:1: error: extended character   is not valid in an identifier
a.cc:18:1: error: extended character   is not valid in an identifier
a.cc:18:1: error: extended character   is not valid in an identifier
a.cc:18:1: error: extended character   is not valid in an identifier
a.cc:18:1: error: extended character   is not valid in an identifier
a.cc:19:1: error: extended character   is not valid in an identifier
   19 |     }
      | ^
a.cc:19:1: error: extended character   is not valid in an identifier
a.cc:19:1: error: extended character   is not valid in an identifier
a.cc:19:1: error: extended character   is not valid in an identifier
a.cc:20:1: error: extended character   is not valid in an identifier
   20 |   };
      | ^
a.cc:20:1: error: extended character   is not valid in an identifier
a.cc:21:1: error: extended character   is not valid in an identifier
   21 |    
      | ^
a.cc:21:1: error: extended character   is not valid in an identifier
a.cc:21:1: error: extended character   is not valid in an identifier
a.cc:22:1: error: extended character   is not valid in an identifier
   22 |   using F = function<T(T,T)>;
      | ^
a.cc:22:1: error: extended character   is not valid in an identifier
a.cc:23:1: error: extended character   is not valid in an identifier
   23 |   using G = function<T(T,E)>;
      | ^
a.cc:23:1: error: extended character   is not valid in an identifier
a.cc:24:1: error: extended character   is not valid in an identifier
   24 |   using H = function<E(E,E)>;
      | ^
a.cc:24:1: error: extended character   is not valid in an identifier
a.cc:25:1: error: extended character   is not valid in an identifier
   25 |   using P = function<E(E,size_t)>;
      | ^
a.cc:25:1: error: extended character   is not valid in an identifier
a.cc:26:1: error: extended character   is not valid in an identifier
   26 |   F f;
      | ^
a.cc:26:1: error: extended character   is not valid in an identifier
a.cc:27:1: error: extended character   is not valid in an identifier
   27 |   G g;
      | ^
a.cc:27:1: error: extended character   is not valid in an identifier
a.cc:28:1: error: extended character   is not valid in an identifier
   28 |   H h;
      | ^
a.cc:28:1: error: extended character   is not valid in an identifier
a.cc:29:1: error: extended character   is not valid in an identifier
   29 |   P p;
      | ^
a.cc:29:1: error: extended character   is not valid in an identifier
a.cc:30:1: error: extended character   is not valid in an identifier
   30 |   T ti;
      | ^
a.cc:30:1: error: extended character   is not valid in an identifier
a.cc:31:1: error: extended character   is not valid in an identifier
   31 |   E ei;
      | ^
a.cc:31:1: error: extended character   is not valid in an identifier
a.cc:32:1: error: extended character   is not valid in an identifier
   32 |    
      | ^
a.cc:32:1: error: extended character   is not valid in an identifier
a.cc:32:1: error: extended character   is not valid in an identifier
a.cc:33:1: error: extended character   is not valid in an identifier
   33 |   const size_t LIM = 1e6;
      | ^
a.cc:33:1: error: extended character   is not valid in an identifier
a.cc:34:1: error: extended character   is not valid in an identifier
   34 |   vector<Node> pool;
      | ^
a.cc:34:1: error: extended character   is not valid in an identifier
a.cc:35:1: error: extended character   is not valid in an identifier
   35 |   size_t ptr;
      | ^
a.cc:35:1: error: extended character   is not valid in an identifier
a.cc:36:1: error: extended character   is not valid in an identifier
   36 |    
      | ^
a.cc:36:1: error: extended character   is not valid in an identifier
a.cc:36:1: error: extended character   is not valid in an identifier
a.cc:37:1: error: extended character   is not valid in an identifier
   37 |   LinkCutTree(F f,G g,H h,P p,T ti,E ei):
      | ^
a.cc:37:1: error: extended character   is not valid in an identifier
a.cc:38:1: error: extended character   is not valid in an identifier
   38 |     f(f),g(g),h(h),p(p),ti(ti),ei(ei),pool(LIM),ptr(0){}
      | ^
a.cc:38:1: error: extended character   is not valid in an identifier
a.cc:38:1: error: extended character   is not valid in an identifier
a.cc:38:1: error: extended character   is not valid in an identifier
a.cc:39:1: error: extended character   is not valid in an identifier
   39 |    
      | ^
a.cc:39:1: error: extended character   is not valid in an identifier
a.cc:39:1: error: extended character   is not valid in an identifier
a.cc:40:1: error: extended character   is not valid in an identifier
   40 |   inline Node* create(){
      | ^
a.cc:40:1: error: extended character   is not valid in an identifier
a.cc:41:1: error: extended character   is not valid in an identifier
   41 |     return &pool[ptr++];
      | ^
a.cc:41:1: error: extended character   is not valid in an identifier
a.cc:41:1: error: extended character   is not valid in an identifier
a.cc:41:1: error: extended character   is not valid in an identifier
a.cc:42:1: error: extended character   is not valid in an identifier
   42 |   }
      | ^
a.cc:42:1: error: extended character   is not valid in an identifier
a.cc:43:1: error: extended character   is not valid in an identifier
   43 |    
      | ^
a.cc:43:1: error: extended character   is not valid in an identifier
a.cc:43:1: error: extended character   is not valid in an identifier
a.cc:44:1: error: extended character   is not valid in an identifier
   44 |   inline Node* create(int idx,T v){
      | ^
a.cc:44:1: error: extended character   is not valid in an identifier
a.cc:45:1: error: extended character   is not valid in an identifier
   45 |     return &(pool[ptr++]=Node(idx,v,ei));
      | ^
a.cc:45:1: error: extended character   is not valid in an identifier
a.cc:45:1: error: extended character   is not valid in an identifier
a.cc:45:1: error: extended character   is not valid in an identifier
a.cc:46:1: error: extended character   is not valid in an identifier
   46 |   }
      | ^
a.cc:46:1: error: extended character   is not valid in an identifier
a.cc:47:1: error: extended character   is not valid in an identifier
   47 |  
      | ^
a.cc:48:1: error: extended character   is not valid in an identifier
   48 |   void propagate(Node *t,E v){