QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#261693#6127. Kawa Examthankhoi98TL 0ms3724kbC++142.8kb2023-11-23 08:42:422023-11-23 08:42:43

Judging History

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

  • [2023-11-23 08:42:43]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:3724kb
  • [2023-11-23 08:42:42]
  • 提交

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;
        }
        if (x != m) cout << ans << " ";
        else cout << ans;
    }

    void solve()
    {
        v.clear();
        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);
        }
        cout << '\n';
    }
}

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

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

        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: 100
Accepted
time: 0ms
memory: 3724kb

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 4
1 1 1
1 1 1

result:

ok 3 lines

Test #2:

score: -100
Time Limit Exceeded

input:

5557
2 7
79960 79960
2 2
1 1
1 1
2 2
1 1
2 1
1 2
9 8
21881 70740 70740 21881 22458 22458 639 21881 70740
3 3
1 6
5 8
7 5
5 7
2 3
5 1
7 6
6 7
13064 20716 6746 13064 6746 69225
5 5
4 1
4 1
1 6
4 5
3 2
3 2
8 4
45146 14400 45146 45146 14400 72969 14400 45146
8 6
1 3
4 6
8 3
18 13
48132 37949 92338 92338...

output:

2 2 2 2 2 2 2
4 4 5 4 4 5 4 4
2 2 2 2 2 2 2
4 4 4 4
5 5 5 5 6 5 5 5 6 6 6 6 6
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
3 3
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
4 5 4
10 10 10 10 10 10 10 10
6 6 6 6 6 7 6 6 6 6 6 6 6 6 6 6 6 6 6 6
8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8
2 2 2 2 2 2 2 2 2 ...

result: