Submission #91842

#TimeUsernameProblemLanguageResultExecution timeMemory
91842karmaBosses (BOI16_bosses)C++11
0 / 100
2 ms504 KiB
#include<bits/stdc++.h> #define For(i, a, b) for(int i = a, _b = b; i <= _b; ++i) #define Ford(i, a, b) for(int i = a, _b = b; i >= _b; --i) #define FileName "test" #define ll long long #define ld long double #define ull unsigned long #define Print(x) cerr << #x << "is " << x << '\n'; #define pb push_back #define X first #define Y second //#define Karma using namespace std; template<typename T> inline void Cin(T &x) { char c; T sign = 1; x = 0; for (c = getchar(); c < '0' || c > '9'; c = getchar()) if (c == '-') sign = -1; for (; c >= '0' && c <= '9'; c = getchar()) x = x * 10 + c - '0'; x *= sign; } template <typename T> inline void Out(T x) {if(x > 9) Out(x / 10); putchar(x % 10 + '0');} template <typename T> inline void Cout(T x, char c) {if(x < 0) putchar('-'); x = abs(x); Out(x); putchar(c);} template <typename T, typename... Args> inline void Cin(T& a, Args&... args) {Cin(a);Cin(args...);} template <typename T, typename... Args> inline void Cout(T a, char c, Args... args) {Cout(a, c);Cout(args...);} typedef pair<int, int> pii; typedef pair<ll, int> plli; const int N = 5e3 + 7; const ll oo = 1e18 + 7; int n, k, s, nVertex; bool vis[N]; vector<int> a[N]; ll res, salary[N], SumSalary[N]; void Enter() { Cin(n); For(i, 1, n) { Cin(k); For(j, 1, k) Cin(s), a[s].pb(i); } } void DFS(int u) { ll sum = 0; vis[u] = 1; --nVertex; for(int v: a[u]) { if(!vis[v]) { DFS(v); sum += salary[v]; } } salary[u] = sum + 1; } ll Build(int s) { fill_n(salary, n + 1, 0); fill_n(vis, n + 1, 0); ll res = 0; nVertex = n; DFS(s); For(i, 1, n) res += salary[i]; if(nVertex) return oo; return res; } void Solve() { res = oo; For(i, 1, n) res = min(res, Build(i)); cout << res; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifdef Karma freopen(FileName".inp", "r", stdin); freopen(FileName".out", "w", stdout); #endif // Karma Enter(); Solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...