Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /***** TheAnshul *****/
- #include<bits/stdc++.h>
- #define ll long long
- #define pb push_back
- #define ppb pop_back
- #define endl '\n'
- #define mii map<ll int,ll int>
- #define msi map<string,ll int>
- #define mis map<ll int, string>
- #define rep(i,a,b) for(ll int i=a;i<b;i++)
- #define mpi map<pair<ll int,ll int>,ll int>
- #define pii pair<ll int,ll int>
- #define vi vector<ll int>
- #define vii vector<pair<ll int, ll int>>
- #define vs vector<string>
- #define all(a) (a).begin(),(a).end()
- #define F first
- #define S second
- #define sz(x) (ll int)x.size()
- #define hell 1000000007
- #define lbnd lower_bound
- #define ubnd upper_bound
- #define bs binary_search
- #define mp make_pair
- #define what_is(x) cerr << #x << " is " << x << endl;
- using namespace std;
- #define N 200005
- vi a[N];
- bool vis[N];
- ll ans;
- ll n;
- ll dfs(ll node)
- {
- ll vl=(n-1)*(n-1),p=0;
- vis[node]=1;
- for(auto i:a[node])
- {
- if(!vis[i])
- {
- ll d;
- d=dfs(i);
- vl-=d*d;
- p+=d;
- }
- }
- // cout<<"*********\n";
- // what_is(node);what_is(p);what_is(vl);
- // cout<<"*********\n";
- vl-=(n-1-p)*(n-1-p);
- ans+=(vl/2);
- return p+1;
- }
- int main()
- {
- ios_base::sync_with_stdio(false);
- cin.tie(0);
- cout.tie(0);
- int TESTS=1;
- // cin>>TESTS;
- while(TESTS--)
- {
- cin>>n;
- ll x,y;
- rep(i,0,n-1)
- {
- cin>>x>>y;
- a[x].pb(y);
- a[y].pb(x);
- }
- dfs(1);
- cout<<ans+n*(n-1);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement