QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#205694#6619. Line Graph MatchingAshokaRE 1ms3548kbC++201.5kb2023-10-07 17:03:382023-10-07 17:03:38

Judging History

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

  • [2023-10-07 17:03:38]
  • 评测
  • 测评结果:RE
  • 用时:1ms
  • 内存:3548kb
  • [2023-10-07 17:03:38]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;
using i64 = long long;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  int idx = 0;
  vector<vector<pair<int, int>>> adj(n + 1);
  vector<int> edge(2 * m), d(n + 1);
  i64 sum = 0;
  for (int i = 0; i < m; ++i) {
    int u, v, w;
    cin >> u >> v >> w;
    adj[u].emplace_back(v, idx++);
    adj[v].emplace_back(u, idx++);
    d[u]++; d[v]++;
    edge[idx - 1] = edge[idx - 2] = w;
    sum += w;
  }

  if (m % 2 == 0) {
    cout << sum << "\n";
    return 0;
  }

  int time = 0;
  vector<int> dfn(n + 1), low(n + 1), siz(n + 1);
  vector<tuple<int, int, int>> bridge;
  vector<bool> tag(2 * m);
  auto tarjan = [&](auto self, int u, int e)->void {
    dfn[u] = low[u] = ++time;
    for (auto [v, i] : adj[u]) {
      if (!dfn[v]) {
        self(self, v, i);
        low[u] = min(low[u], low[v]);
        if (dfn[u] < low[v]) {                 
          siz[i] = siz[i ^ 1] = (d[v] - 1) / 2;        
          bridge.emplace_back(v, u, edge[i]);
          tag[i] = tag[i ^ 1] = 1;
          // cerr << u << "<->" << v << " is bridge\n";
        }
        d[u] += d[v];
      } else if (i != (e ^ 1)) {
        low[u] = min(low[u], dfn[v]);
      }
    }
    return;
  };

  tarjan(tarjan, 1, -1);

  i64 ans = 0;
  for (int i = 0; i < 2 * m; ++i) {
    if (!tag[i] || (tag[i] && siz[i] % 2 == 0 && (m - siz[i] - 1) % 2 == 0)) {
      ans = max(ans, sum - edge[i]);
    }
  }

  cout << ans << "\n";
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3548kb

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

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

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

input:

3 2
1 2 1
2 3 2

output:

3

result:

ok 1 number(s): "3"

Test #5:

score: 0
Accepted
time: 1ms
memory: 3440kb

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

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
Runtime Error

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:


result: