QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#562229 | #6619. Line Graph Matching | rxzfn639 | WA | 215ms | 56948kb | C++23 | 2.5kb | 2024-09-13 15:54:07 | 2024-09-13 15:54:14 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int, int>
#define inf 0x3f3f3f3f
const int N = 5e5 + 5;
int n, m;
int tmp, dfn[N], low[N];
vector<pii> g[N << 1];
// 无向图缩点
// 求边双连通分量,注意可能出现重边
// 标记桥边
map<pii, bool> mp;
void dfs(int u, int las)
{
dfn[u] = low[u] = ++tmp;
for (auto [v, w] : g[u])
{
if (dfn[v] == 0)
{
dfs(v, w);
low[u] = min(low[u], low[v]);
if (low[v] > dfn[u])
mp[{u, v}] = 1, mp[{v, u}] = 1;
}
else if (w != (las ^ 1))
low[u] = min(low[u], dfn[v]);
}
}
int vis[N], cnt, col[N], w[N], in[N];
vector<int> G[N];
void dfs2(int u)
{
col[u] = cnt;
w[cnt] += in[u];
for (auto [v, w] : g[u])
{
if (vis[v]) continue;
if (mp[{u, v}] || mp[{v, u}]) continue;
vis[v] = 1;
dfs2(v);
}
}
struct node
{
int u, v, w;
bool operator<(const node& t)
{
return w < t.w;
}
}e[N];
int minn = inf;
int siz[N];
map<pii, int>bq;
void dfs4(int u, int f)
{
siz[u] = w[u];
for (auto v: G[u])
{
if (v == f) continue;
dfs4(v, u);
siz[u] += siz[v] + 1;
if (!(siz[v] & 1)) minn = min(minn, bq[{u, v}]);
}
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
cin >> n >> m;
int sum = 0;
for (int i = 1; i <= m; i++)
{
int u, v, w;
cin >> u >> v >> w;
sum += w;
in[u]++, in[v]++;
e[i] = {u, v, w};
g[u].push_back({v, i << 1}),
g[v].push_back({u, i << 1 | 1});
}
if (m % 2 == 0)
{
cout << sum << endl;
return 0;
}
for (int i = 1; i <= n; i++)
if (!dfn[i]) dfs(i, 0);
int ans = inf;
for (int i = 1; i <= n; i++)
{
if (vis[i] == 0)
{
cnt++;
vis[i] = 1;
dfs2(i);
}
}
for (int i = 1; i <= cnt; i++) w[i] = (w[i] + 1) / 2 - 1;
for (int i = 1; i <= m; i++)
{
auto [u, v, w] = e[i];
if (mp[{u, v}] == 0) ans = min(ans, w);
else
{
u = col[u], v = col[v];
bq[{u, v}] = w;
G[u].push_back(v),
G[v].push_back(u);
}
}
dfs4(1, 0);
ans = min(ans, minn);
cout << sum - ans << endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 9720kb
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: 3ms
memory: 15936kb
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: 15920kb
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: 2ms
memory: 9668kb
input:
3 2 1 2 1 2 3 2
output:
3
result:
ok 1 number(s): "3"
Test #5:
score: 0
Accepted
time: 3ms
memory: 15924kb
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: 3ms
memory: 15868kb
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: -100
Wrong Answer
time: 215ms
memory: 56948kb
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:
49946352914585
result:
wrong answer 1st numbers differ - expected: '49946352904479', found: '49946352914585'