Contest Duration: - (local time) (100 minutes) Back to Home

Submission #7125615

Source Code Expand

Copy
```#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
struct UnionFind {
vector<int> par; // uf(x,y)->y
UnionFind() {}
UnionFind(int NV) { init(NV); }
void init(int NV) { par.clear(); rep(i, 0, NV) par.push_back(i); }
void reset() { rep(i, 0, par.size()) par[i] = i; }
int operator[](int x) { return par[x] == x ? x : par[x] = operator[](par[x]); }
void operator()(int x, int y) { x = operator[](x); y = operator[](y); if (x != y) par[x] = y; }
};
/*---------------------------------------------------------------------------------------------------
∧＿∧
∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
（ ´_ゝ`）　/　 ⌒i     @hamayanhamayan
／　　　＼　 　  |　|
/　　 /￣￣￣￣/　　|
＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/

int N, H, W;
//---------------------------------------------------------------------------------------------------
void _main() {
cin >> N >> H >> W;
vector<pair<int,pair<int,int>>> E;
rep(i, 0, N) {
int y, x, a; cin >> y >> x >> a;
y--; x--;
E.push_back({a, {x, y + W}});
}

UnionFind uf(H + W + 1);
sort(all(E));
reverse(all(E));

ll ans = 0;
fore(p, E) {
int c = p.first;
int a = p.second.first;
int b = p.second.second;

if(uf[a] == uf[b]) {
if(uf[a] == uf[H + W]) continue;

ans += c;
uf(a, H + W);
} else {
ans += c;
uf(a, b);
}
}
cout << ans << endl;
}

```

#### Submission Info

Submission Time 2019-08-25 01:51:33+0900 E - Card Collector hamayanhamayan C++14 (GCC 5.4.1) 800 2405 Byte AC 37 ms 3572 KB

#### Judge Result

Set Name All Sample
Score / Max Score 800 / 800 0 / 0
Status
 AC × 40
 AC × 3
Set Name Test Cases
All sample_01, sample_02, sample_03, testcase_01, testcase_02, testcase_03, testcase_04, testcase_05, testcase_06, testcase_07, testcase_08, testcase_09, testcase_10, testcase_11, testcase_12, testcase_13, testcase_14, testcase_15, testcase_16, testcase_17, testcase_18, testcase_19, testcase_20, testcase_21, testcase_22, testcase_23, testcase_24, testcase_25, testcase_26, testcase_27, testcase_28, testcase_29, testcase_30, testcase_31, testcase_32, testcase_33, testcase_34, testcase_35, testcase_36, testcase_37
Sample sample_01, sample_02, sample_03
Case Name Status Exec Time Memory
sample_01 AC 1 ms 256 KB
sample_02 AC 1 ms 256 KB
sample_03 AC 2 ms 1400 KB
testcase_01 AC 14 ms 1528 KB
testcase_02 AC 22 ms 1912 KB
testcase_03 AC 6 ms 1084 KB
testcase_04 AC 36 ms 3188 KB
testcase_05 AC 36 ms 3188 KB
testcase_06 AC 16 ms 1272 KB
testcase_07 AC 31 ms 3060 KB
testcase_08 AC 23 ms 1784 KB
testcase_09 AC 26 ms 1912 KB
testcase_10 AC 34 ms 3188 KB
testcase_11 AC 30 ms 1912 KB
testcase_12 AC 37 ms 3188 KB
testcase_13 AC 36 ms 3060 KB
testcase_14 AC 36 ms 3060 KB
testcase_15 AC 29 ms 2036 KB
testcase_16 AC 19 ms 1656 KB
testcase_17 AC 18 ms 1784 KB
testcase_18 AC 34 ms 3188 KB
testcase_19 AC 35 ms 3188 KB
testcase_20 AC 35 ms 3188 KB
testcase_21 AC 35 ms 3188 KB
testcase_22 AC 36 ms 3188 KB
testcase_23 AC 35 ms 3188 KB
testcase_24 AC 2 ms 1400 KB
testcase_25 AC 34 ms 2292 KB
testcase_26 AC 32 ms 2292 KB
testcase_27 AC 29 ms 1912 KB
testcase_28 AC 36 ms 3572 KB
testcase_29 AC 37 ms 3572 KB
testcase_30 AC 36 ms 3188 KB
testcase_31 AC 37 ms 3188 KB
testcase_32 AC 1 ms 256 KB
testcase_33 AC 36 ms 2548 KB
testcase_34 AC 36 ms 3188 KB
testcase_35 AC 35 ms 3188 KB
testcase_36 AC 35 ms 3060 KB
testcase_37 AC 35 ms 3060 KB