hiho week 112 register

Ended

Participants:443

Verdict:Accepted
Score:100 / 100
Submitted:2016-08-26 14:39:28

Lang:G++

Edit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;
#define MAXN 100010
#define MAXM 50010
#define ll long long
using namespace std;
vector<pair<int, int>> ma[MAXN];
int m, e[MAXM << 1], nx[MAXM << 1], ed[MAXN], cnt, f[MAXN], path[MAXN], v[MAXM << 1], siz[MAXN], n;
int flag = 0;
int vis[MAXN];
int huan[MAXN];
ll ans;
ll calc(int y)// fa = x   , son = y
{
    return (ll) siz[y] * ((ll) n - (ll) siz[y]);
}
void dfs(int p, int fa) {
    vis[p] = vis[fa] + 1;
    siz[p] = 1;
    int i = ed[p];
    for (int j = 0; j < ma[p].size(); ++j) {
        int tempe = ma[p][j].first;
        if (tempe != fa && !vis[tempe]) {
            dfs(tempe, p);
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX