/ tabris /

记录详情

Runtime Error

/in/foo.cc:1:0: warning: ignoring #pragma comment  [-Wunknown-pragmas]
 #pragma comment(linker, “/STACK:1024000000,1024000000”)
 
/in/foo.cc: In function 'void dfs(int, int)':
/in/foo.cc:42:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<G[rt].size();i++)
                 ~^~~~~~~~~~~~~
# 状态 耗时 内存占用
#1 Accepted 101ms 17.105 MiB
#2 Runtime Error 55ms 16.594 MiB
#3 Accepted 4ms 5.328 MiB
#4 Accepted 11ms 5.453 MiB
#5 Accepted 4ms 5.078 MiB
#6 Accepted 4ms 4.953 MiB
#7 Accepted 117ms 20.133 MiB
#8 Accepted 26ms 7.562 MiB
#9 Accepted 119ms 17.793 MiB
#10 Accepted 140ms 21.363 MiB

代码

#pragma comment(linker, “/STACK:1024000000,1024000000”)
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string.h>
#include<map>
#include<vector>
#include<set>
#include<queue>
#include<time.h>
#include<math.h>
using namespace std;

#define ok cout<<"OK"<<endl;
#define dbg(x) cout<<#x<<" = "<<x<<endl;
#define dbg2(x1,x2) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<endl;
#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<" "<<#x3<<" = "<<x3<<endl;
#define print(a,n) for(int i=1;i<=n;i++) cout<<a[i]<<" ";cout<<endl;
#define pb push_back
#define Fi first
#define Se second
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pil pair<int,ll>
#define pll pair<ll,ll>

const double eps = 1e-8;
const double PI = acos(-1.0);
const int Mod = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const int maxn = 2e5+10;

vector<pii> G[maxn];
int dp[maxn][32];
int vis[maxn];
int sum[maxn];
void dfs(int rt,int fa)
{
    sum[rt]=1;
    for(int i=0;i<G[rt].size();i++)
    {
        int to=G[rt][i].Fi;
        int val=G[rt][i].Se;
        if(vis[to]||to==fa) continue;
        vis[to]=1;
        dfs(to,rt);
        sum[rt]+=sum[to];
        for(int j=0;j<30;j++)
        {
            if(val&(1LL<<j))
            {
                dp[rt][j]=dp[rt][j]+sum[to]-dp[to][j];
            }
            else
            {
                dp[rt][j]=dp[rt][j]+dp[to][j];
            }
        }
    }
}
int main()
{
    //freopen(".in","r",stdin);
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n-1;i++)
    {
        int u,v,w;
        scanf("%d%d%d",&u,&v,&w);
        G[u].push_back(pii(v,w));
        G[v].push_back(pii(u,w));
    }
    for(int i=1;i<=n;i++) sum[i]=0;
    vis[1]=1;
    dfs(1,-1);
    for(int i=1;i<=n;i++)
    {
        ll ans=0;
        for(int j=0;j<30;j++)
        {
            ans=(ans+1LL*dp[i][j]*(sum[i]-dp[i][j])%Mod*(1LL<<j)%Mod)%Mod;
        }
        printf("%lld ",ans);
    }
    return 0;
}

信息

递交者
类型
递交
语言
C++
递交时间
2019-06-10 12:52:54
评测时间
2019-06-10 12:52:54
评测机
分数
90
总耗时
586ms
峰值内存
21.363 MiB