Submission #3010211
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;
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
2018-08-15 12:23:34+0900
Task
E - Black Cats Deployment
User
fxt
Language
C++14 (GCC 5.4.1)
Score
0
Code Size
1127 Byte
Status
RE
Exec Time
101 ms
Memory
6144 KB
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:52: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
0 / 200
0 / 200
0 / 400
Status
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
RE
100 ms
6144 KB
00_example_02.txt
RE
101 ms
6144 KB
00_example_03.txt
RE
101 ms
6144 KB
s1_01.txt
RE
101 ms
6144 KB
s1_02.txt
RE
100 ms
6144 KB
s1_03.txt
RE
100 ms
6144 KB
s1_04.txt
RE
100 ms
6144 KB
s1_05.txt
RE
100 ms
6144 KB
s1_06.txt
RE
100 ms
6144 KB
s1_07.txt
RE
100 ms
6144 KB
s2_08.txt
RE
101 ms
6144 KB
s2_09.txt
RE
99 ms
6144 KB
s2_10.txt
RE
99 ms
6144 KB
s2_11.txt
RE
101 ms
6144 KB
s2_12.txt
RE
100 ms
6144 KB
s2_13.txt
RE
101 ms
6144 KB
s2_14.txt
RE
100 ms
6144 KB
s3_15.txt
RE
100 ms
6144 KB
s3_16.txt
RE
100 ms
6144 KB
s3_17.txt
RE
100 ms
6144 KB
s3_18.txt
RE
100 ms
6144 KB
s3_19.txt
RE
100 ms
6144 KB
s3_20.txt
RE
101 ms
6144 KB
s3_21.txt
RE
100 ms
6144 KB
s3_22.txt
RE
101 ms
6144 KB
s3_23.txt
RE
100 ms
6144 KB
s3_24.txt
RE
101 ms
6144 KB
s3_25.txt
RE
100 ms
6144 KB
s3_26.txt
RE
100 ms
6144 KB
s3_27.txt
RE
100 ms
6144 KB
s3_28.txt
RE
100 ms
6144 KB
s3_29.txt
RE
100 ms
6144 KB