Submission #7915054


Source Code Expand

Copy
#include<bits/stdc++.h>
using namespace std;
namespace mine
{
    typedef long long ll;
    #define pr pair<int,int>
    #define FR first
    #define SE second
    #define MP make_pair
    #define PB push_back
    #define vc vector
    #define all(x) (x).begin(),(x).end()
    #define sz(x) ((int)(x).size())
    #define bin(x) (1ll<<(x))
    #define GG(x) if(x) {puts("error");exit(666);}
    #define fo(i,l,r) for(int i=(l),I=(r);i<=I;i++)
    #define fd(i,r,l) for(int i=(r),I=(l);i>=I;i--)
    ll qread()
    {
        ll ans=0,f=1;char c=getchar();
        while(c<'0' or c>'9') {if(c=='-')f=-1;c=getchar();}
        while('0'<=c and c<='9') ans=ans*10+c-'0',c=getchar();
        return ans*f;
    }
    void write(ll num)
    {
        if(num<0) putchar('-'),num=-num;
        if(num>=10) write(num/10);
        putchar('0'+num%10);
    }
    void write1(ll num){write(num);putchar(' ');}
    void write2(ll num){write(num);putchar('\n');}
    template<typename T> void chmax(T &x,const T y) {x=(x>y?x:y);}
    template<typename T> void chmin(T &x,const T y) {x=(x<y?x:y);}
    ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}

    const int INF=0x3f3f3f3f;
    const int MOD=1e9+7;
    inline int mm(const int x){return x>=MOD?x-MOD:x;}
    template<typename T> inline void add(T &x,const T y){x=mm(x+y);}
    inline ll qpower(ll x,ll e,int mod=MOD){ll ans=1;GG(e<0)while(e){if(e&1)ans=ans*x%mod;x=x*x%mod;e>>=1;}return ans;}
    ll invm(ll x){return qpower(x,MOD-2);}
    const int N=1e5+10;

    vc<int> pt;int pos[N];
    int deg[N];bool cmp(int x,int y){return deg[x]<deg[y];}

    ll g3[N],g4[N];
    vc<int> bb[N],to[N];
    bool vis[N];
    void calc3(int n)
    {
        for(auto x:pt)
        {
            for(auto y:bb[x]) vis[y]=1;
            for(auto y:bb[x]) for(auto z:bb[y])
                if(vis[z]) g3[x]++,g3[y]++,g3[z]++;
            for(auto y:bb[x]) vis[y]=0;
        }
    }
    ll cc[N];
    void calc4(int n)
    {
        for(auto x:pt)
        {
            for(auto y:to[x]) if(pos[y]<pos[x]) for(auto z:to[y])
                if(pos[z]<pos[x]) g4[x]+=cc[z],g4[y]+=cc[z],g4[z]+=cc[z],cc[z]++;
            for(auto y:to[x]) if(pos[y]<pos[x]) for(auto z:to[y])
                if(pos[z]<pos[x]) cc[z]--,g4[y]+=cc[z];
        }
    }
    ll f[N][5];
    void main()
    {
        int n=qread(),m=qread();
        while(m--){int x=qread(),y=qread();deg[x]++,deg[y]++;to[x].PB(y);to[y].PB(x);}
        fo(x,1,n) pt.PB(x);sort(all(pt),cmp);fo(t,0,sz(pt)-1) pos[pt[t]]=t;
        fo(x,1,n) for(auto y:to[x]) if(pos[x]<pos[y]) bb[x].PB(y);
        calc3(n);calc4(n);

        fo(x,1,n) f[x][1]=deg[x];
        fo(x,1,n) for(auto y:to[x]) f[x][2]+=f[y][1]-1;
        fo(x,1,n) {for(auto y:to[x]) f[x][3]+=f[y][2]-(deg[x]-1);f[x][3]-=g3[x]*2;}
        fo(x,1,n)
        {
            for(auto y:to[x]) f[x][4]+=f[y][3];
            f[x][4]-=g4[x]*2+g3[x]*(deg[x]-2)*2+(f[x][2]*(deg[x]-1)-g3[x]*2);
            write2(f[x][4]);
        }
    }
};//(ans+MOD)%MOD
signed main()
{
    srand(time(0));
    mine::main();
}

Submission Info

Submission Time
Task H - デバッグ(Debug)
User Zory
Language C++14 (GCC 5.4.1)
Score 140
Code Size 3134 Byte
Status
Exec Time 381 ms
Memory 18424 KB

Judge Result

Set Name subtask_1 subtask_2
Score / Max Score 10 / 10 130 / 130
Status
× 5
× 21
Set Name Test Cases
subtask_1 subtask_1_1_1_120.txt, subtask_1_1_2_110.txt, subtask_1_1_5_102.txt, subtask_1_3_100.txt, subtask_1_4_100.txt
subtask_2 sample1.txt, sample2.txt, sample3.txt, subtask_1_1_1_120.txt, subtask_1_1_2_110.txt, subtask_1_1_5_102.txt, subtask_1_3_100.txt, subtask_1_4_100.txt, subtask_2_1_1_1010.txt, subtask_2_1_1_210.txt, subtask_2_1_1_510.txt, subtask_2_1_2_1010.txt, subtask_2_1_2_210.txt, subtask_2_1_2_510.txt, subtask_2_1_5_1010.txt, subtask_2_1_5_210.txt, subtask_2_1_5_510.txt, subtask_2_3_446.txt, subtask_2_3_447.txt, subtask_2_4_74899.txt, subtask_2_4_74999.txt
Case Name Status Exec Time Memory
sample1.txt 3 ms 8448 KB
sample2.txt 3 ms 8448 KB
sample3.txt 3 ms 8448 KB
subtask_1_1_1_120.txt 4 ms 8448 KB
subtask_1_1_2_110.txt 4 ms 8448 KB
subtask_1_1_5_102.txt 3 ms 8448 KB
subtask_1_3_100.txt 8 ms 8576 KB
subtask_1_4_100.txt 3 ms 8448 KB
subtask_2_1_1_1010.txt 64 ms 17656 KB
subtask_2_1_1_210.txt 53 ms 12032 KB
subtask_2_1_1_510.txt 56 ms 14588 KB
subtask_2_1_2_1010.txt 65 ms 17020 KB
subtask_2_1_2_210.txt 51 ms 12032 KB
subtask_2_1_2_510.txt 55 ms 14588 KB
subtask_2_1_5_1010.txt 45 ms 18424 KB
subtask_2_1_5_210.txt 50 ms 12032 KB
subtask_2_1_5_510.txt 52 ms 15100 KB
subtask_2_3_446.txt 378 ms 9984 KB
subtask_2_3_447.txt 381 ms 9984 KB
subtask_2_4_74899.txt 50 ms 17268 KB
subtask_2_4_74999.txt 48 ms 17268 KB