Submission #1111356

# Submission time Handle Problem Language Result Execution time Memory
1111356 2024-11-12T07:33:57 Z hmm789 Drivers (BOI24_drivers) C++14
100 / 100
132 ms 23980 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long 

int p[200000];
int root(int x) {
	if(p[x] == x) return x;
	else return p[x] = root(p[x]);
}
void merge(int x, int y) {
	x = root(x); y = root(y);
	if(x == y) return;
	p[x] = y;
}

int32_t main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n, m, q, x, y, w;
	cin >> n >> m >> q;
	vector<tuple<int, int, int>> edg;
	for(int i = 0; i < m; i++) {
		cin >> x >> y >> w;
		x--; y--;
		edg.push_back({w, x, y});
	}
	sort(edg.begin(), edg.end());
	tuple<int, int, int, int> qry[q];
	int ans[q];
	for(int i = 0; i < q; i++) {
		cin >> x >> y >> w;
		x--; y--;
		qry[i] = {w, i, x, y};
	}
	sort(qry, qry+q);
	for(int i = 0; i < n; i++) p[i] = i;
	int idx = 0;
	for(int i = 0; i < q; i++) {
		int x, y, w, ind;
		tie(w, ind, x, y) = qry[i];
		while(idx < edg.size() && get<0>(edg[idx]) <= w) {
			int nx = get<1>(edg[idx]);
			int ny = get<2>(edg[idx]);
			merge(nx, ny);
			idx++;
		}
		ans[ind] = root(x) == root(y);
	}
	for(int i = 0; i < q; i++) {
		if(ans[i]) cout << "TAIP\n";
		else cout << "NE\n";
	}
}

Compilation message

Main.cpp: In function 'int32_t main()':
Main.cpp:41:13: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::tuple<long long int, long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |   while(idx < edg.size() && get<0>(edg[idx]) <= w) {
      |         ~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 2 ms 604 KB Output is correct
3 Correct 2 ms 608 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 68 ms 11852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 2 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 592 KB Output is correct
8 Correct 2 ms 600 KB Output is correct
9 Correct 2 ms 592 KB Output is correct
10 Correct 2 ms 608 KB Output is correct
11 Correct 2 ms 592 KB Output is correct
12 Correct 3 ms 892 KB Output is correct
13 Correct 2 ms 592 KB Output is correct
14 Correct 4 ms 848 KB Output is correct
15 Correct 1 ms 472 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 592 KB Output is correct
19 Correct 6 ms 1524 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 2 ms 336 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 5 ms 1356 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 2 ms 604 KB Output is correct
3 Correct 2 ms 608 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 68 ms 11852 KB Output is correct
6 Correct 1 ms 508 KB Output is correct
7 Correct 2 ms 592 KB Output is correct
8 Correct 3 ms 848 KB Output is correct
9 Correct 2 ms 592 KB Output is correct
10 Correct 3 ms 784 KB Output is correct
11 Correct 3 ms 848 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 504 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 2 ms 604 KB Output is correct
3 Correct 2 ms 608 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 68 ms 11852 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 2 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 592 KB Output is correct
13 Correct 2 ms 600 KB Output is correct
14 Correct 2 ms 592 KB Output is correct
15 Correct 2 ms 608 KB Output is correct
16 Correct 2 ms 592 KB Output is correct
17 Correct 3 ms 892 KB Output is correct
18 Correct 2 ms 592 KB Output is correct
19 Correct 4 ms 848 KB Output is correct
20 Correct 1 ms 472 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 592 KB Output is correct
24 Correct 6 ms 1524 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 2 ms 336 KB Output is correct
28 Correct 1 ms 336 KB Output is correct
29 Correct 5 ms 1356 KB Output is correct
30 Correct 1 ms 336 KB Output is correct
31 Correct 1 ms 508 KB Output is correct
32 Correct 2 ms 592 KB Output is correct
33 Correct 3 ms 848 KB Output is correct
34 Correct 2 ms 592 KB Output is correct
35 Correct 3 ms 784 KB Output is correct
36 Correct 3 ms 848 KB Output is correct
37 Correct 1 ms 336 KB Output is correct
38 Correct 1 ms 336 KB Output is correct
39 Correct 1 ms 504 KB Output is correct
40 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 2 ms 604 KB Output is correct
3 Correct 2 ms 608 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 68 ms 11852 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 2 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 592 KB Output is correct
13 Correct 2 ms 600 KB Output is correct
14 Correct 2 ms 592 KB Output is correct
15 Correct 2 ms 608 KB Output is correct
16 Correct 2 ms 592 KB Output is correct
17 Correct 3 ms 892 KB Output is correct
18 Correct 2 ms 592 KB Output is correct
19 Correct 4 ms 848 KB Output is correct
20 Correct 1 ms 472 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 592 KB Output is correct
24 Correct 6 ms 1524 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 2 ms 336 KB Output is correct
28 Correct 1 ms 336 KB Output is correct
29 Correct 5 ms 1356 KB Output is correct
30 Correct 1 ms 336 KB Output is correct
31 Correct 1 ms 508 KB Output is correct
32 Correct 2 ms 592 KB Output is correct
33 Correct 3 ms 848 KB Output is correct
34 Correct 2 ms 592 KB Output is correct
35 Correct 3 ms 784 KB Output is correct
36 Correct 3 ms 848 KB Output is correct
37 Correct 1 ms 336 KB Output is correct
38 Correct 1 ms 336 KB Output is correct
39 Correct 1 ms 504 KB Output is correct
40 Correct 1 ms 336 KB Output is correct
41 Correct 132 ms 23980 KB Output is correct
42 Correct 9 ms 1992 KB Output is correct
43 Correct 8 ms 1992 KB Output is correct
44 Correct 16 ms 2760 KB Output is correct
45 Correct 12 ms 2248 KB Output is correct
46 Correct 8 ms 1612 KB Output is correct
47 Correct 104 ms 17860 KB Output is correct
48 Correct 11 ms 2248 KB Output is correct
49 Correct 91 ms 23524 KB Output is correct