QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#654863 | #4577. Kingdom Partition | IllusionaryDominance# | WA | 0ms | 3672kb | C++20 | 1.8kb | 2024-10-18 22:36:53 | 2024-10-18 22:36:56 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
typedef vector <pii> vp;
const int MAX_N = 1000 + 5;
int N, M, a, b;
vp edge[MAX_N];
char col[MAX_N];
ll ans;
int main() {
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin >> N >> M >> a >> b;
for (int i = 1; i <= M; i ++) {
int x, y, w;
cin >> x >> y >> w;
edge[x].emplace_back(y, w);
edge[y].emplace_back(x, w);
}
col[a] = 1; col[b] = 2;
for (auto [y, w] : edge[a]) {
(col[y] || (ans += w));
}
for (auto [y, w] : edge[b]) {
(col[y] || (ans += w));
}
while (true) {
int u = -1, nc = -1;
ll val = 0;
for (int i = 1; i <= N; i ++) {
if (!col[i]) {
ll suma = 0, sumb = 0, sumc = 0;
for (auto [y, w] : edge[i]) {
switch (col[y]) {
case 0 : sumc += w; break;
case 1 : suma += w; break;
case 2 : sumb += w; break;
default : assert(false);
}
}
ll sum = abs(suma - sumb) - sumc;
if (val < sum) {
val = sum; u = i;
nc = suma < sumb ? 1 : 2;
}
}
}
if (u == -1) break;
col[u] = nc;
ans -= val;
}
cout << ans << '\n';
for (int i = 1; i <= N; i ++) {
char c = 0;
switch (col[i]) {
case 0 : c = 'C'; break;
case 1 : c = 'A'; break;
case 2 : c = 'B'; break;
default : assert(false);
}
cout << c;
}
cout << endl;
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3660kb
input:
6 7 1 3 1 2 10 2 3 5 1 3 7 4 5 3 3 6 100 4 6 3 5 6 8
output:
16 ABBCBA
result:
ok [n = 6, m = 7] 16
Test #2:
score: 0
Accepted
time: 0ms
memory: 3596kb
input:
3 2 3 2 1 2 3 3 1 2
output:
4 ABA
result:
ok [n = 3, m = 2] 4
Test #3:
score: 0
Accepted
time: 0ms
memory: 3672kb
input:
3 3 1 2 2 3 17 2 1 8 3 1 16
output:
32 ABA
result:
ok [n = 3, m = 3] 32
Test #4:
score: -100
Wrong Answer
time: 0ms
memory: 3656kb
input:
4 6 1 4 4 3 14 4 1 1 1 3 5 2 1 8 4 2 2 3 2 17
output:
29 ACCB
result:
wrong answer [n = 4, m = 6] jury found 14, contestant found 29