Submission #1118484

# Submission time Handle Problem Language Result Execution time Memory
1118484 2024-11-25T14:40:25 Z quanquai Drivers (BOI24_drivers) C++11
100 / 100
144 ms 15932 KB
#include <bits/stdc++.h>
using namespace std;

#define i64 long long
#define i32 int
#define all(v) (v).begin(), (v).end()
#define task "drivers"

const int N = 2e5 + 123;

int n, m, q;
int ans[N];
array<int, 3> edge[N];
array<int, 4> que[N];

struct DSU {
   vector<int> par, sz;
   DSU(int n) : par(n + 1), sz(n + 1) {
      for (int i = 1; i <= n; i++) {
         par[i] = i;
         sz[i] = 1;
      }
   }
   int get(int u) {
      return (u == par[u] ? par[u] : par[u] = get(par[u]));
   }
   void join(int u, int v) {
      u = get(u);
      v = get(v);
      if (u == v) return;
      if (sz[u] < sz[v]) swap(u, v);
      par[v] = par[u];
      sz[u] += sz[v];
   }
   bool same(int u, int v) {
      u = get(u);
      v = get(v);
      return (u == v);
   }
};

int main() {
   ios::sync_with_stdio(false);
   cin.tie(0);
   if (fopen("drivers.inp", "r")) {
      freopen("drivers.inp", "r", stdin);
      freopen("drivers.out", "w", stdout);
   }
   cin >> n >> m >> q;
   for (int i = 0; i < m; i++) {
      int u, v, w;
      cin >> u >> v >> w;
      edge[i] = {w, u, v};
   }
   for (int i = 0; i < q; i++) {
      cin >> que[i][1] >> que[i][2] >> que[i][0];
      que[i][3] = i;
   }
   sort(que, que + q);
   sort(edge, edge + m);
   int j = 0;
   DSU dsu(n);
   for (int i = 0; i < q; i++) {
      while (j < m && edge[j][0] <= que[i][0]) {
         int u = edge[j][1];
         int v = edge[j][2];
         dsu.join(u, v);
         j++;
      }
      if (dsu.same(que[i][1], que[i][2])) {
         ans[que[i][3]] = 1;
      } else {
         ans[que[i][3]] = 0;
      }
   }
   for (int i = 0; i < q; i++) {
      if (ans[i]) {
         cout << "TAIP\n";
      } else {
         cout << "NE\n";
      }
   }

  return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:46:14: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   46 |       freopen("drivers.inp", "r", stdin);
      |       ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:47:14: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   47 |       freopen("drivers.out", "w", stdout);
      |       ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 2 ms 2572 KB Output is correct
3 Correct 2 ms 2580 KB Output is correct
4 Correct 2 ms 2396 KB Output is correct
5 Correct 66 ms 8788 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 2 ms 2552 KB Output is correct
4 Correct 2 ms 2548 KB Output is correct
5 Correct 2 ms 2396 KB Output is correct
6 Correct 2 ms 2384 KB Output is correct
7 Correct 3 ms 2640 KB Output is correct
8 Correct 2 ms 2388 KB Output is correct
9 Correct 3 ms 2656 KB Output is correct
10 Correct 3 ms 2384 KB Output is correct
11 Correct 3 ms 2552 KB Output is correct
12 Correct 3 ms 2628 KB Output is correct
13 Correct 2 ms 2640 KB Output is correct
14 Correct 3 ms 2640 KB Output is correct
15 Correct 1 ms 2384 KB Output is correct
16 Correct 1 ms 2388 KB Output is correct
17 Correct 1 ms 2536 KB Output is correct
18 Correct 2 ms 2396 KB Output is correct
19 Correct 8 ms 3012 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 2 ms 2396 KB Output is correct
23 Correct 2 ms 2556 KB Output is correct
24 Correct 5 ms 2908 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 2 ms 2572 KB Output is correct
3 Correct 2 ms 2580 KB Output is correct
4 Correct 2 ms 2396 KB Output is correct
5 Correct 66 ms 8788 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 2 ms 2396 KB Output is correct
8 Correct 3 ms 2400 KB Output is correct
9 Correct 3 ms 2396 KB Output is correct
10 Correct 4 ms 2544 KB Output is correct
11 Correct 4 ms 2652 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 2 ms 2532 KB Output is correct
14 Correct 1 ms 2384 KB Output is correct
15 Correct 1 ms 2384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 2 ms 2572 KB Output is correct
3 Correct 2 ms 2580 KB Output is correct
4 Correct 2 ms 2396 KB Output is correct
5 Correct 66 ms 8788 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 2 ms 2552 KB Output is correct
9 Correct 2 ms 2548 KB Output is correct
10 Correct 2 ms 2396 KB Output is correct
11 Correct 2 ms 2384 KB Output is correct
12 Correct 3 ms 2640 KB Output is correct
13 Correct 2 ms 2388 KB Output is correct
14 Correct 3 ms 2656 KB Output is correct
15 Correct 3 ms 2384 KB Output is correct
16 Correct 3 ms 2552 KB Output is correct
17 Correct 3 ms 2628 KB Output is correct
18 Correct 2 ms 2640 KB Output is correct
19 Correct 3 ms 2640 KB Output is correct
20 Correct 1 ms 2384 KB Output is correct
21 Correct 1 ms 2388 KB Output is correct
22 Correct 1 ms 2536 KB Output is correct
23 Correct 2 ms 2396 KB Output is correct
24 Correct 8 ms 3012 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 2 ms 2396 KB Output is correct
28 Correct 2 ms 2556 KB Output is correct
29 Correct 5 ms 2908 KB Output is correct
30 Correct 1 ms 2396 KB Output is correct
31 Correct 1 ms 2396 KB Output is correct
32 Correct 2 ms 2396 KB Output is correct
33 Correct 3 ms 2400 KB Output is correct
34 Correct 3 ms 2396 KB Output is correct
35 Correct 4 ms 2544 KB Output is correct
36 Correct 4 ms 2652 KB Output is correct
37 Correct 1 ms 2396 KB Output is correct
38 Correct 2 ms 2532 KB Output is correct
39 Correct 1 ms 2384 KB Output is correct
40 Correct 1 ms 2384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 2 ms 2572 KB Output is correct
3 Correct 2 ms 2580 KB Output is correct
4 Correct 2 ms 2396 KB Output is correct
5 Correct 66 ms 8788 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 2 ms 2552 KB Output is correct
9 Correct 2 ms 2548 KB Output is correct
10 Correct 2 ms 2396 KB Output is correct
11 Correct 2 ms 2384 KB Output is correct
12 Correct 3 ms 2640 KB Output is correct
13 Correct 2 ms 2388 KB Output is correct
14 Correct 3 ms 2656 KB Output is correct
15 Correct 3 ms 2384 KB Output is correct
16 Correct 3 ms 2552 KB Output is correct
17 Correct 3 ms 2628 KB Output is correct
18 Correct 2 ms 2640 KB Output is correct
19 Correct 3 ms 2640 KB Output is correct
20 Correct 1 ms 2384 KB Output is correct
21 Correct 1 ms 2388 KB Output is correct
22 Correct 1 ms 2536 KB Output is correct
23 Correct 2 ms 2396 KB Output is correct
24 Correct 8 ms 3012 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 2 ms 2396 KB Output is correct
28 Correct 2 ms 2556 KB Output is correct
29 Correct 5 ms 2908 KB Output is correct
30 Correct 1 ms 2396 KB Output is correct
31 Correct 1 ms 2396 KB Output is correct
32 Correct 2 ms 2396 KB Output is correct
33 Correct 3 ms 2400 KB Output is correct
34 Correct 3 ms 2396 KB Output is correct
35 Correct 4 ms 2544 KB Output is correct
36 Correct 4 ms 2652 KB Output is correct
37 Correct 1 ms 2396 KB Output is correct
38 Correct 2 ms 2532 KB Output is correct
39 Correct 1 ms 2384 KB Output is correct
40 Correct 1 ms 2384 KB Output is correct
41 Correct 144 ms 15932 KB Output is correct
42 Correct 10 ms 3152 KB Output is correct
43 Correct 9 ms 3152 KB Output is correct
44 Correct 21 ms 3152 KB Output is correct
45 Correct 19 ms 3408 KB Output is correct
46 Correct 8 ms 3152 KB Output is correct
47 Correct 106 ms 13760 KB Output is correct
48 Correct 17 ms 3408 KB Output is correct
49 Correct 108 ms 15700 KB Output is correct