Submission #807343

# Submission time Handle Problem Language Result Execution time Memory
807343 2023-08-04T16:10:28 Z Tunglam07 Odašiljači (COCI20_odasiljaci) C++17
0 / 70
1 ms 468 KB
#include<bits/stdc++.h>
using namespace std;
 
long long n, a[100001], parent[100001], ans[100001], sum = 0;
pair<int, pair<int, int>> connect[100001];
 
int findparent(int id)
{
	if(id == parent[id])	
	{
		return id;
	}
	else	
	{
		return parent[id] = findparent(parent[id]);
	}
}
 
int main()
{
	cin >> n;
	for(int i = 1; i <= n; ++i)
	{
		cin >> a[i];
		parent[i] = i;
		ans[i] = a[i];
	}
	for(int i = 1; i < n; ++i)
	{
		cin >> connect[i].second.first >> connect[i].second.second;
		connect[i].first = max(a[connect[i].second.first], a[connect[i].second.second]);
	}
	sort(connect + 1, connect + n);
	for(int i = 1; i < n; ++i)
	{
		long long x = findparent(connect[i].second.first), y = findparent(connect[i].second.second);
		sum = sum + ans[x] + ans[y];
		if(x != y)
		{
			parent[x] = y;
			ans[y] = max(ans[x], ans[y]);
		}
	}
	cout << sum;
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Incorrect 0 ms 212 KB Output isn't correct
4 Runtime error 1 ms 340 KB Execution killed with signal 11
5 Runtime error 1 ms 468 KB Execution killed with signal 11
6 Incorrect 1 ms 340 KB Output isn't correct
7 Incorrect 0 ms 212 KB Output isn't correct
8 Incorrect 1 ms 340 KB Output isn't correct
9 Runtime error 1 ms 468 KB Execution killed with signal 11
10 Runtime error 1 ms 468 KB Execution killed with signal 11