Submission #2667937


Source Code Expand

#include<bits/stdc++.h>

using namespace std;

#define int long long
#define pb push_back

struct data{
	int x , y , val;
};
const int N = 1e5 + 1;

int n , pa[N] , ans[N] ,lazy[N];
vector<data> inp;
vector<int> par[N];

bool how_sort(data a , data b){
	return a.val > b.val;
}
signed main(){
	cin >> n;
	pa[n] = n; par[n].pb(n);
	for(int i = 1 ; i < n ; ++ i){
		pa[i] = i ; par[i].pb(i);
		int u , v , w;
		cin >> u >> v >> w;
		inp.pb( data{ u , v , w });
	}	
	sort(inp.begin() , inp.end() , how_sort);
	for(int i = 0 ; i < inp.size() ; ++ i){
		int u = inp[i].x , v = inp[i].y , w = inp[i].val; 
		if(par[pa[u]].size() > par[pa[v]].size()) swap(u,v);
		int z = pa[u];
		lazy[pa[v]] += w * par[z].size();
		int add = w * par[pa[v]].size();
		for(int i = 0 ;i < par[z].size() ; ++ i){
			int k = par[z][i];
			pa[k] = pa[v];
			par[pa[v]].pb(k);
			ans[k] += lazy[z] - lazy[pa[v]] + add;
		}
	}
	for(int i = 0 ;i < par[pa[1]].size() ; ++ i){
		int k = par[pa[1]][i];
		ans[k] += lazy[pa[1]];
	}
	for(int i = 1 ; i <= n ; ++ i)
		cout << ans[i] << "\n";
}

Submission Info

Submission Time
Task E - Black Cats Deployment
User vjudge3
Language C++14 (GCC 5.4.1)
Score 800
Code Size 1056 Byte
Status AC
Exec Time 159 ms
Memory 19760 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 4480 KB
s1_05.txt AC 4 ms 4480 KB
s1_06.txt AC 4 ms 4480 KB
s1_07.txt AC 3 ms 4352 KB
s2_08.txt AC 100 ms 14128 KB
s2_09.txt AC 50 ms 8628 KB
s2_10.txt AC 28 ms 6840 KB
s2_11.txt AC 113 ms 14640 KB
s2_12.txt AC 115 ms 15024 KB
s2_13.txt AC 116 ms 16048 KB
s2_14.txt AC 112 ms 17072 KB
s3_15.txt AC 127 ms 14256 KB
s3_16.txt AC 63 ms 9140 KB
s3_17.txt AC 37 ms 6840 KB
s3_18.txt AC 62 ms 8756 KB
s3_19.txt AC 144 ms 15536 KB
s3_20.txt AC 147 ms 16048 KB
s3_21.txt AC 144 ms 14768 KB
s3_22.txt AC 144 ms 15408 KB
s3_23.txt AC 159 ms 19760 KB
s3_24.txt AC 147 ms 19120 KB
s3_25.txt AC 129 ms 14384 KB
s3_26.txt AC 145 ms 18736 KB
s3_27.txt AC 131 ms 13616 KB
s3_28.txt AC 144 ms 18096 KB
s3_29.txt AC 131 ms 13616 KB