hdu 2586 How far away ?倍增LCA
阿新 • • 發佈:2017-11-22
printf truct != algorithm for sin can -i cnblogs
hdu 2586 How far away ?倍增LCA
題目鏈接
http://acm.hdu.edu.cn/showproblem.php?pid=2586
思路:
- 針對詢問次數多的時候,采取倍增求取LCA,同時跟新距離數組
- 因為
- \(2^{16} > 40000\)
- 所以所以表示祖先的數組dp[][]第二維取到16即可
就這道題來說,與比較tarjan比較,稍快一點
代碼:
#include <iostream> #include <algorithm> #include <stdio.h> #include <string.h> #include <math.h>
hdu 2586 How far away ?倍增LCA