hihoCoder Challenge 27 register

Ended

Participants:323

Verdict:Accepted
Submitted:2017-02-19 19:35:50

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<bits/stdc++.h>
#define N 200005
#define ll long long
#define mod 1000000007
using namespace std;
int n,m,cnt,tot,a[N],fac[N],inv[N],fst[N],pnt[N],nxt[N],d[N],fa[N],sz[N],lf[N],rg[N],dfsclk;
void add(int x,int y){
    pnt[++tot]=y;nxt[tot]=fst[x];fst[x]=tot;
}
void dfs(int x){
    int i,y; sz[x]=1; lf[x]=++dfsclk;
    for (i=fst[x]; i; i=nxt[i]){
        y=pnt[i];
        if (y!=fa[x]){
            fa[y]=x; d[y]=d[x]+1; dfs(y); sz[x]+=sz[y];
        }
    }
    rg[x]=dfsclk;
}
bool cmp(int x,int y){ return d[x]>d[y]; }
bool isanc(int x,int y){ return lf[x]<=lf[y] && rg[y]<=rg[x]; }
int main(){
    scanf("%d%d",&n,&m);
    int i,x,y;
    fac[0]=inv[0]=inv[1]=1;
    for (i=1; i<=n*2; i++) fac[i]=(ll)fac[i-1]*i%mod;
    for (i=2; i<=n*2; i++) inv[i]=mod-(ll)inv[mod%i]*(mod/i)%mod;
    for (i=1; i<=n*2; i++) inv[i]=(ll)inv[i-1]*inv[i]%mod;
    for (i=1; i<n; i++){
        scanf("%d%d",&x,&y);
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX