QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#261689#6127. Kawa Examthankhoi98WA 0ms5820kbC++142.6kb2023-11-23 08:39:262023-11-23 08:39:26

Judging History

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

  • [2023-11-23 08:39:26]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:5820kb
  • [2023-11-23 08:39:26]
  • 提交

answer

//  Author : Nguyen Anh Tuan - THPT Chuyen Bac Giang - Train VOI 2023/2024

#include<bits/stdc++.h>
#define file(NAME) {freopen(NAME".inp", "r", stdin); freopen(NAME".out", "w", stdout);}
#define foru(i, a, b) for(int i=(a);i<=(b);i++)
#define ford(i, a, b) for(int i=(a);i>=(b);i--)
#define rep(i, n) for(int i=(1);i<=(n);i++)
#define fi first
#define se second
#define mp make_pair
#define SZ(v) ((int)((v).size()))
#define all(v) v.begin(),v.end()
#define RR(X) X.resize(unique(all(X)) - begin(X))

using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;

void maximum(ll &a, ll b) {if(b > a) a = b;}
void minimum(ll &a, ll b) {if(b < a) a = b;}
bool bit(int x, int i) {return (x >> i) & 1;}

//-----------------------------------------------------------------------------------
//      END OF TEMPLATE
//-----------------------------------------------------------------------------------
//      Nguyen Anh Tuan - AnhTuan_BG
//      PRAY FOR VOI 2023
//-----------------------------------------------------------------------------------

const int maxn = 100005;
int n, m;
int a[maxn];
int U[maxn];
int V[maxn];

namespace sub3
{
    const int maxn = 5005;
    int cnt[maxn][maxn];
    vector<int> v;
    vector<pii> adj[maxn];
    map<int, int> mmap;
    bool d[maxn];

    void dfs(int u, int x)
    {
        mmap[a[u]]++;
        d[u] = 1;
        for(auto [v, id] : adj[u])
        {
            if(id == x) continue;
            if(d[v]) continue;
            dfs(v, x);
        }
    }

    void solve(int x)
    {
        int ans = 0;
        foru(i, 1, n) d[i] = 0;
        foru(i, 1, n)
        {
            if(d[i]) continue;
            mmap.clear();
            dfs(i, x);
            int tmp = 0;
            for(auto [u, w] : mmap)
            {
                tmp = max(tmp, w);
            }

            ans += tmp;
        }
        cout << ans << " ";
    }

    void solve()
    {
        foru(i, 1, n) v.push_back(a[i]);
        sort(all(v));
        RR(v);
        foru(i, 1, n) a[i] = lower_bound(all(v), a[i]) - v.begin() + 1;
        foru(i, 1, m)
        {
            adj[U[i]].push_back(mp(V[i], i));
            adj[V[i]].push_back(mp(U[i], i));
        }
        foru(i, 1, m)
        {
            solve(i);
        }
    }
}

int main()
{
    ios_base :: sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
   // file("");

    cin >> n >> m;
    foru(i, 1, n) cin >> a[i];
    foru(i, 1, m) cin >> U[i] >> V[i];

    sub3 :: solve();

    return 0;
}




Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 5820kb

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:

1 1 1 1 2 1 1 

result:

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