QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#728243#9573. Social Mediaucup-team059#WA 32ms3864kbC++202.1kb2024-11-09 14:50:382024-11-09 14:50:45

Judging History

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

  • [2024-11-09 14:50:45]
  • 评测
  • 测评结果:WA
  • 用时:32ms
  • 内存:3864kb
  • [2024-11-09 14:50:38]
  • 提交

answer

#include <bits/stdc++.h>

#define ll long long

void solve() {
	int n, m, k;
	std::cin >> k >> m >> n;

	std::vector<std::vector<int>> adj(n + 1);
	std::map<std::pair<int, int>, int> e;
	std::vector<int> self(n + 1);

	int init = 0;
	std::vector<int> sel(n + 1), forst(n + 1);
	for (int i = 0; i < k; i++){
		int f;
		std::cin >> f;
		sel[f] = 1;
	}

	for (int i = 0; i < m; i++){
		int a, b;
		std::cin >> a >> b;
		if (a == b){
			self[a]++;
			// std::cout << a << ' ' << b << "SSS\n";
		}else{
			adj[a].push_back(b);
			adj[b].push_back(a);
			if (a > b) {
				std::swap(a, b);
			}
			e[{a, b}]++;
		}
	}

	std::vector<std::pair<std::pair<int, int>, int>> edg(e.begin(), e.end());
	for (int i = 1; i <= n; i++){
		for (auto y : adj[i]){
			if (sel[y]){
				forst[i]++;
			}
		}
	}

	int ans = 0;

	for (auto [_, w] : edg){
		auto [x, y] = _;
		if (sel[x] && sel[y]){
			init++;
		}
	}
	for (int i = 1; i <= n; i++){
		if (sel[i]){
			init += self[i];
		}
	}

	std::vector<std::pair<int, int>> b;
	for (int i = 1; i <= n; i++){
		if (sel[i] == 0){
			b.push_back({forst[i], i});
		}
	}

	sort(b.begin(), b.end(), std::greater<>());
	ans = init;
	for (auto [_, w] : edg){
		auto [x, y] = _;
		// std::cout << x << ' '<< y << ' ' << w << '\n';
		if (sel[x] == 1 && sel[y] == 1) {
			continue;
		}
		int cur = 0;
		if (sel[x] == 0 && sel[y] == 0){
			cur += w;
			cur += self[x];
			cur += forst[x];
			cur += self[y];
			cur += forst[y];
			cur += init;
		}else{
			if (sel[x] == 0){
				cur += forst[x];
				cur += self[x];
				for (auto [val, idx] : b){
					if (idx != x){
						cur += val;
						cur += self[idx];
						break;
					}
				}
			}else{
				cur += forst[y];
				cur += self[y];
				for (auto [val, idx] : b){
					if (idx != y){
						cur += val;
						cur += self[idx];
						break;
					}
				}
			}
			cur += init;
		}
		ans = std::max(ans, cur);
	}

	std::cout << ans << '\n';
}

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(nullptr);

	int t;
	std::cin >> t;

	while (t--){
		solve();
	}


	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3844kb

input:

5
4 12 7
5 7 3 6
3 6
2 2
1 4
2 4
1 3
7 6
4 1
5 4
1 1
1 1
2 1
3 7
2 7 6
2 4
1 2
3 2
2 5
5 4
2 6
4 6
2 6
1 1 2
1
1 2
2 1 2
1 2
1 2
2 1 100
24 11
11 24

output:

9
5
1
1
1

result:

ok 5 number(s): "9 5 1 1 1"

Test #2:

score: -100
Wrong Answer
time: 32ms
memory: 3864kb

input:

10000
19 12 20
8 12 1 5 11 7 17 13 19 6 3 9 10 15 14 20 4 18 16
4 11
7 1
8 4
16 19
1 13
15 2
16 2
8 7
3 15
11 13
5 20
18 14
17 14 20
2 9 1 12 8 11 10 17 18 16 3 15 5 14 20 13 7
15 10
3 2
5 16
7 8
6 1
6 4
18 16
1 8
4 1
20 6
6 9
4 15
7 5
14 9
1 3 18
9
15 18
17 15
11 14
7 19 7
3 1 2 5 6 4 7
5 1
4 5
3 1...

output:

12
14
1
11
6
5
1
4
18
4
3
10
4
0
4
19
14
2
17
4
14
5
1
2
5
14
3
2
6
14
6
3
6
4
4
7
3
7
4
1
16
14
2
3
6
12
11
7
6
8
8
6
7
11
16
1
4
9
8
13
2
6
13
17
16
7
18
13
8
12
7
9
6
8
2
14
9
5
5
2
6
6
18
8
13
11
10
5
3
5
3
1
8
5
8
11
7
14
10
9
8
11
7
9
4
2
8
14
10
5
3
5
5
9
1
6
8
16
5
3
18
1
4
8
8
10
4
2
1
13
1...

result:

wrong answer 4th numbers differ - expected: '19', found: '11'