QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#261460#6127. Kawa ExamtaxuankienWA 2ms6900kbC++201.5kb2023-11-22 21:58:262023-11-22 21:58:26

Judging History

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

  • [2023-11-22 21:58:26]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:6900kb
  • [2023-11-22 21:58:26]
  • 提交

answer

#include <bits/stdc++.h>
#define ll long long
using namespace std;

int n,m;
const int mx=1e5+5;
int a[mx], u[mx], v[mx], res=0, q1, q2;
vector <int> vt[mx];
bool seen[mx];

void bfs(int i){

    vector<int> lt;
    lt.push_back(i);
    queue<int> q;
    q.push(i);
    seen[i]=1;
    while (!q.empty()){

        int u=q.front();
        q.pop();
        for (auto v:vt[u]){
            if (!seen[v]){
                q.push(v);
                seen[v]=1;
                lt.push_back(v);
            }
        }

    }

    int d=0;
    map <int,int> m;
    for (auto v:lt){
        m[a[v]]++;
        d=max(d,m[a[v]]);
    }
    res+=d;
}

int main(){

    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);

    int t; cin >> t;
    while (t--){

        cin >> n >> m;

        for (int i=1;i<=n;i++) cin >> a[i];

        for (int i=1; i<=m;i++){

            cin >> u[i] >> v[i];

        }

        for (int i=1;i<=m;i++){

            for (int j=1; j<=n; j++) vt[j].clear();
            for (int j=1; j<=m; j++){
                if (j==i) continue;
                vt[u[j]].push_back(v[j]);
                vt[v[j]].push_back(u[j]);
            }
            for (int j=1;j<=n;j++) seen[j]=0;
            res=0;
            for (int j=1;j<=n;j++){
                if (!seen[j]) bfs(j);
            }
            if (i!=m) cout << res<<' ';
            //else cout << res<<'\n';

        }
        //cout << '\n';

    }
    return 0;

}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 2ms
memory: 6900kb

input:

3
7 5
1 2 1 2 1 2 1
1 2
1 3
2 4
5 6
5 7
3 3
1 2 3
1 2
1 3
2 3
2 3
12345 54321
1 2
1 2
1 1

output:

6 5 5 5 1 1 1 1 

result:

wrong answer 1st lines differ - expected: '6 5 5 5 4', found: '6 5 5 5 1 1 1 1 '