답안 #743683

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
743683 2023-05-17T17:18:31 Z speedyArda 자매 도시 (APIO20_swap) C++14
13 / 100
2000 ms 14988 KB
#include "swap.h"
#include "bits/stdc++.h"
#include <vector>
using namespace std;
using ll = long long;
const int MAXN = 1e5+5;
vector < vector< pair<ll, ll> > > adj(MAXN);
int sum_dist = 0;
int dist[MAXN];
int par[MAXN], sz[MAXN], edge_sz[MAXN], max_sz[MAXN], cnt[MAXN];
int max_ed = 0, u_max;
int n, m;
vector < pair<int, pair<int, int> > > edges;

int find(int v)
{
  if(par[v] == v)
    return v;
  return par[v] = find(par[v]);
}

void merge(int a, int b)
{
  int maxi = max(cnt[a], cnt[b]);
  a = find(a), b = find(b);
  if(a == b) {
    edge_sz[a]++;
    max_sz[a] = max(max_sz[a], maxi);
    return;
  }
  if(sz[a] < sz[b])
    swap(a, b);
  par[b] = a;
  sz[a] += sz[b];
  edge_sz[a]++;
  max_sz[a] = max(max_sz[a], max(max_sz[b], maxi));
}
void init(int N, int M, vector<int> U, vector<int> V, vector<int> W) {

    m = M;
    n = N;

    for(int i = 0; i < M; i++)
    {
      adj[U[i]].push_back({W[i], V[i]});
      adj[V[i]].push_back({W[i], U[i]});
      dist[V[i]] = W[i]; // for sub 2
      edges.push_back({W[i], {U[i], V[i]}});
      u_max = max(u_max, U[i]);
      sum_dist = max(sum_dist, W[i]);
    }
    sort(edges.begin(), edges.end());
    for(int i = 0; i < N; i++)
    {
      sort(adj[i].begin(), adj[i].end());
      max_ed = max(max_ed, (int)adj[i].size());
    }

}

