QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#732268#9573. Social Mediaucup-team059RE 0ms0kbC++201.7kb2024-11-10 13:49:462024-11-10 13:49:52

Judging History

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

  • [2024-11-10 13:49:52]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-11-10 13:49:46]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;
//#define double long double
#define int long long
#define PII pair<int, int>
#define ull unsigned int
const int N = 1e5 + 5, mod = 998244353, Mod = 1e9 + 7, inf = 1e18, MAXN = 2e5;
const double eps = 1e-12, pi = acos(-1);
int M[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, 1, 0, -1};
//int dx[4] = {1, 0, -1, 0};
//int dy[4] = {0, 1, 0, -1};



void solve() {
    int k, m, n;
    cin >> k >> m >> n;
    vector<int> st(n + 1);
    for (int i = 0; i < k; ++i) {
        int u;
        cin >> u;
        st[u] = 1;
    }
    map<PII, int> cnt;
    vector<int> c(n + 1), sel(n + 1);
    int ans = 0;
    for (int i = 0; i < m; ++i) {
        int a, b;
        cin >> a >> b;
        if (st[a] && st[b]) ans ++;
        else if (st[a]) c[b] ++;
        else if (st[b]) c[a] ++;
        else {
            if (a > b) swap(a, b);
            if (a == b) c[a] ++;
            else cnt[{a, b}] ++;
        }
    }
    int ma[2];
    for (int i = 1; i <= n; ++i) {
        if (st[i]) continue;
        if (c[i] > c[ma[0]]) {
            ma[1] = ma[0], ma[0] = i;
        } else if (c[i] > c[ma[1]]) {
            ma[1] = i;
        }
    }
    int res = 0;
    for (auto [_, y]: cnt) {
        res = max(res, c[_.first] + c[_.second] + y);
    }
    int res1 = c[ma[0]] + c[ma[1]];
    if (cnt.count({ma[0], ma[1]})) res1 += cnt[{ma[0], ma[1]}];
    ans += max(res, res1);
    cout << ans << '\n';
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int T = 1, idx = 1;
    cin >> T;
    while (T--) {
//        cout << "Case #" << idx ++ << ": ";
        solve();
    }

    return 0;
}

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

output:


result: