結果
| 問題 |
No.1002 Twotone
|
| コンテスト | |
| ユーザー |
kotamanegi
|
| 提出日時 | 2020-02-28 22:12:53 |
| 言語 | C++17(clang) (17.0.6 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,863 bytes |
| コンパイル時間 | 2,037 ms |
| コンパイル使用メモリ | 165,888 KB |
| 実行使用メモリ | 30,444 KB |
| 最終ジャッジ日時 | 2024-11-30 16:35:24 |
| 合計ジャッジ時間 | 8,477 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 16 WA * 17 |
コンパイルメッセージ
main.cpp:2:18: warning: '#pragma comment linker' ignored [-Wignored-pragmas]
2 | #pragma comment (linker, "/STACK:526000000")
| ^
1 warning generated.
ソースコード
#define _CRT_SECURE_NO_WARNINGS
#pragma comment (linker, "/STACK:526000000")
#include "bits/stdc++.h"
using namespace std;
typedef string::const_iterator State;
#define eps 1e-11L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL
#define MOD 998244353LL
#define seg_size 262144
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long (a) = 0;(a) < (b);++(a))
#define ALL(x) (x).begin(),(x).end()
unsigned long xor128() {
static unsigned long x = 123456789, y = 362436069, z = 521288629, w = time(NULL);
unsigned long t = (x ^ (x << 11));
x = y; y = z; z = w;
return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}
void init() {
iostream::sync_with_stdio(false);
cout << fixed << setprecision(20);
}
#define int ll
int union_tree[300000];
int cnt[300000];
vector<pair<int, int>> edges[300000];
int dp[300000];
int union_find(int now) {
if (now == union_tree[now]) return now;
return union_tree[now] = union_find(union_tree[now]);
}
void union_merge(int a, int b) {
a = union_find(a);
b = union_find(b);
union_tree[a] = b;
return;
}
void solve() {
int n, k;
cin >> n >> k;
REP(i, n-1) {
int a, b, c;
cin >> a >> b >> c;
a--; b--; c--;
edges[c].push_back(mp(a, b));
}
REP(i, n) {
union_tree[i] = i;
}
int ans = 0;
for (int q = 0; q < 2e5; ++q) {
set<int> appeared;
for (auto x : edges[q]) {
union_merge(x.first, x.second);
appeared.insert(x.first);
appeared.insert(x.second);
}
for (auto x : appeared) {
cnt[union_find(x)]++;
}
for (auto x : appeared) {
ans += dp[x] * (cnt[union_find(x)] - 1LL);
dp[x] += (cnt[union_find(x)] - 1LL);
}
for (auto x : edges[q]) {
union_tree[x.first] = x.first;
union_tree[x.second] = x.second;
cnt[x.first] = 0;
cnt[x.second] = 0;
}
}
cout << ans << endl;
}
#undef int
int main() {
init();
solve();
}
kotamanegi