답안 #204072

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
204072 2020-02-24T08:04:56 Z ics0503 Designated Cities (JOI19_designated_cities) C++17
0 / 100
16 ms 10488 KB
#include<stdio.h>
#include<vector>
using namespace std;
struct xy { long long x, y, z; };
vector<xy>edge[212121];
long long D[212121];
void get_D(long long w,long long bef) {
	D[w] = 0;
	for (xy E : edge[w]) if (E.x != bef) {
		get_D(E.x, w);
		D[w] += D[E.x] + E.y;
	}
}
long long resX[212121];
void get_resX(long long w, long long bef, long long fromRoot) {
	long long sum = 0;
	for (xy E : edge[w]) if (E.x != bef) sum += D[E.x] + E.y;
	resX[w] = sum + fromRoot;
	for (xy E : edge[w]) if (E.x != bef) get_resX(E.x, w, fromRoot + sum - (D[E.x] + E.y) + E.z);
}
long long ans[212121];
int main() {
	freopen("input.txt", "r", stdin);
	long long n, i, j, allsum = 0; scanf("%lld", &n);
	for (i = 0; i < n - 1; i++) {
		long long s, e, a, b; scanf("%lld%lld%lld%lld", &s, &e, &a, &b);
		allsum += a; allsum += b;
		edge[s].push_back({ e, b, a });
		edge[e].push_back({ s, a, b });
	}
	get_D(1, -1);
	get_resX(1, -1, 0);
	long long rootSum = 0, root = 1;
	for (i = 1; i <= n; i++) if (rootSum < resX[i])rootSum = resX[i], root = i;
	ans[1] = allsum - rootSum;
	long long q, x; scanf("%lld %lld", &q, &x);
	if (q == 1 && x == 1)printf("%lld", ans[1]);
	return 0;
}  

Compilation message

designated_cities.cpp: In function 'int main()':
designated_cities.cpp:24:18: warning: unused variable 'j' [-Wunused-variable]
  long long n, i, j, allsum = 0; scanf("%lld", &n);
                  ^
designated_cities.cpp:33:25: warning: variable 'root' set but not used [-Wunused-but-set-variable]
  long long rootSum = 0, root = 1;
                         ^~~~
designated_cities.cpp:23:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
  freopen("input.txt", "r", stdin);
  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
designated_cities.cpp:24:38: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  long long n, i, j, allsum = 0; scanf("%lld", &n);
                                 ~~~~~^~~~~~~~~~~~
designated_cities.cpp:26:30: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   long long s, e, a, b; scanf("%lld%lld%lld%lld", &s, &e, &a, &b);
                         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
designated_cities.cpp:36:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  long long q, x; scanf("%lld %lld", &q, &x);
                  ~~~~~^~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 14 ms 10488 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 15 ms 10488 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 16 ms 10488 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 14 ms 10488 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 15 ms 10488 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 14 ms 10488 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -