Submission #1884075


Source Code Expand

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

const int N=1e5+10;
int n;
int v[N][2],w[N];

int gr[N];
bool comp(int x,int y){
        return w[x]>w[y];
}
ll f[N];
ll fcom[N];
int p[N];
vector <int> imp[N];
int main(){
        cin>>n;
        for(int i=1;i<n;i++)
                cin>>v[i][0]>>v[i][1]>>w[i];
        for(int i=1;i<n;i++) p[i]=i;
        sort(p+1,p+n,comp);
        

        for(int i=1;i<=n;i++){
                gr[i]=i;
                imp[i].push_back(i);
        }

        for(int i=1;i<n;i++){
                int use=p[i];
                int x=gr[v[use][0]],y=gr[v[use][1]];
                if (imp[x].size()>imp[y].size()) swap(x,y);
                fcom[x]+=1LL*imp[y].size()*w[use];
                fcom[y]+=1LL*imp[x].size()*w[use];
                for(auto per:imp[x]){
                        f[per]+=fcom[x]-fcom[y];
                        gr[per]=y;
                        imp[y].push_back(per);
                }
        }
        for(int i=1;i<=n;i++) cout<<f[i]+fcom[gr[i]]<<"\n";
}

Submission Info

Submission Time
Task E - Black Cats Deployment
User tanphatls987
Language C++14 (GCC 5.4.1)
Score 800
Code Size 1090 Byte
Status AC
Exec Time 177 ms
Memory 13944 KB

Judge Result

Set Name Sample Subtask1 Subtask2 All
Score / Max Score 0 / 0 200 / 200 200 / 200 400 / 400
Status
AC × 3
AC × 10
AC × 9
AC × 32
Set Name Test Cases
Sample 00_example_01.txt, 00_example_02.txt, 00_example_03.txt
Subtask1 00_example_01.txt, 00_example_02.txt, 00_example_03.txt, s1_01.txt, s1_02.txt, s1_03.txt, s1_04.txt, s1_05.txt, s1_06.txt, s1_07.txt
Subtask2 00_example_02.txt, s1_07.txt, s2_08.txt, s2_09.txt, s2_10.txt, s2_11.txt, s2_12.txt, s2_13.txt, s2_14.txt
All 00_example_01.txt, 00_example_02.txt, 00_example_03.txt, s1_01.txt, s1_02.txt, s1_03.txt, s1_04.txt, s1_05.txt, s1_06.txt, s1_07.txt, s2_08.txt, s2_09.txt, s2_10.txt, s2_11.txt, s2_12.txt, s2_13.txt, s2_14.txt, s3_15.txt, s3_16.txt, s3_17.txt, s3_18.txt, s3_19.txt, s3_20.txt, s3_21.txt, s3_22.txt, s3_23.txt, s3_24.txt, s3_25.txt, s3_26.txt, s3_27.txt, s3_28.txt, s3_29.txt
Case Name Status Exec Time Memory
00_example_01.txt AC 3 ms 4352 KB
00_example_02.txt AC 3 ms 4352 KB
00_example_03.txt AC 3 ms 4352 KB
s1_01.txt AC 3 ms 4352 KB
s1_02.txt AC 3 ms 4352 KB
s1_03.txt AC 3 ms 4352 KB
s1_04.txt AC 4 ms 4352 KB
s1_05.txt AC 4 ms 4352 KB
s1_06.txt AC 4 ms 4480 KB
s1_07.txt AC 2 ms 4352 KB
s2_08.txt AC 109 ms 10332 KB
s2_09.txt AC 54 ms 7216 KB
s2_10.txt AC 32 ms 6144 KB
s2_11.txt AC 126 ms 11128 KB
s2_12.txt AC 126 ms 11044 KB
s2_13.txt AC 126 ms 12024 KB
s2_14.txt AC 122 ms 12536 KB
s3_15.txt AC 152 ms 10940 KB
s3_16.txt AC 75 ms 7676 KB
s3_17.txt AC 43 ms 6272 KB
s3_18.txt AC 73 ms 7420 KB
s3_19.txt AC 169 ms 11768 KB
s3_20.txt AC 174 ms 12280 KB
s3_21.txt AC 173 ms 11768 KB
s3_22.txt AC 169 ms 11768 KB
s3_23.txt AC 177 ms 13944 KB
s3_24.txt AC 166 ms 13560 KB
s3_25.txt AC 154 ms 11256 KB
s3_26.txt AC 165 ms 13372 KB
s3_27.txt AC 154 ms 11256 KB
s3_28.txt AC 167 ms 13436 KB
s3_29.txt AC 154 ms 11256 KB