[luoguP1351] 联合权值(Dfs)
传送门
距离为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
上一篇:[luoguP2957] [USACO09OCT]谷仓里的回声Barn Echoes(Hash)
下一篇:[BZOJ3932] [CQOI2015]任务查询系统(主席树 || 树状数组 套 主席树 + 差分 + 离散化)
dfs 模拟
spc文件怎么看,spc文件用什么打开?
0文件怎么看,0文件用什么打开?
sparseimage文件怎么看,sparseimage文件用什么打开?
sp文件怎么看,sp文件用什么打开?
dv文件怎么看,dv文件用什么打开?
soundpack文件怎么看,soundpack文件用什么打开?
dus文件怎么看,dus文件用什么打开?
dtw文件怎么看,dtw文件用什么打开?
spdf文件怎么看,spdf文件用什么打开?
0文件怎么看,0文件用什么打开?