Submission #39837

#TimeUsernameProblemLanguageResultExecution timeMemory
39837MladenPBosses (BOI16_bosses)C++14
0 / 100
0 ms2052 KiB
#include<bits/stdc++.h> #define STIZE(x) fprintf(stderr, "STIZE%d\n", x); #define PRINT(x) fprintf(stderr, "%s = %d\n", #x, x); #define NL(x) printf("%c", " \n"[(x)]); #define lld long long #define pii pair<int,int> #define pb push_back #define fi first #define se second #define endl '\n' #define mid (l+r)/2 #define all(a) begin(a),end(a) #define sz(a) int((a).size()) #define LINF 1000000000000000000LL #define INF 1000000000 #define EPS 1e-9 using namespace std; #define MAXN 1010 vector<int> adj[MAXN]; lld dist[MAXN], n; bool pos[MAXN]; queue<pii> q; lld BFS(int st) { for(int i = 1; i <= n; i++) pos[i] = 0; q.push({st, 1}); while(!q.empty()) { pii v = q.front(); q.pop(); lld node = v.fi, weight = v.se; dist[node] = weight; pos[node] = 1; for(auto x : adj[node]) { if(!pos[x]) { q.push({x, weight+1}); } } } lld rez = 0; for(int i = 1; i <= n; i++) { if(!pos[i]) return LINF; rez += dist[i]; } return rez; } int main() { //ios::sync_with_stdio(false);cin.tie(0); cin >> n; for(int i = 1; i <= n; i++) { int k; cin >> k; for(int j = 1; j <= k; j++) { int x; cin >> x; adj[x].pb(i); } } lld rez = LINF; for(int i = 1; i <= n; i++) { int cur = BFS(i); if(cur < rez) { rez = cur; } } cout << rez; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...