提出 #60544451
ソースコード 拡げる
#pragma region header
// C
#include <cassert>
#include <cctype>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstddef>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
// C++
#include <algorithm>
#include <array>
#include <bit>
#include <bitset>
#include <chrono>
#include <compare>
#include <complex>
#include <concepts>
#include <deque>
#include <functional>
#include <initializer_list>
#include <iomanip>
#include <ios>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numbers>
#include <numeric>
#include <queue>
#include <random>
#include <ranges>
#include <regex>
#include <set>
#include <span>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <valarray>
#include <vector>
// atcoder
#include <atcoder/all>
#define int ll
#define all(a) begin(a), end(a)
#define rall(a) rbegin(a), rend(a)
#define rep1(i, n) for (decltype(+n) i = 0; i < (n); i++)
#define rrep1(i, n) for (auto i = (n) - 1; i >= 0; i--)
#define rep2(i, a, b) for (auto i = (a); i < (b); i++)
#define rrep2(i, a, b) for (auto i = (b) - 1; i >= a; i--)
#define GET_NAME(_1, _2, _3, NAME, ...) NAME
#define rep(...) GET_NAME(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)
#define rrep(...) \
GET_NAME(__VA_ARGS__, rrep2, rrep1)(__VA_ARGS__)
using namespace std;
using namespace literals;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using vvs = vector<vs>;
using vd = vector<ld>;
using vvd = vector<vd>;
using vb = vector<bool>;
using vvb = vector<vb>;
using pii = pair<int, int>;
using vp = vector<pii>;
using vvp = vector<vp>;
using i3 = tuple<int, int, int>;
using vi3 = vector<i3>;
using vvi3 = vector<vi3>;
using i4 = tuple<int, int, int, int>;
using vi4 = vector<i4>;
using vvi4 = vector<vi4>;
using mii = map<int, int>;
template <class T, class U>
using umap = unordered_map<T, U>;
using umii = umap<int, int>;
using seti = set<int>;
template <class T>
using uset = unordered_set<T>;
using useti = uset<int>;
template <class T>
using less_queue = priority_queue<T>;
template <class T>
using greater_queue = priority_queue<T, vector<T>, greater<T>>;
using int128 = __int128_t;
template <class T, class U>
istream &operator>>(istream &is, pair<T, U> &x) {
T a;
U b;
is >> a >> b;
x = {a, b};
return is;
}
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &x) {
return os << x.first << ' ' << x.second;
}
template <class T, class... U>
tuple<T, U...> read_tuple(istream &is) {
T a;
is >> a;
if constexpr (sizeof...(U) == 0)
return {a};
else
return tuple_cat(tuple{a}, read_tuple<U...>(is));
}
template <class... T>
istream &operator>>(istream &is, tuple<T...> &x) {
x = read_tuple<T...>(is);
return is;
}
template <size_t I = 0, class... T>
constexpr void write_tuple(ostream &os, const tuple<T...> &x) {
if constexpr (I < sizeof...(T)) {
if constexpr (I == 0)
os << get<0>(x);
else
os << ' ' << get<I>(x);
write_tuple<I + 1>(os, x);
}
}
template <class... T>
ostream &operator<<(ostream &os, const tuple<T...> &x) {
write_tuple(os, x);
return os;
}
template <class T>
istream &operator>>(istream &is, vector<T> &v) {
for (T &x : v) is >> x;
return is;
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
const int n = v.size();
if (n) os << v[0];
for (int i = 1; i < n; i++) os << ' ' << v[i];
return os;
}
ostream &operator<<(ostream &os, int128 x) {
if (!x) return os << '0';
if (x < 0) {
os << '-';
x = -x;
}
string s;
for (; x; x /= 10) s += x % 10 + '0';
reverse(all(s));
return os << s;
}
constexpr long long INF = 1e18;
constexpr ld EPS = 1e-10;
const ld PI = acosl(-1);
bool eq(ld a, ld b) {
return abs(a - b) < EPS;
}
template <typename T>
void SORT(T &a) {
stable_sort(all(a));
}
template <typename T>
T sorted(T a) {
SORT(a);
return a;
}
template <typename T>
void RSORT(T &a) {
stable_sort(rall(a));
}
template <typename T>
T rsorted(T a) {
RSORT(a);
return a;
}
template <typename T, typename U>
void ERASE(T &a, U i) {
a.erase(remove(all(a), i), end(a));
}
template <typename T>
void rev(T &a) {
reverse(all(a));
}
template <typename T>
T reversed(T a) {
rev(a);
return a;
}
template <typename T>
void uniq(T &a) {
a.erase(unique(all(a)), end(a));
}
template <typename T>
auto min_of(const vector<T> &a) {
return *min_element(all(a));
}
template <typename T>
auto max_of(const vector<T> &a) {
return *max_element(all(a));
}
template <typename T>
T sum_of(const vector<T> &a) {
return accumulate(all(a), T{});
}
template <typename T>
int count_of(const T &a, T i) {
return count(all(a), i);
}
template <typename T>
bool has(const vector<T> &a, T i) {
return find(all(a), i) != end(a);
}
bool has(const string &a, char i) {
return find(all(a), i) != end(a);
}
template <typename T>
bool has(const set<T> &a, T i) {
return a.find(i) != a.end();
}
template <typename T, typename U>
bool has(const map<T, U> &a, T i) {
return a.find(i) != a.end();
}
template <typename T, typename U>
bool has(const umap<T, U> &a, T i) {
return a.find(i) != a.end();
}
void CIN() {};
template <class T, class... U>
void CIN(T &&x, U &&...y) {
cin >> x;
CIN(forward<U>(y)...);
}
void _COUT() {
cout << endl;
}
template <class T, class... U>
void _COUT(T &&x, U &&...y) {
cout << ' ' << x;
_COUT(forward<U>(y)...);
}
void COUT() {
_COUT();
};
template <class T, class... U>
void COUT(T &&x, U &&...y) {
cout << x;
_COUT(forward<U>(y)...);
}
void CSP() {};
template <class T, class... U>
void CSP(T &&x, U &&...y) {
cout << x << ' ';
CSP(forward<U>(y)...);
}
template <typename T>
bool amin(T &a, const T &b) {
return a > b ? a = b, true : false;
}
template <typename T>
bool amax(T &a, const T &b) {
return a < b ? a = b, true : false;
}
template <typename T>
vector<T> powers(T base, int N) {
vector<T> ret(N + 1);
ret[0] = 1;
rep(i, N) ret[i + 1] = ret[i] * base;
return ret;
}
template <typename T>
vector<T> factorials(int N) {
vector<T> ret(N + 1);
ret[0] = 1;
rep(i, N) ret[i + 1] = ret[i] * T{i + 1};
return ret;
}
int ceil_div(int x, int y) {
int d = x / y;
return d * y == x ? d : d + ((x > 0) ^ (y < 0));
}
int floor_div(int x, int y) {
int d = x / y;
return d * y == x ? d : d - ((x < 0) ^ (y < 0));
}
int out_div(int x, int y) {
int d = x / y;
return d * y == x ? d : ((x > 0) == (y > 0)) ? d + 1 : d - 1;
}
#pragma endregion header
struct union_find {
vi data;
union_find(int size) : data(size, -1) {}
bool join(int x, int y) {
x = root(x);
y = root(y);
if (x != y) {
if (data[y] < data[x]) swap(x, y);
data[x] += data[y];
data[y] = x;
}
return x != y;
}
bool same(int x, int y) {
return root(x) == root(y);
}
int root(int x) {
return data[x] < 0 ? x : data[x] = root(data[x]);
}
int size(int x) {
return -data[root(x)];
}
};
void solve() {
int N, M, K;
CIN(N, M, K);
map<int, vp> w_uv;
rep(i, M) {
int u, v, w;
CIN(u, v, w);
u--, v--;
w_uv[w].emplace_back(u, v);
}
vi av(N), bv(N);
rep(i, K) {
int A, B;
CIN(A, B);
A--, B--;
av[A]++;
bv[B]++;
}
int ans = 0;
union_find uf(N);
for (auto [w, uv] : w_uv) {
for (auto [u, v] : uv) {
if (uf.same(u, v)) {
continue;
}
u = uf.root(u);
v = uf.root(v);
uf.join(u, v);
if (uf.root(u) == v) {
swap(u, v);
}
av[u] += av[v];
bv[u] += bv[v];
int cnt = min(av[u], bv[u]);
ans += cnt * w;
av[u] -= cnt;
bv[u] -= cnt;
}
}
COUT(ans);
}
#pragma region main
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cout << fixed << setprecision(15);
solve();
}
#pragma endregion main
提出情報
| 提出日時 |
|
| 問題 |
E - Sum of Max Matching |
| ユーザ |
dnek |
| 言語 |
C++ 23 (gcc 12.2) |
| 得点 |
0 |
| コード長 |
7994 Byte |
| 結果 |
WA |
| 実行時間 |
283 ms |
| メモリ |
29848 KiB |
コンパイルエラー
Main.cpp:1: warning: ignoring ‘#pragma region header’ [-Wunknown-pragmas]
1 | #pragma region header
|
Main.cpp:309: warning: ignoring ‘#pragma endregion header’ [-Wunknown-pragmas]
309 | #pragma endregion header
|
Main.cpp:383: warning: ignoring ‘#pragma region main’ [-Wunknown-pragmas]
383 | #pragma region main
|
Main.cpp:392: warning: ignoring ‘#pragma endregion main’ [-Wunknown-pragmas]
392 | #pragma endregion main
|
ジャッジ結果
| セット名 |
Sample |
All |
| 得点 / 配点 |
0 / 0 |
0 / 500 |
| 結果 |
|
|
| セット名 |
テストケース |
| Sample |
00_sample_00.txt, 00_sample_01.txt |
| All |
00_sample_00.txt, 00_sample_01.txt, 01_test_00.txt, 01_test_01.txt, 01_test_02.txt, 01_test_03.txt, 01_test_04.txt, 01_test_05.txt, 01_test_06.txt, 01_test_07.txt, 01_test_08.txt, 01_test_09.txt, 01_test_10.txt, 01_test_11.txt, 01_test_12.txt, 01_test_13.txt, 01_test_14.txt, 01_test_15.txt, 01_test_16.txt, 01_test_17.txt, 01_test_18.txt, 01_test_19.txt, 01_test_20.txt, 01_test_21.txt, 01_test_22.txt, 01_test_23.txt, 01_test_24.txt, 01_test_25.txt, 01_test_26.txt, 01_test_27.txt, 01_test_28.txt, 01_test_29.txt, 01_test_30.txt, 01_test_31.txt, 01_test_32.txt, 01_test_33.txt, 01_test_34.txt, 01_test_35.txt, 01_test_36.txt, 01_test_37.txt, 01_test_38.txt, 01_test_39.txt |
| ケース名 |
結果 |
実行時間 |
メモリ |
| 00_sample_00.txt |
AC |
1 ms |
3380 KiB |
| 00_sample_01.txt |
AC |
1 ms |
3464 KiB |
| 01_test_00.txt |
WA |
1 ms |
3532 KiB |
| 01_test_01.txt |
WA |
1 ms |
3592 KiB |
| 01_test_02.txt |
WA |
1 ms |
3580 KiB |
| 01_test_03.txt |
WA |
123 ms |
18720 KiB |
| 01_test_04.txt |
WA |
17 ms |
7252 KiB |
| 01_test_05.txt |
WA |
5 ms |
4456 KiB |
| 01_test_06.txt |
AC |
7 ms |
4704 KiB |
| 01_test_07.txt |
AC |
1 ms |
3424 KiB |
| 01_test_08.txt |
WA |
186 ms |
25008 KiB |
| 01_test_09.txt |
WA |
212 ms |
28436 KiB |
| 01_test_10.txt |
WA |
28 ms |
7372 KiB |
| 01_test_11.txt |
WA |
28 ms |
7804 KiB |
| 01_test_12.txt |
WA |
14 ms |
6412 KiB |
| 01_test_13.txt |
WA |
43 ms |
10596 KiB |
| 01_test_14.txt |
WA |
44 ms |
12224 KiB |
| 01_test_15.txt |
WA |
67 ms |
15128 KiB |
| 01_test_16.txt |
WA |
228 ms |
29696 KiB |
| 01_test_17.txt |
WA |
283 ms |
29720 KiB |
| 01_test_18.txt |
WA |
72 ms |
12624 KiB |
| 01_test_19.txt |
WA |
55 ms |
12736 KiB |
| 01_test_20.txt |
WA |
257 ms |
29848 KiB |
| 01_test_21.txt |
WA |
264 ms |
29776 KiB |
| 01_test_22.txt |
WA |
49 ms |
11896 KiB |
| 01_test_23.txt |
WA |
60 ms |
11836 KiB |
| 01_test_24.txt |
WA |
274 ms |
29688 KiB |
| 01_test_25.txt |
WA |
275 ms |
29788 KiB |
| 01_test_26.txt |
WA |
270 ms |
29780 KiB |
| 01_test_27.txt |
WA |
279 ms |
29688 KiB |
| 01_test_28.txt |
WA |
275 ms |
29708 KiB |
| 01_test_29.txt |
WA |
221 ms |
25324 KiB |
| 01_test_30.txt |
WA |
220 ms |
25480 KiB |
| 01_test_31.txt |
WA |
217 ms |
25332 KiB |
| 01_test_32.txt |
WA |
257 ms |
29632 KiB |
| 01_test_33.txt |
WA |
256 ms |
29776 KiB |
| 01_test_34.txt |
WA |
261 ms |
29692 KiB |
| 01_test_35.txt |
WA |
98 ms |
29748 KiB |
| 01_test_36.txt |
WA |
99 ms |
29636 KiB |
| 01_test_37.txt |
WA |
89 ms |
29776 KiB |
| 01_test_38.txt |
WA |
208 ms |
29632 KiB |
| 01_test_39.txt |
AC |
1 ms |
3516 KiB |