Submission #1065962

# Submission time Handle Problem Language Result Execution time Memory
1065962 2024-08-19T13:37:36 Z EkinOnal Deblo (COCI18_deblo) C++17
0 / 90
1000 ms 24332 KB
//#pragma GCC optimize("O3,unroll-loops,Ofast")
//#pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt")
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;
 
#define MAX 200007
#define pb push_back
#define mp make_pair 
#define int long long
#define f first
#define s second
#define vi vector<int>
#define pii pair<int,int>
#define si set<int>
#define vpii vector<pair<int,int>> 
const int mod = 1e9+7;
const int INF = 1e18;
// myMap.begin()->first :  key
// myMap.begin()->second : value
 
int epow(int a,int b){int ans=1;while(b){if(b&1) ans*=a;a*=a;;b>>=1;}return ans;}
int gcd(int a,int b) {if(a<b)swap(a,b);while(b){int tmp=b;b=a%b;a=tmp;}return a;}
int mul(int a,int b){return ((a%mod)*(b%mod))%mod;}
int sum(int a,int b){return ((a%mod)+(b%mod))%mod;}
 
//typedef tree<pii,null_type,less<pii>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
vi dead(MAX),v(MAX);
vi adj[MAX],degree(MAX);
priority_queue<pii,vector<pii>,greater<pii>> pq;

int ans=0;
int dfs(int node,int par,int curr){
	int now=0;
	for(auto u : adj[node]){
		if(u==par || dead[u]) continue;
		now+=dfs(u,node,curr^v[u]);
	//	now+=curr^v[u];
	}
	return curr+now;
}
	
	
void solve(){
	int n; cin>>n;
	for(int i=1;i<=n;i++) cin>>v[i];

	for(int i=1;i<n;i++){
		int a,b; cin>>a>>b;
		adj[a].pb(b); adj[b].pb(a);
		degree[a]++;
		degree[b]++;
	}

	for(int i=1;i<=n;i++){
		pq.push({degree[i],i});
	}

	int cvp=0;
	while(pq.size()){
		int node=pq.top().s;  pq.pop();
		cvp+=dfs(node,node,v[node]);  dead[node]=true;
		ans=0;

	//	cout<<node<<" "<<cvp<<endl;

	}
	cout<<cvp<<endl;
		
	return;
}
 
int32_t main() {
//	freopen("hayfeast.in", "r", stdin);
//	freopen("hayfeast.out", "w", stdout);
	ios_base::sync_with_stdio(0);cin.tie(0);   
 
    int t=1;
 //   cin >> t;
    while (t--) solve();
 
    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 9820 KB Output isn't correct
2 Incorrect 4 ms 9820 KB Output isn't correct
3 Incorrect 7 ms 9820 KB Output isn't correct
4 Incorrect 6 ms 9820 KB Output isn't correct
5 Incorrect 7 ms 9952 KB Output isn't correct
6 Execution timed out 1077 ms 24332 KB Time limit exceeded
7 Execution timed out 1048 ms 24164 KB Time limit exceeded
8 Execution timed out 1041 ms 18384 KB Time limit exceeded
9 Execution timed out 1057 ms 17664 KB Time limit exceeded
10 Execution timed out 1040 ms 17352 KB Time limit exceeded