Submission #813330

#TimeUsernameProblemLanguageResultExecution timeMemory
813330vjudge1Bosses (BOI16_bosses)C++17
22 / 100
1 ms724 KiB
#include <bits/stdc++.h>
#define int long long

using namespace std;

void open(){
	if(fopen("input.inp", "r")){
		freopen("input.inp", "r", stdin);
		// freopen("output.out", "w", stdout);
	}
}

const int inf = 1e9 + 7;
const int maxn = 1e4 + 5;
int n;
vector<int> candidate[maxn];
vector<int> tr[maxn];
bool check[maxn];

signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	open();
	cin >> n;
	for(int i = 1; i <= n; i++){
		int k;
		cin >> k;
		for(int j = 1; j <= k; j++){
			int a;
			cin >> a;
			candidate[a].push_back(i);
		}
	}

	int root = 0;
	int max_adj = 0;

	for(int i = 1; i <= n; i++){
		if(root == 0 || max_adj < candidate[i].size()){
			root = i;
			max_adj = candidate[i].size();
		}
	}

	queue<pair<int, int>> q;
	q.push({root, 0});
	while(!q.empty()){
		int u = q.front().first;
		int p = q.front().second;
		q.pop();
		if(check[u]) continue;
		check[u] = true;
		tr[p].push_back(u);
		for(int v : candidate[u]){
			if(check[v]) continue;
			q.push({v, u});
		}
	}

	int result = 0;

	auto dfs = [&](auto &&dfs, int u) -> int {
		int sz = 1;
		for(int v : tr[u]){
			sz += dfs(dfs, v);
		}

		result += sz;
		return sz;
	};

	dfs(dfs, root);

	cout << result << endl;

	return 0;
}

Compilation message (stderr)

bosses.cpp: In function 'int main()':
bosses.cpp:39:27: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |   if(root == 0 || max_adj < candidate[i].size()){
      |                   ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~
bosses.cpp: In function 'void open()':
bosses.cpp:8:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    8 |   freopen("input.inp", "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...