QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#249755 | #6619. Line Graph Matching | ucup-team1001# | WA | 82ms | 12300kb | C++23 | 2.2kb | 2023-11-12 15:05:21 | 2023-11-12 15:05:22 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, l, r) for(ll (i) = (l); (i) < (r); ++ (i))
#define per(i, r, l) for(ll (i) = (r); (i) > (l); -- (i))
#define MAXN (int)1e5+5
int low[MAXN], dfn[MAXN], dfs_clock;
bool isbridge[MAXN];
vector<int> G[MAXN];
int cnt_bridge;
int father[MAXN];
ll nums;
bool isable[MAXN];
bool vis[MAXN];
void tarjan(int u, int fa) {
father[u] = fa;
low[u] = dfn[u] = ++dfs_clock;
for (int i = 0; i < G[u].size(); i++) {
int v = G[u][i];
if (!dfn[v]) {
tarjan(v, u);
low[u] = min(low[u], low[v]);
if (low[v] > dfn[u]) {
isbridge[v] = true;
++cnt_bridge;
}
} else if (dfn[v] < dfn[u] && v != fa) {
low[u] = min(low[u], dfn[v]);
}
}
}
void dfs(int u) {
vis[u] = true;
for (int v : G[u]) {
if (!vis[v]) {
if(u==1)nums=0;
dfs(v);
}
}
nums++;
if (isbridge[u]) {
if (nums % 2)isable[u] = true;
}
}
int main() {
int n, m;
cin >> n >> m;
ll s = 0;
priority_queue<pair<ll, pair<int, int>>, vector<pair<ll, pair<int, int>>>, greater<>> pq;
for (int i = 1; i <= m; i++) {
int x, y, w;
cin >> x >> y >> w;
G[x].push_back(y);
G[y].push_back(x);
pq.push({w, {x, y}});
s += w;
}
if (m % 2 == 0) {
cout << s;
return 0;
}
tarjan(1, 1);
dfs(1);
// for (int i = 1; i <= n; i++) {
// cerr << i << " " << father[i] << " " << isable[i] << endl;
// }
auto is_b = [&](int x, int y) {
return father[x] == y && isbridge[x] || father[y] == x && isbridge[y];
};
auto is_a = [&](int x, int y) {
return father[x] == y && isable[x] || father[y] == x && isable[y];
};
while (true) {
auto [w, e] = pq.top();
auto &[x, y] = e;
pq.pop();
if (is_b(x, y) && !is_a(x, y)) {
continue;
}
cout << s - w;
return 0;
}
}
//12 13
//1 2 6
//2 3 7
//2 4 8
//3 5 9
//4 5 10
//5 6 1
//6 7 2
//6 8 3
//7 9 4
//8 9 5
//9 10 6
//1 11 7
//10 12 7
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 6608kb
input:
5 6 1 2 1 1 3 2 1 4 3 4 3 4 4 5 5 2 5 6
output:
21
result:
ok 1 number(s): "21"
Test #2:
score: 0
Accepted
time: 1ms
memory: 6172kb
input:
6 5 1 2 4 2 3 1 3 4 3 4 5 2 5 6 5
output:
12
result:
ok 1 number(s): "12"
Test #3:
score: 0
Accepted
time: 0ms
memory: 6376kb
input:
5 5 1 2 1 2 3 2 3 4 3 4 5 4 5 1 5
output:
14
result:
ok 1 number(s): "14"
Test #4:
score: 0
Accepted
time: 1ms
memory: 5960kb
input:
3 2 1 2 1 2 3 2
output:
3
result:
ok 1 number(s): "3"
Test #5:
score: 0
Accepted
time: 0ms
memory: 5948kb
input:
3 3 1 2 3 2 3 1 3 1 2
output:
5
result:
ok 1 number(s): "5"
Test #6:
score: 0
Accepted
time: 1ms
memory: 6092kb
input:
6 7 1 2 1 2 3 2 3 4 3 4 1 4 4 5 5 5 6 6 6 4 7
output:
27
result:
ok 1 number(s): "27"
Test #7:
score: 0
Accepted
time: 78ms
memory: 12300kb
input:
100000 99999 54273 5761 179909546 6472 21601 924153552 610 22693 767540137 37784 2454 951330587 24457 93770 781030280 36098 27 448166069 21292 43394 244510129 58047 86330 869927899 18770 83124 20504174 24036 92856 8370757 92492 21932 734860719 43776 77624 226721931 15746 70738 429430538 71204 87185 ...
output:
49946352904479
result:
ok 1 number(s): "49946352904479"
Test #8:
score: -100
Wrong Answer
time: 82ms
memory: 11776kb
input:
100000 99999 18547 67114 422842568 19693 8496 779855087 51167 18426 915314526 44355 50210 119625069 12950 4056 197918233 61098 35840 389797594 73234 63511 535160500 47702 90861 938540623 91579 13299 509661983 40747 91690 12909789 58827 9678 282003419 35422 9560 815634437 20241 26517 840659336 93110 ...
output:
49888240269641
result:
wrong answer 1st numbers differ - expected: '49888240257242', found: '49888240269641'