QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#643621#6619. Line Graph Matchingadivse#WA 46ms12672kbC++201.8kb2024-10-15 22:24:132024-10-15 22:24:13

Judging History

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

  • [2024-10-15 22:24:13]
  • 评测
  • 测评结果:WA
  • 用时:46ms
  • 内存:12672kb
  • [2024-10-15 22:24:13]
  • 提交

answer

#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <map>
#define endl '\n'
#define int long long
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define rep2(i,a,b) for(int i=(a);i>=(b);i--)
using namespace std;
template<typename... Args>
void bubu(Args... args) { cout << ":: "; ((cout << args << " "), ...); cout << endl; }
void bubu(vector<int> tem) { for (auto x : tem) cout << x << ' '; cout << endl; }
void kuaidu() { ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); }
inline int max(int a, int b) { if (a < b) return b; return a; }
inline int min(int a, int b) { if (a < b) return a; return b; }
using PII = pair<int, int>;
using i128 = __int128;

//=======================================================================
const int N = 1e5 + 10;
const int M = 1e6 + 10;
const int mod = 1e9 + 7;
const int INF = 1e16;
int n, m, T;
vector<PII> A[N];
int st; int in[N]; bool vis[N];
int mmin = INF;
//=======================================================================
void dfs(int x, int pa, int d) {
	for (auto [y, val] : A[x]) {
		if (y == pa) continue;
		if (vis[y]) continue;
		vis[y] = 1;
		if (d % 2==0) mmin = min(mmin, val);
		dfs(y, x, d + 1);
	}
}
signed main() {
	kuaidu();
	cin >> n >> m;
	int ans = 0;
	rep(i, 1, m) {
		int a, b, c; cin >> a >> b >> c;
		A[a].push_back({ b,c });
		A[b].push_back({ a,c });
		in[a]++, in[b]++;
		// mmin = min(mmin, c);
		ans += c;
	}

	if (m % 2 == 0) {
		cout << ans << endl;
		return 0;
	}

	rep(i, 1, n) {
		if (in[i] == 1) { st = i; break; }
	}
	dfs(st, 0, 0);
	if (mmin >=INF/2) {
		rep(i, 1, n) {
			for (auto [y, val] : A[i]) mmin = min(mmin, val);
		}
	}
	cout << ans - mmin << endl;

	return 0;
}

詳細信息

Test #1:

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

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

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: 1ms
memory: 3688kb

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

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

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

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: 46ms
memory: 12672kb

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:

49946352897973

result:

wrong answer 1st numbers differ - expected: '49946352904479', found: '49946352897973'