QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#791845 | #9565. Birthday Gift | imwinter# | RE | 0ms | 0kb | C++20 | 1.6kb | 2024-11-28 21:20:38 | 2024-11-28 21:20:38 |
answer
#include <bits/stdc++.h>
using i64 = long long;
void sol() {
int n, m, k;
std::cin >> n >> m >> k;
std::set<int> s;
for (int i = 0; i < n; i++) {
int p;
std::cin >> p;
s.insert(p);
}
std::vector<int> c(k + 1);
int cnt = 0;
std::map<std::pair<int, int>, int> mp;
for (int i = 0; i < m; i++) {
int a, b;
std::cin >> a >> b;
if (s.find(a) != s.end() && s.find(b) != s.end()) {
cnt++;
//std::cout << a << b<<'\n';
}
if (s.count(a) == 0 && s.count(b) == 0) {
if (a > b) {
std::swap(a, b);
}
if (a == b) {c[a]++;
continue;}
mp[{a, b}]++;
}
if (s.count(a) == 1 && s.count(b) == 0 || s.count(a) == 0 && s.count(b) == 1) {
c[s.count(a) == 1 ? b : a]++;
}
}
if (mp.empty()) {
std::sort(c.begin(), c.end(), std::greater<int>());
std::cout << cnt + c[0] + c[1] << "\n";
return;
}
std::vector<int> A;
for (auto _ : mp) {
auto x = _.first.first, y = _.first.second;
mp[_.first] += c[x] + c[y];
A.push_back(mp[_.first]);
}
std::sort(A.begin(), A.end(),std::greater<int>());
//std::cout << A[0] << cnt << " \n";
std::cout << A[0] + cnt << " \n";
}
int main() {
//std::ios::sync_with_stdio(false);
//std::cin.tie(nullptr);
int _ = 1;
std::cin >> _;
while (_--) {
sol();
}
return 0;
}
详细
Test #1:
score: 0
Runtime Error
input:
5 0110101 01020102 0000021111 1012121010 0100202010