QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#261462#6127. Kawa ExamcatloverTL 4ms54608kbC++142.2kb2023-11-22 21:58:472023-11-22 21:58:48

Judging History

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

  • [2023-11-22 21:58:48]
  • 评测
  • 测评结果:TL
  • 用时:4ms
  • 内存:54608kb
  • [2023-11-22 21:58:47]
  • 提交

answer

#include <bits/stdc++.h>

#define int long long

#define file(task) if(fopen(task".inp", "r")) { freopen(task".inp", "r", stdin); freopen(task".out", "w", stdout); }
#define FOR(i, a, b) for(int i = (a), _b = (b); i <= _b; ++i)
#define FORD(i, a, b) for(int i = (a), _b = (b); i >= _b; --i)
#define fi first
#define se second
#define SZ(X) (int)(X.size())
#define pb push_back
#define all(X) X.begin(), X.end()

using namespace std;

typedef pair<int, int> pii;

const int maxN = 1e6;

int N, M;
int g[maxN+5];
pii e[maxN+5];

void read_input()
{
  cin >> N >> M;
  FOR(i, 1, N) cin >> g[i];
  FOR(i, 1, M)
  {
    cin >> e[i].fi >> e[i].se;
  }
}

namespace trau
{
  vector<int> adj[maxN+5];
  vector<int> tplt[maxN+5];
  int K = 0;
  int vst[maxN+5];

  void clr()
  {
    K = 0;
    FOR(i, 1, N)
    {
      adj[i].clear();
      vst[i] = false;
      tplt[i].clear();
    }
  }

  void dfs(int u)
  {
    vst[u] = true;
    tplt[K].pb(u);
    for(int v : adj[u])
    {
      if(vst[v] == true) continue;
      dfs(v);
    }
  }

  void solve()
  {
    FOR(i, 1, M)
    {
      clr();
      int res = 0;
      FOR(j, 1, M)
      {
        if(i == j) continue;
        int u = e[j].fi, v = e[j].se;
        adj[u].pb(v);
        adj[v].pb(u);
      }
      FOR(j, 1, N)
      {
        if(vst[j] == false)
        {
          ++K;
          dfs(j);
        }
      }
      FOR(j, 1, K)
      {
        sort(all(tplt[j]), [](int &x, int &y)
        {
          return g[x] < g[y];
        });
        int cnt = 0, t = 0;
        while(t < SZ(tplt[j]))
        {
          int curC = g[tplt[j][t]], curCNT = 0;
          while(t < SZ(tplt[j]) && curC == g[tplt[j][t]])
          {
            ++curCNT;
            ++t;
          }
          cnt = max(cnt, curCNT);
        }
        res += cnt;
      }
      cout << res;
      if(i != M) cout << " ";
    }
    cout << '\n';
  }
}

void solve()
{
  int testcase; cin >> testcase;
  while(testcase --> 0)
  {
    read_input();
    trau::solve();
  }
}

int32_t main()
{
  cin.tie(0)->sync_with_stdio(0);

  file("PARK");

  solve();

  return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 4ms
memory: 54608kb

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: