Submission #786651

# Submission time Handle Problem Language Result Execution time Memory
786651 2023-07-18T10:53:21 Z Dan4Life Designated Cities (JOI19_designated_cities) C++17
0 / 100
2 ms 5008 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define sz(a) (int)a.size()
const int mxN = (int)1e5+10;
int n, q, ans[mxN];
vector<array<int,2>> adj[mxN], tadj[mxN];

void rem(int s, int p){
	for(auto &[u,w] : adj[s]){
		if(u==p) continue;
		w = 0; rem(u,s);
	}
}

int dfs(int s, int p=-1){
	int tot = 0;
	for(auto [u,w] : adj[s])
		if(u!=p) tot+=w+dfs(u,s);
	return tot;
}

int getRoot(){
	pair<int,int> best = {-1,-1};
	for(int i = 0; i < n; i++)
		best=max(best,{dfs(i),i});
	return best.second*0;
}

int32_t main()
{
	cin >> n; int tot = 0;
	for(int i = 0; i < n-1; i++){
		int a, b, c, d;
		cin >> a >> b >> c >> d; 
		a--,b--, swap(c,d); tot+=c+d;
		adj[a].pb({b,c}); adj[b].pb({a,d});
		tadj[a].pb({b,c}); tadj[b].pb({a,d});
	}
	for(int x = 1; x <= n; x++){
		rem(getRoot(),-1);
		for(int i = 0; i < n; i++)
			for(auto [b,c] : adj[i]) ans[x]+=c;
	}
	cin >> q;
	while(q--){ int x; cin >> x,cout << ans[x] << "\n";}
}
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 5008 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 4948 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 4948 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 5008 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 4948 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 5008 KB Output isn't correct
2 Halted 0 ms 0 KB -