Submission #3010205


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef long double llf;
typedef pair<int, int> pi;
const int mod = 1e9 + 7;
const int MAXN = 100005;

lint dap[MAXN];

struct disj{
	int pa[MAXN], sz[MAXN];
	lint offset[MAXN];
	vector<int> nd[MAXN];
	void init(int n){
		for(int i=1; i<=n; i++){
			pa[i] = i;
			sz[i] = 1;
			nd[i].push_back(i);
		}
	}
	int find(int x){
		return pa[x] = (pa[x] == x ? x : find(pa[x]));
	}
	bool uni(int p, int q, lint x){
		p = find(p);
		q = find(q);
		if(sz[p] < sz[q]) swap(p, q);
		pa[q] = p;
		offset[p] += sz[q] * x;
		for(auto &i : nd[q]){
			dap[i] += sz[p] * x + offset[q];
			dap[i] -= offset[p];
			nd[p].push_back(i);
		}
		sz[p] += sz[q];
		return 1;
	}
}disj;

struct edg{
	int s, e, x;
	bool operator<(const edg &e)const{
		return x > e.x;
	}
}v[MAXN];

int main(){
	int n;
	scanf("%d",&n);
	for(int i=1; i<n; i++){
		int s, e, x;
		scanf("%d %d %d",&s,&e,&x);
		v[i] = {s, e, x};
	}
	sort(v+1, v+n);
	disj.init(n);
	for(int i=1; i<n; i++){
		disj.uni(v[i].s, v[i].e, v[i].x);
	}
	lint f = disj.offset[disj.find(1)];
	for(int i=1; i<=n; i++) printf("%lld\n",f +  dap[i]);
}

Submission Info

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

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:50:16: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&n);
                ^
./Main.cpp:53:29: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d %d",&s,&e,&x);
                             ^

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 2 ms 3328 KB
00_example_02.txt AC 2 ms 3328 KB
00_example_03.txt AC 2 ms 3328 KB
s1_01.txt AC 3 ms 3328 KB
s1_02.txt AC 3 ms 3328 KB
s1_03.txt AC 3 ms 3328 KB
s1_04.txt AC 3 ms 3328 KB
s1_05.txt AC 3 ms 3328 KB
s1_06.txt AC 3 ms 3328 KB
s1_07.txt AC 2 ms 3328 KB
s2_08.txt AC 50 ms 10332 KB
s2_09.txt AC 24 ms 6832 KB
s2_10.txt AC 15 ms 5504 KB
s2_11.txt AC 58 ms 11128 KB
s2_12.txt AC 59 ms 11048 KB
s2_13.txt AC 61 ms 12024 KB
s2_14.txt AC 54 ms 12408 KB
s3_15.txt AC 60 ms 10812 KB
s3_16.txt AC 30 ms 7164 KB
s3_17.txt AC 18 ms 5504 KB
s3_18.txt AC 28 ms 7036 KB
s3_19.txt AC 68 ms 11768 KB
s3_20.txt AC 71 ms 12280 KB
s3_21.txt AC 69 ms 11768 KB
s3_22.txt AC 68 ms 11768 KB
s3_23.txt AC 74 ms 13944 KB
s3_24.txt AC 68 ms 13560 KB
s3_25.txt AC 54 ms 11128 KB
s3_26.txt AC 67 ms 13372 KB
s3_27.txt AC 54 ms 11128 KB
s3_28.txt AC 67 ms 13304 KB
s3_29.txt AC 54 ms 11128 KB