int getMinimumFuelCapacity(int X, int Y) {
  if(max_ed <= 2) // Sub 1
  {
    if(m == n - 1)
      return -1;
    else
      return sum_dist;
  }

  if(u_max == 0) // Sub 2
  {
    if(X > Y)
      swap(X, Y);
    ll sum = max(dist[X], dist[Y]);
    if(X != 0) {
      
      sum = max(sum, (adj[0][0].second != X && adj[0][0].second != Y) ? adj[0][0].first : ((adj[0][1].second != X && adj[0][1].second != Y) ? adj[0][1].first : adj[0][2].first));
    } else 
    {
      sum = max(sum, (adj[0][0].second != Y ? max(adj[0][0].first, adj[0][1].second != Y ? adj[0][1].first : adj[0][2].first) : max(adj[0][1].first, adj[0][2].first)));
    }
    return sum;
  }

  for(int i = 0; i < n; i++)
  {
    cnt[i] = 0;
    edge_sz[i] = max_sz[i] = 0;
    sz[i] = 1;
    par[i] = i;
  }

  for(pair<int, pair<int, int> > edge : edges)
  {
    cnt[edge.second.first]++;
    cnt[edge.second.second]++;
    merge(edge.second.first, edge.second.second);

    if(find(X) == find(Y))
    {
      int curr = find(X);
      if(edge_sz[curr] >= sz[curr] || max_sz[curr] > 2)
        return edge.first;
    }
  }


  return -1;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 1 ms 2644 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 2 ms 2644 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 2 ms 2772 KB Output is correct
8 Correct 2 ms 2644 KB Output is correct
9 Correct 54 ms 9896 KB Output is correct
10 Correct 71 ms 11388 KB Output is correct
11 Correct 91 ms 11248 KB Output is correct
12 Correct 71 ms 11756 KB Output is correct
13 Correct 73 ms 11804 KB Output is correct
14 Correct 57 ms 10032 KB Output is correct
15 Correct 118 ms 13180 KB Output is correct
16 Correct 142 ms 13008 KB Output is correct
17 Correct 128 ms 13544 KB Output is correct
18 Correct 116 ms 13480 KB Output is correct
19 Correct 52 ms 7500 KB Output is correct
20 Correct 144 ms 14448 KB Output is correct
21 Correct 131 ms 14364 KB Output is correct
22 Correct 120 ms 14884 KB Output is correct
23 Correct 124 ms 14988 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 115 ms 13756 KB Output is correct
4 Correct 119 ms 14124 KB Output is correct
5 Correct 115 ms 14248 KB Output is correct
6 Correct 134 ms 13940 KB Output is correct
7 Correct 113 ms 14192 KB Output is correct
8 Correct 113 ms 13792 KB Output is correct
9 Correct 113 ms 13952 KB Output is correct
10 Correct 122 ms 13696 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 1 ms 2644 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 2 ms 2644 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 2 ms 2772 KB Output is correct
8 Correct 2 ms 2644 KB Output is correct
9 Correct 2 ms 2644 KB Output is correct
10 Correct 2 ms 2772 KB Output is correct
11 Correct 2 ms 2772 KB Output is correct
12 Correct 2 ms 2772 KB Output is correct
13 Correct 2 ms 2772 KB Output is correct
14 Correct 2 ms 2772 KB Output is correct
15 Correct 2 ms 2772 KB Output is correct
16 Correct 2 ms 2772 KB Output is correct
17 Correct 2 ms 2772 KB Output is correct
18 Correct 2 ms 2772 KB Output is correct
19 Correct 3 ms 2772 KB Output is correct
20 Correct 2 ms 2772 KB Output is correct
21 Correct 2 ms 2772 KB Output is correct
22 Correct 2 ms 2772 KB Output is correct
23 Correct 2 ms 2772 KB Output is correct
24 Incorrect 3 ms 2772 KB Output isn't correct
25 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 1 ms 2644 KB Output is correct
4 Correct 1 ms 2644 KB Output is correct
5 Correct 2 ms 2644 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 2 ms 2772 KB Output is correct
9 Correct 2 ms 2644 KB Output is correct
10 Correct 54 ms 9896 KB Output is correct
11 Correct 71 ms 11388 KB Output is correct
12 Correct 91 ms 11248 KB Output is correct
13 Correct 71 ms 11756 KB Output is correct
14 Correct 73 ms 11804 KB Output is correct
15 Correct 2 ms 2772 KB Output is correct
16 Correct 2 ms 2772 KB Output is correct
17 Correct 2 ms 2772 KB Output is correct
18 Correct 2 ms 2772 KB Output is correct
19 Correct 2 ms 2772 KB Output is correct
20 Correct 2 ms 2772 KB Output is correct
21 Correct 2 ms 2772 KB Output is correct
22 Correct 2 ms 2772 KB Output is correct
23 Correct 2 ms 2772 KB Output is correct
24 Correct 3 ms 2772 KB Output is correct
25 Correct 2 ms 2772 KB Output is correct
26 Correct 2 ms 2772 KB Output is correct
27 Correct 2 ms 2772 KB Output is correct
28 Correct 2 ms 2772 KB Output is correct
29 Incorrect 3 ms 2772 KB Output isn't correct
30 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 1 ms 2644 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 2 ms 2644 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 2 ms 2772 KB Output is correct
8 Correct 2 ms 2644 KB Output is correct
9 Correct 54 ms 9896 KB Output is correct
10 Correct 71 ms 11388 KB Output is correct
11 Correct 91 ms 11248 KB Output is correct
12 Correct 71 ms 11756 KB Output is correct
13 Correct 73 ms 11804 KB Output is correct
14 Correct 57 ms 10032 KB Output is correct
15 Correct 118 ms 13180 KB Output is correct
16 Correct 142 ms 13008 KB Output is correct
17 Correct 128 ms 13544 KB Output is correct
18 Correct 116 ms 13480 KB Output is correct
19 Correct 115 ms 13756 KB Output is correct
20 Correct 119 ms 14124 KB Output is correct
21 Correct 115 ms 14248 KB Output is correct
22 Correct 134 ms 13940 KB Output is correct
23 Correct 113 ms 14192 KB Output is correct
24 Correct 113 ms 13792 KB Output is correct
25 Correct 113 ms 13952 KB Output is correct
26 Correct 122 ms 13696 KB Output is correct
27 Correct 2 ms 2772 KB Output is correct
28 Correct 2 ms 2772 KB Output is correct
29 Correct 2 ms 2772 KB Output is correct
30 Correct 2 ms 2772 KB Output is correct
31 Correct 2 ms 2772 KB Output is correct
32 Correct 2 ms 2772 KB Output is correct
33 Correct 2 ms 2772 KB Output is correct
34 Correct 2 ms 2772 KB Output is correct
35 Correct 2 ms 2772 KB Output is correct
36 Correct 9 ms 4180 KB Output is correct
37 Correct 87 ms 12540 KB Output is correct
38 Correct 91 ms 12460 KB Output is correct
39 Correct 90 ms 12520 KB Output is correct
40 Correct 82 ms 12464 KB Output is correct
41 Correct 80 ms 12392 KB Output is correct
42 Correct 73 ms 11616 KB Output is correct
43 Correct 88 ms 12568 KB Output is correct
44 Correct 108 ms 12652 KB Output is correct
45 Correct 95 ms 12520 KB Output is correct
46 Correct 88 ms 12528 KB Output is correct
47 Execution timed out 2087 ms 4180 KB Time limit exceeded
48 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 1 ms 2644 KB Output is correct
4 Correct 1 ms 2644 KB Output is correct
5 Correct 2 ms 2644 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 2 ms 2772 KB Output is correct
9 Correct 2 ms 2644 KB Output is correct
10 Correct 54 ms 9896 KB Output is correct
11 Correct 71 ms 11388 KB Output is correct
12 Correct 91 ms 11248 KB Output is correct
13 Correct 71 ms 11756 KB Output is correct
14 Correct 73 ms 11804 KB Output is correct
15 Correct 57 ms 10032 KB Output is correct
16 Correct 118 ms 13180 KB Output is correct
17 Correct 142 ms 13008 KB Output is correct
18 Correct 128 ms 13544 KB Output is correct
19 Correct 116 ms 13480 KB Output is correct
20 Correct 115 ms 13756 KB Output is correct
21 Correct 119 ms 14124 KB Output is correct
22 Correct 115 ms 14248 KB Output is correct
23 Correct 134 ms 13940 KB Output is correct
24 Correct 113 ms 14192 KB Output is correct
25 Correct 113 ms 13792 KB Output is correct
26 Correct 113 ms 13952 KB Output is correct
27 Correct 122 ms 13696 KB Output is correct
28 Correct 2 ms 2772 KB Output is correct
29 Correct 2 ms 2772 KB Output is correct
30 Correct 2 ms 2772 KB Output is correct
31 Correct 2 ms 2772 KB Output is correct
32 Correct 2 ms 2772 KB Output is correct
33 Correct 2 ms 2772 KB Output is correct
34 Correct 2 ms 2772 KB Output is correct
35 Correct 2 ms 2772 KB Output is correct
36 Correct 2 ms 2772 KB Output is correct
37 Correct 9 ms 4180 KB Output is correct
38 Correct 87 ms 12540 KB Output is correct
39 Correct 91 ms 12460 KB Output is correct
40 Correct 90 ms 12520 KB Output is correct
41 Correct 82 ms 12464 KB Output is correct
42 Correct 80 ms 12392 KB Output is correct
43 Correct 73 ms 11616 KB Output is correct
44 Correct 88 ms 12568 KB Output is correct
45 Correct 108 ms 12652 KB Output is correct
46 Correct 95 ms 12520 KB Output is correct
47 Correct 88 ms 12528 KB Output is correct
48 Execution timed out 2087 ms 4180 KB Time limit exceeded
49 Halted 0 ms 0 KB -