[弱校联萌2016]2016弱校联盟十一专场10.3
2016-10-03 17:19
363 查看
比赛链接:https://www.bnuoj.com/v3/contest_show.php?cid=8504#info
A.找两个数乘积是连续上升并且最大的。
E
A.找两个数乘积是连续上升并且最大的。
1 #include <bits/stdc++.h> 2 using namespace std; 3 4 typedef long long LL; 5 typedef unsigned long long ULL; 6 const ULL mod = ULL(1e9+7); 7 const int maxn = 100100; 8 int n; 9 vector<int> G[maxn]; 10 map<ULL, LL> h; 11 map<ULL, LL>::iterator it; 12 13 ULL dfs(int p, int u) { 14 ULL hs = 0; 15 for(int i = 0; i < G[u].size(); i++) { 16 int v = G[u][i]; 17 if(v == p) continue; 18 hs += dfs(u, v); 19 } 20 hs *= mod; 21 h[++hs]++; 22 return hs; 23 } 24 25 int main() { 26 //freopen("in", "r", stdin); 27 int u, v; 28 while(~scanf("%d",&n)) { 29 h.clear(); 30 for(int i = 1; i <= n; i++) G[i].clear(); 31 for(int i = 0; i < n-1; i++) { 32 scanf("%d%d",&u,&v); 33 G[u].push_back(v); 34 G[v].push_back(u); 35 } 36 dfs(-1, 1); 37 LL ret = 0; 38 for(it = h.begin(); it != h.end(); it++) ret += (it->second * it->second); 39 cout << (ret - n) / 2 << endl; 40 } 41 return 0; 42 }
E
相关文章推荐
- [弱校联萌2016]2016弱校联盟十一专场10.2
- [弱校联萌2016]2016弱校联盟十一专场10.5
- 2016弱校联盟十一专场10.3 A Best Matched Pair(水)
- (2016弱校联盟十一专场10.3) A.Best Matched Pair
- (2016弱校联盟十一专场10.3) D Parentheses
- 2016弱校联盟十一专场10.3(12点场)
- 2016弱校连萌十一专场10.3 部分题解
- (2016弱小联盟十一专场10.3)Parentheses 找规律
- (2016弱小联盟十一专场10.3) Best Matched Pair 暴力
- 2016弱校联盟十一专场10.3,BNU52308,大模拟
- (2016弱小联盟十一专场10.3) Help the Princess! BFS
- 2016弱校联盟十一专场10.3---Similarity of Subtrees(深搜+hash、映射)
- 2016弱校联盟十一专场10.3 We don't wanna work!
- (2016 弱校联盟十一专场10.3) Similarity of Subtrees DFS + hash
- 2016弱校联盟十一专场10.3---We don't wanna work!(STL--set的使用)
- 2016弱校联盟十一专场10.3 We don't wanna work!
- 2016弱校联盟十一专场10.3 C. We don't wanna work!(集合操作)
- 2016弱校联盟十一专场10.2——Floyd-Warshall
- 2016弱校联盟十一专场10.5(12点场) Increasing or Decreasing
- (2016弱校联盟十一专场10.2) A.Nearest Neighbor Search