QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#261448#6127. Kawa Examthankhoi98WA 3ms13416kbC++143.3kb2023-11-22 21:49:462023-11-22 21:49:47

Judging History

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

  • [2023-11-22 21:49:47]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:13416kb
  • [2023-11-22 21:49:46]
  • 提交

answer

#include <bits/stdc++.h>

#define fi first
#define se second
#define pii pair<int, int>
#define mp make_pair
#define pb push_back
#define bit(X,i) ((X>>i)&1)
#define fori(i,d,c) for(int i = d; i <= c; ++ i)
#define ford(i,d,c) for(int i = d; i >= c; -- i)
#define all(V) V.begin(), V.end()
#define RRH(V) V.resize(unique(all(V))-V.begin())
#define debug(x) { cerr << #x << " = "; cerr << (x) << '\n'; }
#define open(Task) if (fopen(Task".inp", "r")) {freopen(Task".inp", "r", stdin);freopen(Task".out", "w", stdout);}

using namespace std;
using ll = long long;
using ld = long double;

const int maxn = 1e5 + 5;
const int maxm = 1e5 + 5;
const int base = 101;

int n, m;
int a[maxn];
vector<int> adj[maxn];
pii b[maxn];

void read() {
    cin >> n >> m;
    fori(i,1,n) cin >> a[i];
    fori(i,1,n) adj[i].clear();
    fori(i,1,m) {
        cin >> b[i].fi >> b[i].se;
        adj[b[i].fi].pb(i);
        adj[b[i].se].pb(i);
    }
}

namespace sub1 {
    unordered_map<int,int> f[maxn];
    int mark[maxn], timer, visit[maxn];
    void dfs(int u) {
        visit[u] = timer;
        for(int id : adj[u]) {
            if (mark[id]) continue;
            int v = b[id].fi == u ? b[id].se : b[id].fi;
            if (visit[v]) continue;
            dfs(v);
            if (f[u].size() < f[v].size()) swap(f[u], f[v]);
            for(auto [val, cnt] : f[v]) f[u][val] += cnt;
        }
        f[u][a[u]] ++;
    }
    void solve() {
        memset(mark, 0, sizeof mark);
        fori(i,1,m) {
            mark[i] = 1;
            timer = 0;
            fori(u,1,n) {
                visit[u] = 0;
                f[u].clear();
            }
            int res = 0;
            fori(u,1,n) {
                if (!visit[u]) {
                    timer ++;
                    dfs(u);
                    int tmp = 0;
                    for(auto [val, cnt] : f[u]) {
                        tmp = max(tmp, cnt);
                    }
                    res += tmp;
                }
            }
            cout << res << ' ';
            mark[i] = 0;
        }
        cout << '\n';
    }
}

namespace sub2 {
    int Num[maxn], Low[maxn], dd[maxn];
    stack<int> st;
    void dfs(int u) {
        Num[u] = ++Num[0];
        Low[u] = 1e9;
        st.push(u);
        for (int id : adj[u]) {
            int v = b[id].fi == u ? b[id].se : b[id].fi;
            if (!dd[v]) {
                    if (Num[v]) Low[u] = min(Low[u], Num[v]);
                    else {
                        dfs(v);
                        Low[u] = min(Low[u], Low[v]);
                    }
            }
        }
        if (Low[u] < Num[u]) return;
        for (;;) {
            int k = st.top();
            st.pop();
            dd[k] = 1;
            cout << k << ' ';
            if (k == u) {
                cout << '\n';
                return ;
            }
        }
    }
    void solve() {
        fori(i,1,n) {
            if (!Num[i]) {
                dfs(i);
            }
        }
    }
}

void solve() {
    sub1::solve();
}

int main () {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    open("park");
    int t; cin >> t; while(t-->0){
        read();
        solve();
    }
    return 0;
}



詳細信息

Test #1:

score: 0
Wrong Answer
time: 3ms
memory: 13416kb

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 '