답안 #110517

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
110517 2019-05-11T05:31:05 Z AngusRitossa Designated Cities (JOI19_designated_cities) C++14
0 / 100
415 ms 29260 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
vector<pair<int, pair<int, int> > > adj[200010];
int n;
int dgoingup[200010], dgoingdown[200010], done[200010];
int goingup(int a)
{
	if (dgoingup[a]) return dgoingup[a]-1;
	dgoingup[a] = 1;
	for (auto b : adj[a])
	{
		if (!dgoingup[b.first]) dgoingup[a] += goingup(b.first), dgoingup[a] += b.second.second;
	}
	return dgoingup[a]-1;
}
int goingdown(int a)
{
	if (dgoingdown[a]) return dgoingdown[a]-1;
	dgoingdown[a] = 1;
	for (auto b : adj[a])
	{
		if (!dgoingdown[b.first]) dgoingdown[a] += goingdown(b.first), dgoingdown[a] += b.second.first;
	}
	return dgoingdown[a]-1;
}
int oneans = 1e9;
void findoneans(int a, int above)
{
	done[a] = 1;
	int am = 0;
	for (auto b : adj[a])
	{
		if (done[b.first]) continue;
		am += goingup(b.first)+b.second.second;
	}
	oneans = min(oneans, am+above);
	for (auto b : adj[a])
	{
		if (done[b.first]) continue;
		findoneans(b.first, above+am-goingup(b.first)-b.second.second + b.second.first);
	}
}
#undef int
int main()
{
	#define int long long
	scanf("%lld", &n);
	for (int i = 1; i < n; i++)
	{
		int a, b, c, d;
		scanf("%lld%lld%lld%lld", &a, &b, &c, &d);
		a--;
		b--;
		adj[a].push_back({ b, { d, c }});
		adj[b].push_back({ a, { c, d }});
	}
	goingup(0), goingdown(0), findoneans(0, 0);
	printf("%lld\n", oneans);
}

Compilation message

designated_cities.cpp: In function 'int main()':
designated_cities.cpp:48:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld", &n);
  ~~~~~^~~~~~~~~~~~
designated_cities.cpp:52:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld%lld%lld%lld", &a, &b, &c, &d);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 7 ms 4992 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 4964 KB Output is correct
2 Incorrect 415 ms 29260 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 7 ms 5120 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 7 ms 4992 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 4964 KB Output is correct
2 Incorrect 415 ms 29260 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 7 ms 4992 KB Output isn't correct
2 Halted 0 ms 0 KB -