传送门
距离为2的点会产生权值,第一问,只需要在dfs的时候把一个点相邻的点都处理出来就行。
具体处理方式看代码,然而这样只处理了一遍,最后在乘2就好了。
第二问只需要处理一个点相邻的点中最大的和次大的就行。
——代码
1 #include <cstdio> 2 #include <cstring> 3 #include <iostream> 4 #define LL long long 5 6 const int MAXN = 200001, p = 10007; 7 int n, cnt; 8 int head[MAXN], to[MAXN << 1], next[MAXN << 1]; 9 LL max, tot, a[MAXN], sum[MAXN], ans[MAXN], max1[MAXN], max2[MAXN]; 10 bool vis[MAXN]; 11 12 inline int read() 13 20 21 inline LL Max(LL x, LL y) 22 25 26 inline void add(int x, int y) 27 32 33 inline void dfs(int u) 34 46 } 47 48 int main() 49 60 for(i = 1; i <= n; i++) a[i] = read(); 61 dfs(1); 62 for(i = 1; i <= n; i++) 67 printf("%lld %lld\n", max, (tot << 1) % p); 68 return 0; 69 }View Code
上一篇:[BZOJ3932] [CQOI2015]任务查询系统(主席树 || 树状数组 套 主席树 + 差分 + 离散化)
下一篇:高精度
dfs 模拟









