QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#261452#6127. Kawa Examthankhoi98TL 0ms13644kbC++143.3kb2023-11-22 21:51:482023-11-22 21:51:48

Judging History

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

  • [2023-11-22 21:51:48]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:13644kb
  • [2023-11-22 21:51:48]
  • 提交

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;
                }
            }
            if (i != m) cout << res << ' ';
            else 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;
}



Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 13644kb

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
6 6 7 6 6 6 6 6
3 3 3 4 4 3 3
7 7 7 7
9 9 9 8 9 8 9 8 9 9 10 9 9
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
7 8
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
9 10 9
16 16 16 16 16 17 16 16
10 10 11 10 12 11 10 10 10 10 10 10 10 12 10 10 10 10 10 11
10 9 9 9 9 9 9 9 9 9 9 9 9 9 10 ...

result: