Submission #976022

# Submission time Handle Problem Language Result Execution time Memory
976022 2024-05-06T05:22:17 Z josanneo22 Swapping Cities (APIO20_swap) C++17
37 / 100
2000 ms 9160 KB
#include "swap.h"

#include <vector>
#include <bits/stdc++.h>
using namespace std;
struct dsu {
   vector<int> fa, sz, mx_deg;
   vector<bool> ok;
   dsu(int n) {
      fa.resize(n + 10);
      iota(fa.begin(), fa.end(), 0);
      sz.assign(n + 10, 1);
      mx_deg.assign(n + 10, 0);
      ok.assign(n + 10, false);
   }
   int find(int x) {
      while (x != fa[x]) x = fa[x] = fa[fa[x]];
      return x;
   }
   bool merge(int x, int y) {
      int px = find(x), py = find(y);
      if (px == py) return false;
      if (sz[py] > sz[px]) swap(px, py);
      sz[px] += sz[py]; fa[py] = px;
      mx_deg[px] = max(mx_deg[px], mx_deg[py]);
      if (mx_deg[px] >= 3) ok[px] = true;
      return true;
   }
   bool same(int x, int y) {
      int px = find(x), py = find(y);
      return px == py;
   }
};
vector<pair<int, pair<int, int>>> edges;
int n;
void init(int _N, int M, std::vector<int> U, std::vector<int> V, std::vector<int> W) {
    n = _N;
    for (int i = 0; i < M; i++) 
      edges.push_back(make_pair(W[i], make_pair(U[i], V[i])));
    sort(edges.begin(), edges.end());
}
int getMinimumFuelCapacity(int X, int Y) {
   // cout << "++++++++++++++++\n";
   dsu D(n);
   vector<int> deg(n);
   for (int i = 0; i < edges.size(); i++) {
      int w = edges[i].first;
      int u = edges[i].second.first, v = edges[i].second.second;
      // cout << w << ' ' << u << ' ' << v << '\n';
      if (D.same(u, v)) D.ok[D.find(u)] = true;
      deg[u]++; deg[v]++;
      if (deg[u] >= 3) {
         D.mx_deg[D.find(u)] = 3;
         D.ok[D.find(u)] = true;
      }
      if (deg[v] >= 3) {
         D.mx_deg[D.find(v)] = 3;
         D.ok[D.find(v)] = true;
      }
      D.merge(u, v);
      if (D.same(X, Y) && D.ok[D.find(X)] == true) return w;
   }
   return -1;
}
// #include "grader.cpp"

Compilation message

swap.cpp: In function 'int getMinimumFuelCapacity(int, int)':
swap.cpp:46:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |    for (int i = 0; i < edges.size(); i++) {
      |                    ~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 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 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 1 ms 348 KB Output is correct
8 Correct 1 ms 596 KB Output is correct
9 Correct 29 ms 3796 KB Output is correct
10 Correct 43 ms 4308 KB Output is correct
11 Correct 52 ms 4356 KB Output is correct
12 Correct 49 ms 4356 KB Output is correct
13 Correct 43 ms 4316 KB Output is correct
14 Execution timed out 2089 ms 4048 KB Time limit exceeded
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Execution timed out 2052 ms 6812 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 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 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 1 ms 348 KB Output is correct
8 Correct 1 ms 596 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 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 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 596 KB Output is correct
10 Correct 29 ms 3796 KB Output is correct
11 Correct 43 ms 4308 KB Output is correct
12 Correct 52 ms 4356 KB Output is correct
13 Correct 49 ms 4356 KB Output is correct
14 Correct 43 ms 4316 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 1 ms 344 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 5 ms 1048 KB Output is correct
35 Correct 47 ms 4316 KB Output is correct
36 Correct 48 ms 4328 KB Output is correct
37 Correct 47 ms 4324 KB Output is correct
38 Correct 56 ms 4316 KB Output is correct
39 Correct 47 ms 4304 KB Output is correct
40 Correct 43 ms 4052 KB Output is correct
41 Correct 49 ms 4320 KB Output is correct
42 Correct 48 ms 4296 KB Output is correct
43 Correct 40 ms 4328 KB Output is correct
44 Correct 56 ms 4572 KB Output is correct
45 Correct 59 ms 6856 KB Output is correct
46 Correct 46 ms 4320 KB Output is correct
47 Correct 47 ms 4336 KB Output is correct
48 Correct 50 ms 4552 KB Output is correct
49 Correct 58 ms 7112 KB Output is correct
50 Correct 40 ms 4912 KB Output is correct
51 Correct 59 ms 5076 KB Output is correct
52 Correct 67 ms 7316 KB Output is correct
53 Correct 67 ms 8648 KB Output is correct
54 Correct 78 ms 9160 KB Output is correct
55 Correct 44 ms 4316 KB Output is correct
56 Correct 72 ms 8900 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 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 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 1 ms 348 KB Output is correct
8 Correct 1 ms 596 KB Output is correct
9 Correct 29 ms 3796 KB Output is correct
10 Correct 43 ms 4308 KB Output is correct
11 Correct 52 ms 4356 KB Output is correct
12 Correct 49 ms 4356 KB Output is correct
13 Correct 43 ms 4316 KB Output is correct
14 Execution timed out 2089 ms 4048 KB Time limit exceeded
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 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 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 596 KB Output is correct
10 Correct 29 ms 3796 KB Output is correct
11 Correct 43 ms 4308 KB Output is correct
12 Correct 52 ms 4356 KB Output is correct
13 Correct 49 ms 4356 KB Output is correct
14 Correct 43 ms 4316 KB Output is correct
15 Execution timed out 2089 ms 4048 KB Time limit exceeded
16 Halted 0 ms 0 KB -