题解

1 条题解

  • 0
    @ 2017-08-20 21:38:42

    ------------------------------------------------AC code------------------------------------------------

    #include<cstdio>
    #include<cmath>
    
    using namespace std;
    
    typedef long long LL;
    const int MAXN = 1000005;
    int n, x, y, ans;
    
    struct Edge{
        int nxt, to;
    }edge[MAXN<<1];
    
    int head[MAXN], edge_num;
    void add_edge(int from, int to){
        edge[++edge_num].nxt = head[from];
        edge[edge_num].to = to;
        head[from] = edge_num;
    }
    
    int sz[MAXN];
    void dfs(int x, int f){
        sz[x] = 1;
        for(int i = head[x]; i; i = edge[i].nxt){
            if(edge[i].to == f) continue;
            dfs(edge[i].to, x);
            sz[x] += sz[edge[i].to];
        }
    }
    
    int main(){
        scanf("%d", &n);
        for(int i = 1; i < n; i++){
            scanf("%d%d", &x, &y);
            add_edge(x, y);
            add_edge(y, x);
        }
        dfs(1, 0);
        ans = 2;
        for(int i = 2; i <= sqrt(n); i++){
            int cnt = 0, num = n/i;
            if(n % i == 0){
                for(int j = 1; j <= n; j++)
                    if(sz[j] % i == 0)
                        cnt++;
                if(cnt >= num)  ans++;
                if(i * i == n)  continue;
                cnt = 0, num = i;
                for(int j = 1; j <= n; j++)
                    if(sz[j] % (n/i) == 0)
                        cnt++;
                if(cnt >= num)  ans++;
            }
        }
        printf("%d", ans);
        return 0;
    }
    
  • 1

信息

难度
(无)
分类
(无)
标签
递交数
0
已通过
0
通过率
?
上传者