Submission #1260329

#TimeUsernameProblemLanguageResultExecution timeMemory
1260329tminhBosses (BOI16_bosses)C++20
0 / 100
13 ms23876 KiB
#include "bits/stdc++.h"
using namespace std;

#define task ""
#define ll long long
#define endl '\n'
#define fi first
#define se second
#define vall(a) (a).begin(), (a).end()
#define sze(a) (int)a.size()
#define pii pair<int, int>
#define pll pair<ll, ll>


#define ep emplace_back
#define pb push_back
#define pf push_front


const ll mod = 1e9 + 7;
const int N = 1e6 + 5;
const ll oo = 1e18;

bool START;

int n;
bool vis[N];
ll dp[N];

vector<int> adj[N];
ll bfs(int s) {
	for (int i = 1; i <= n; ++i) {
		vis[i] = false;
		dp[i] = 1;
	}
	queue<int> q;
	stack<pii> st;
	q.push(s);
	vis[s] = true;
	
	
	ll ans = 0;
	while(!q.empty()) {
		int u = q.front();
		q.pop();
		for (int v : adj[u]) {
			if (!vis[v]) {
				q.push(v);
				vis[v] = true;
				st.push(make_pair(u, v));
			}
		}
	}
	while(!st.empty()) {
		auto[u, v] = st.top();
		st.pop();
		
		ans += dp[v];
		dp[u] += dp[v];
	}
	ans += dp[s];
	return ans;
}

inline void solve() {
	ll ans = oo;
	for (int i = 1; i <= n; ++i) ans = min(ans, bfs(i));
	cout << ans;
}


inline void input() {
    cin >> n;
    for (int u = 1; u <= n; ++u) {
    	int k; cin >> k;
    	for (int i = 1; i <= k; ++i) {
    		int v; cin >> v;
    		adj[v].pb(u);
    	}
    }
    return solve();
}
bool END;

int main() {
    if(fopen(task ".inp", "r")) {
        freopen(task ".inp", "r", stdin);
        freopen(task ".out", "w", stdout);
    }
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);

    input();
    
    
    cerr << endl << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << 's' << endl;
    cerr << "Memory: " << fabs ((&END - &START)) / 1048576.0 << "MB\n";
    return 0;
}

Compilation message (stderr)

bosses.cpp: In function 'int main()':
bosses.cpp:87:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   87 |         freopen(task ".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
bosses.cpp:88:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   88 |         freopen(task ".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...