Advertisement
Guest User

Untitled

a guest
Sep 19th, 2017
6,715
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.46 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4. vector<int> v[100005];
  5. long long cnt[2];
  6. void dfs(int node,int pnode,int color)
  7. {
  8.     cnt[color]++;
  9.     for (int i=0;i<v[node].size();i++)
  10.     {
  11.         if (v[node][i]!=pnode)
  12.         dfs(v[node][i],node,!color);
  13.     }
  14. }
  15. int main()
  16. {
  17.     int n;
  18.     scanf("%d",&n);
  19.     for (int i=1;i<n;i++)
  20.     {
  21.         int a,b;
  22.         scanf("%d%d",&a,&b);
  23.         v[a].push_back(b);
  24.         v[b].push_back(a);
  25.     }
  26.     dfs(1,0,0);
  27.     printf("%I64d",cnt[0]*cnt[1]-n+1);
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement