답안 #975764

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
975764 2024-05-05T20:12:36 Z OAleksa 자매 도시 (APIO20_swap) C++14
37 / 100
2000 ms 13508 KB
#include "swap.h"
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 69;
vector<tuple<int, int, int>> edges;
int n, m, p[N], sz[N], dg, deg[N];
int root(int v) {
  if (p[v] == v)
    return v;
  return p[v] = root(p[v]);
}
void init(int _n, int _m, vector<int> u, vector<int> v, vector<int> w) {
  n = _n;
  m = _m;
  for (int i = 0;i < m;i++) {
    edges.push_back({w[i], u[i], v[i]});
    deg[u[i]]++;
    deg[v[i]]++;
  }
}

int getMinimumFuelCapacity(int x, int y) {
  int ans = -1;
  int l = 1, r = 1e9;
  auto check = [&](int mid) {
    for (int i = 0;i < n;i++) {
      p[i] = i;
      sz[i] = 1;
      deg[i] = 0;
    }
    for (int i = 0;i < m;i++) {
      int a, b, c;
      tie(c, a, b) = edges[i];
      if (c > mid)
        continue;
      deg[a]++;
      deg[b]++;
      int t = root(a);
      int tt = root(b);
      if (t != tt) {
        if (sz[t] < sz[tt])
          swap(t, tt);
        sz[t] += sz[tt];
        p[tt] = t;
      }
    }
    if (root(x) != root(y))
      return false;
    bool ok = 0, all = 1;
    for (int i = 0;i < n;i++) {
      if (root(i) == root(x)) {
        ok |= (deg[i] > 2);
        all &= (deg[i] == 2);
      }
    }
    return ok || all;
  };
  while (l <= r) {
    int mid = (l + r) / 2;
    if (check(mid)) {
      ans = mid;
      r = mid - 1;
    }
    else
      l = mid + 1;
  }
  return ans;
}
/*
5 6
0 1 4
0 2 4
1 2 1
1 3 2
1 4 10
2 3 3
3
1 2
2 4
0 1

3 2
0 1 5
0 2 5
1
1 2

*/
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 2 ms 500 KB Output is correct
7 Correct 2 ms 348 KB Output is correct
8 Correct 2 ms 348 KB Output is correct
9 Correct 107 ms 4060 KB Output is correct
10 Correct 254 ms 4564 KB Output is correct
11 Correct 314 ms 4564 KB Output is correct
12 Correct 336 ms 4812 KB Output is correct
13 Correct 384 ms 4808 KB Output is correct
14 Execution timed out 2049 ms 4308 KB Time limit exceeded
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Execution timed out 2044 ms 6092 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 2 ms 500 KB Output is correct
7 Correct 2 ms 348 KB Output is correct
8 Correct 2 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 2 ms 348 KB Output is correct
11 Correct 2 ms 348 KB Output is correct
12 Correct 2 ms 348 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 2 ms 348 KB Output is correct
15 Correct 2 ms 348 KB Output is correct
16 Correct 2 ms 348 KB Output is correct
17 Correct 2 ms 348 KB Output is correct
18 Correct 2 ms 524 KB Output is correct
19 Correct 2 ms 348 KB Output is correct
20 Correct 2 ms 348 KB Output is correct
21 Correct 2 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 2 ms 344 KB Output is correct
24 Correct 3 ms 348 KB Output is correct
25 Correct 2 ms 344 KB Output is correct
26 Correct 3 ms 348 KB Output is correct
27 Correct 2 ms 348 KB Output is correct
28 Correct 2 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 2 ms 500 KB Output is correct
8 Correct 2 ms 348 KB Output is correct
9 Correct 2 ms 348 KB Output is correct
10 Correct 107 ms 4060 KB Output is correct
11 Correct 254 ms 4564 KB Output is correct
12 Correct 314 ms 4564 KB Output is correct
13 Correct 336 ms 4812 KB Output is correct
14 Correct 384 ms 4808 KB Output is correct
15 Correct 2 ms 348 KB Output is correct
16 Correct 2 ms 348 KB Output is correct
17 Correct 2 ms 348 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 2 ms 348 KB Output is correct
20 Correct 2 ms 348 KB Output is correct
21 Correct 2 ms 348 KB Output is correct
22 Correct 2 ms 348 KB Output is correct
23 Correct 2 ms 524 KB Output is correct
24 Correct 2 ms 348 KB Output is correct
25 Correct 2 ms 348 KB Output is correct
26 Correct 2 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 2 ms 344 KB Output is correct
29 Correct 3 ms 348 KB Output is correct
30 Correct 2 ms 344 KB Output is correct
31 Correct 3 ms 348 KB Output is correct
32 Correct 2 ms 348 KB Output is correct
33 Correct 2 ms 344 KB Output is correct
34 Correct 10 ms 1368 KB Output is correct
35 Correct 353 ms 6588 KB Output is correct
36 Correct 343 ms 6612 KB Output is correct
37 Correct 344 ms 6604 KB Output is correct
38 Correct 349 ms 6452 KB Output is correct
39 Correct 336 ms 6572 KB Output is correct
40 Correct 333 ms 5956 KB Output is correct
41 Correct 372 ms 6868 KB Output is correct
42 Correct 351 ms 6604 KB Output is correct
43 Correct 321 ms 6672 KB Output is correct
44 Correct 336 ms 6856 KB Output is correct
45 Correct 399 ms 10440 KB Output is correct
46 Correct 353 ms 6604 KB Output is correct
47 Correct 343 ms 6612 KB Output is correct
48 Correct 369 ms 7088 KB Output is correct
49 Correct 72 ms 11460 KB Output is correct
50 Correct 84 ms 7212 KB Output is correct
51 Correct 289 ms 7880 KB Output is correct
52 Correct 471 ms 12636 KB Output is correct
53 Correct 423 ms 11976 KB Output is correct
54 Correct 550 ms 13508 KB Output is correct
55 Correct 345 ms 6572 KB Output is correct
56 Correct 540 ms 11520 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 2 ms 500 KB Output is correct
7 Correct 2 ms 348 KB Output is correct
8 Correct 2 ms 348 KB Output is correct
9 Correct 107 ms 4060 KB Output is correct
10 Correct 254 ms 4564 KB Output is correct
11 Correct 314 ms 4564 KB Output is correct
12 Correct 336 ms 4812 KB Output is correct
13 Correct 384 ms 4808 KB Output is correct
14 Execution timed out 2049 ms 4308 KB Time limit exceeded
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 2 ms 500 KB Output is correct
8 Correct 2 ms 348 KB Output is correct
9 Correct 2 ms 348 KB Output is correct
10 Correct 107 ms 4060 KB Output is correct
11 Correct 254 ms 4564 KB Output is correct
12 Correct 314 ms 4564 KB Output is correct
13 Correct 336 ms 4812 KB Output is correct
14 Correct 384 ms 4808 KB Output is correct
15 Execution timed out 2049 ms 4308 KB Time limit exceeded
16 Halted 0 ms 0 KB -