QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#562222#6619. Line Graph Matchingrxzfn639WA 197ms50936kbC++232.5kb2024-09-13 15:51:542024-09-13 15:52:00

Judging History

你现在查看的是最新测评结果

  • [2024-09-13 15:52:00]
  • 评测
  • 测评结果:WA
  • 用时:197ms
  • 内存:50936kb
  • [2024-09-13 15:51:54]
  • 提交

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];
vector<int> G[N];
void dfs2(int u)
{
    col[u] = cnt;
    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 ans = 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)) ans = min(ans, 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;
        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);

    for (int i = 1; i <= n; i++)
    {
        if (vis[i] == 0)
        {
            cnt++;
            vis[i] = 1;
            dfs2(i);
        }
    }

    for (int i = 1; i <= m; i++)
    {
        auto [u, v, ww] = e[i];
        if (mp[{u, v}] == 0) 
        {
            ans = min(ans, ww);
            // cout << u << ' ' << v << endl;
            w[col[u]]++;
        }
        else 
        {
            u = col[u], v = col[v];
            bq[{u, v}] = ww;
            G[u].push_back(v),
            G[v].push_back(u);
        }
    }

//     for (int i = 1; i <= cnt; i++) cout << w[i] << endl;

    dfs4(1, 0);
    cout << sum - ans << endl;
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 2ms
memory: 7772kb

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: 0ms
memory: 11784kb

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: 13824kb

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: 7620kb

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: 13820kb

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: 13888kb

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: 197ms
memory: 50936kb

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'