QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#261691#6127. Kawa Examthankhoi98WA 1ms3476kbC++142.7kb2023-11-23 08:42:012023-11-23 08:42:01

Judging History

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

  • [2023-11-23 08:42:01]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3476kb
  • [2023-11-23 08:42:01]
  • 提交

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()
    {
        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;
}




详细

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3476kb

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:

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