zoukankan      html  css  js  c++  java
  • 1036

    未完待续

      1 #include <bits/stdc++.h>
      2 
      3 using namespace std;
      4 
      5 const int N = 30100;
      6 
      7 int read(){
      8     int x = 0;char ch = getchar();
      9     while (ch < '0' || '9' < ch) ch = getchar();
     10     while ('0' <= ch && ch <= '9') x = x * 10 + ch - '0',ch = getchar();
     11     return x;
     12 }
     13 int getch(){
     14     char ch = getchar();
     15     while (ch != 'A' && ch != 'S' && ch != 'C') ch = getchar();
     16     if (ch == 'A') return 0;
     17     if (ch == 'S') return 1;
     18     if (ch == 'C') return 2;
     19 }
     20 
     21 
     22 struct Node{
     23     int son[2],fa,mx,sum,val;
     24 };
     25 struct Edge{
     26     int next,end;
     27 }edge[N<<1];
     28 
     29 
     30 int a[N],first[N],efn;
     31 struct Lct{
     32     int ncnt;
     33     Node nod[N];
     34     void init(int p){
     35         ncnt = p;
     36         for (int i = 1;i <= p;i++){
     37             Node&g = nod[i];
     38             g.son[0] = g.son[1] = g.fa = 0;
     39             g.mx = g.sum = g.val = a[i];
     40         }
     41     }
     42     void update(int p){
     43         Node&g = nod[p];
     44         int u = g.son[0],v = g.son[1];
     45         g.sum = g.val+nod[u].sum+nod[v].sum;
     46         g.mx = max(g.mx,max(nod[u].mx,nod[v].mx));
     47     }
     48     void splay(int x){
     49         while (check(x) != -1){
     50             int y = nod[x].fa;int u = check(x);
     51             if (check(y) == u) rotate(y,u^1);
     52             rotate(x,u^1);
     53         }
     54     }
     55     int check(int p){
     56         int u = nod[p].fa;
     57         if (u == 0) return -1;
     58         if (nod[u].son[0] == p) return 0;
     59         if (nod[u].son[1] == p) return 1;
     60         return -1;
     61     }
     62     void rotate(int x,int d){
     63         int y = nod[x].fa,z = check(y);
     64         nod[x].fa = nod[y].fa;
     65         if (z != -1) nod[nod[y].fa].son[z] = x;
     66         nod[y].fa = x;
     67         nod[y].son[d^1] = nod[x].son[d];
     68         if (nod[x].son[d]) nod[nod[x].son[d]].fa = y;
     69         nod[x].son[d] = y;
     70         update(y);
     71         update(x);
     72     }
     73     
     74     
     75 }lct;
     76 
     77 int n;
     78 void addedge(int,int);
     79 int main(){
     80     n = read();
     81     for (int i = 1;i < n;i++){
     82         int x = read(),y = read();
     83         addedge(x,y);
     84     }
     85     for (int i = 1;i <= n;i++) a[i] = read();
     86     lct.init(n);
     87     dfs(1,0);
     88     m = read();
     89     for (int i = 1;i <= m;i++){
     90         int opt = getch();
     91         if (opt == 0){
     92         }
     93         else if (opt == 1){
     94         }
     95         else{
     96             int x,y;x = read();y = read();
     97             lct.change(x,y);
     98         }
     99     }
    100     return 0;
    101 }
    102 void addedge(int x,int y){
    103     edge[++efn].end = y;
    104     edge[  efn].next = first[x];
    105     first[x] = efn;
    106     edge[++efn].end = x;
    107     edge[  efn].next = first[y];
    108     first[y] = efn;    
    109 }
  • 相关阅读:
    700. Search in a Binary Search Tree
    100. Same Tree
    543. Diameter of Binary Tree
    257. Binary Tree Paths
    572. Subtree of Another Tree
    226. Invert Binary Tree
    104. Maximum Depth of Binary Tree
    1、解决sublime打开文档,出现中文乱码问题
    移植seetafaceengine-master、opencv到ARM板
    ubuntu16.04-交叉编译-SeetaFaceEngine-master
  • 原文地址:https://www.cnblogs.com/victbr/p/6711075.html
Copyright © 2011-2022 走看看