Submission #1092091

#TimeUsernameProblemLanguageResultExecution timeMemory
1092091vjudge1Bosses (BOI16_bosses)C++17
0 / 100
0 ms348 KiB
#include <bits/stdc++.h>

#define int long long
#define pb push_back

using namespace std;

const int maxn = 5e3 + 10;

int n, h[maxn];
bool mark[maxn];
vector <int> adj[maxn];
queue <int> q;

int32_t main (){
	ios_base::sync_with_stdio(0);
	int n;
	cin >> n;
	for (int x, y, i = 0; i < n; i++){
		cin >> x;
		for (int y, j = 0; j < x; j++)
			cin >> y,
			adj[--y].pb(i);
	}
	int ans = 1e15;
	for (int i = 0; i < n; i++){
		for (int i = 0; i < n; i++) mark[i] = h[i] = 0;
		q.push(i), mark[i] = 1, h[i] = 1;
		int tmp = 0;
		while (q.size()){
			int v = q.front(); q.pop();
			tmp += h[v];
			for (auto u : adj[v])
				if (!mark[u])
					q.push(u), mark[u] = 1, h[u] = h[v] + 1;
		}
		ans = min(ans, tmp);
	}
	cout << ans;
}

Compilation message (stderr)

bosses.cpp: In function 'int32_t main()':
bosses.cpp:19:14: warning: unused variable 'y' [-Wunused-variable]
   19 |  for (int x, y, i = 0; i < n; i++){
      |              ^
bosses.cpp:27:46: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   27 |   for (int i = 0; i < n; i++) mark[i] = h[i] = 0;
      |                                         ~~~~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...