Submission #205773

# Submission time Handle Problem Language Result Execution time Memory
205773 2020-02-29T20:10:17 Z ly20 Toll (BOI17_toll) C++17
7 / 100
56 ms 2808 KB
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 512345;
long long v[MAXN];
int pai[MAXN], sz[MAXN];
int find(int a) {
	if(a == pai[a]) return a;
	return pai[a] = find(pai[a]);
}
void une(int a, int b) {
	a = find(a); b = find(b);
	if(sz[a] > sz[b]) swap(a, b);
	pai[a] = b;
	sz[b] += sz[a];
}
int main() {
	int k, n, m, o;
	scanf("%d %d %d %d", &k, &n, &m, &o);
	for(int i = 0; i < n; i++) {
		pai[i] = i; sz[i] = 1;
	}
	for(int i = 0; i < m; i++) {
		int a, b;
		scanf("%d %d", &a, &b);
		scanf("%lld", &v[b]);
		une(a, b);
	}
	for(int i = 1; i < n; i++) {
		v[i] += v[i - 1];
	}
	for(int i = 0; i < o; i++) {
		int a, b;
		scanf("%d %d", &a, &b);
		if(find(a) != find(b)) {
			printf("-1\n");
		}
		else if(a < b) printf("%lld\n", v[b] - v[a]);
		else printf("-1\n");
	}
	return 0;
}

Compilation message

toll.cpp: In function 'int main()':
toll.cpp:18:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d %d %d", &k, &n, &m, &o);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
toll.cpp:24:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &a, &b);
   ~~~~~^~~~~~~~~~~~~~~~~
toll.cpp:25:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld", &v[b]);
   ~~~~~^~~~~~~~~~~~~~~
toll.cpp:33:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &a, &b);
   ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 35 ms 2172 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 248 KB Output is correct
6 Correct 6 ms 376 KB Output is correct
7 Correct 6 ms 376 KB Output is correct
8 Correct 34 ms 2040 KB Output is correct
9 Correct 32 ms 2040 KB Output is correct
10 Correct 9 ms 1272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 56 ms 2808 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Incorrect 5 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Incorrect 5 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 35 ms 2172 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 248 KB Output is correct
6 Correct 6 ms 376 KB Output is correct
7 Correct 6 ms 376 KB Output is correct
8 Correct 34 ms 2040 KB Output is correct
9 Correct 32 ms 2040 KB Output is correct
10 Correct 9 ms 1272 KB Output is correct
11 Incorrect 56 ms 2808 KB Output isn't correct
12 Halted 0 ms 0 KB -