/ tabris /

记录详情

Compile Error

/in/foo.cc: In function 'void dfs(int, int)':
/in/foo.cc:18:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i=0; i<t[u].size(); i++) {
                   ~^~~~~~~~~~~~
/in/foo.cc: In function 'void sum01(int, int)':
/in/foo.cc:31:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i=0; i<t[u].size(); i++) {
                   ~^~~~~~~~~~~~
/in/foo.cc: In function 'void solve(int, int)':
/in/foo.cc:42:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i=0; i<t[u].size(); i++) {
                   ~^~~~~~~~~~~~
/in/foo.cc: At global scope:
/in/foo.cc:64:33: error: ISO C++ forbids declaration of 'addedge' with no type [-fpermissive]
 inline addedge(int u,int v,int w){
                                 ^
/in/foo.cc: In function 'int addedge(int, int, int)':
/in/foo.cc:69:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^

代码

#include <bits/stdc++.h>
#define nmax 100005
#define m 1000000007

using namespace std;
typedef long long ll;
int n,ie=-1;
vector <int> t[nmax];
int x[nmax];
ll ans[nmax]={0};
int n0[nmax][31],n1[nmax][31];  //最多有31位

struct edge{
    int v,w;
}e[nmax*2];

void dfs(int fa,int u){
    for (int i=0; i<t[u].size(); i++) {
        edge ue=e[ t[u][i] ];
        if(ue.v==fa) continue;
        x[ue.v]=x[u]^ue.w;
        dfs(u,ue.v);
    }
}

void sum01(int fa,int u){  //统计每一个子树每一位的01个数
    for (int i=0; i<31; i++) {
        if( (1<<i) & x[u] )  {  n0[u][i]=0; n1[u][i]=1; }
        else                 {  n0[u][i]=1; n1[u][i]=0; }
    }
    for (int i=0; i<t[u].size(); i++) {
        int v=e[ t[u][i] ].v;
        if(v==fa) continue;
        sum01(u,v);
        for (int i=0; i<31; i++) { n0[u][i]+=n0[v][i]; n1[u][i]+=n1[v][i]; }
    }
}

void solve(int fa,int u){  //算贡献求解  别忘了取模quq
    int tmp0[31],tmp1[31];
    for (int i=0; i<31; i++) { tmp0[i]=n0[u][i]; tmp1[i]=n1[u][i]; }
    for (int i=0; i<t[u].size(); i++) {
        int v=e[ t[u][i] ].v;
        if(v==fa) continue;
        solve(u,v);
        for (int i=0; i<31; i++) { tmp0[i]-=n0[v][i];  tmp1[i]-=n1[v][i];  }

        //for (int i=0; i<31; i++) { cout<<u<<' '<<tmp0[i]<<' '<<tmp1[i]<<endl;  }

        //按位算贡献,得出ans
        for (int i=0; i<31; i++) {
            ll c=(1<<i)%m;
            ll tmp=n0[v][i]*tmp1[i]+n1[v][i]*tmp0[i];
            tmp%=m;
            ans[u]+=( (tmp*c)%m );
            ans[u]%=m;
           // printf("tmp=%d,u=%d,ans[%d]=%d\n",tmp,u,u,ans[u]);
        }
        ans[u]+=ans[v];
        ans[u]%=m;
    }
}

inline addedge(int u,int v,int w){
    ie++;
    t[u].push_back(ie);
    e[ie].v=v;
    e[ie].w=w;
}

int main(){

//    freopen("10.in","r",stdin);
//    freopen("quq.txt","w",stdout);

    cin>>n;
    int a,b,c;
    for (int i=1; i<n; i++) {
        scanf("%d%d%d",&a,&b,&c);
        addedge(a,b,c);
        addedge(b,a,c);
    }
    x[1]=0;
    dfs(0,1);
    sum01(0,1);
    solve(0,1);

    for (int i=1; i<=n; i++)  printf("%lld ",ans[i]);
       // for (int j=0; j<31; j++) cout<<n0[i][j]<<' '<<n1[i][j]<<endl;


    return 0;
}

信息

递交者
类型
递交
语言
C++
递交时间
2019-06-11 14:57:15
评测时间
2019-06-11 14:57:15
评测机
分数
0
总耗时
0ms
峰值内存
0 Bytes