QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#713079 | #9573. Social Media | ucup-team1196# | RE | 0ms | 0kb | C++23 | 3.1kb | 2024-11-05 18:01:17 | 2024-11-05 18:01:17 |
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
void solve() {
int n, m, k;
std::cin >> n >> m >> k;
// std::cerr << n << " " << m << " " << k << "!!!" << std::endl;
std::vector<int> f(n + 1), a(m + 1), b(m + 1);
std::map<int, int> is, one;
std::map<std::array<int, 2>, int> two;
std::vector G(k + 1, std::vector<int>());
for (int i = 1; i <= n; i++) {
std::cin >> f[i];
is[f[i]] = 1;
}
// std::cout << __LINE__ << std::endl;
int ans = 0, alr = 0;
for (int i = 1; i <= m; i++) {
std::cin >> a[i] >> b[i];
if (is.count(a[i]) && is.count(b[i])) {
alr ++;
} else if (is.count(a[i])) {
one[b[i]] ++;
} else if (is.count(b[i])) {
one[a[i]] ++;
} else {
if (a[i] == b[i]) {
one[a[i]] ++;
} else {
if (a[i] > b[i]) {
std::swap(a[i], b[i]);
}
two[{a[i], b[i]}] = 1;
G[a[i]].push_back(b[i]);
G[b[i]].push_back(a[i]);
}
}
}
// return;
// std::cout << __LINE__ << std::endl;
std::vector<int> tr(k << 2 + 1);
auto pushup = [&](int u) {
return std::max(tr[u << 1], tr[u << 1 | 1]);
};
// std::cout << __LINE__ << std::endl;
std::function<void(int, int, int, int, int)> modify = [&](int u, int l, int r, int p, int x) {
// std::cerr << u << " " << l << " " << r << std::endl;
if (l == r) {
tr[u] += x;
return;
}
int mid = (l + r + 1) >> 1;
if (mid <= p) {
modify(u << 1 | 1, mid, r, p, x);
} else {
modify(u << 1, l, mid - 1, p, x);
}
tr[u] = pushup(u);
};
std::function<void(int, int, int, int, int)> query = [&](int u, int l, int r, int p, int x) {
// std::cerr << u << " " << l << " " << r << std::endl;
if (l == r && l == p) {
std::cout << tr[l] << ' ';
return;
}
int mid = (l + r + 1) >> 1;
if (mid <= p) {
query(u << 1 | 1, mid, r, p, x);
} else {
query(u << 1, l, mid - 1, p, x);
}
};
// std::cout << __LINE__ << std::endl;
for (auto [x, y] : one) {
modify(1, 1, k, x, y);
}
for (int i = 1; i <= k; i++) {
int cnt = one[i];
for (auto x : G[i]) {
modify(1, 1, k, x, 1);
}
modify(1, 1, k, i, -one[i]);
// for (int j = 1; j <= k; j++) {
// query(1, 1, k, j, 0);
// }
// std::cout << '\n';
cnt += tr[1];
for (auto x : G[i]) {
modify(1, 1, k, x, -1);
}
modify(1, 1, k, i, one[i]);
ans = std::max(ans, cnt);
}
std::cout << alr + ans << '\n';
}
signed main() {
std::ios::sync_with_stdio(false);
std::cin.tie(0);
freopen("J.in", "r", stdin);
int t = 1;
std::cin >> t;
while (t --) {
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Runtime Error
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