Submission #1306262

#TimeUsernameProblemLanguageResultExecution timeMemory
1306262thecrazycandyPolitical Development (BOI17_politicaldevelopment)C++20
16 / 100
3096 ms241224 KiB
#include <bits/stdc++.h> //#pragma GCC optimize("Ofast") //#pragma GCC target("avx,avx2,fma") using namespace std; #define ll long long #define sped_up ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define rall(v) (v).rbegin(), (v).rend() #define all(v) (v).begin(), (v).end() #define pb push_back #define S second #define F first const ll INF = (ll)1e9 + 1, INFL = (ll)1e18 + 1; const ll mod = (ll)1e9 + 7, MAXN = (ll)5e3 + 1; vector <ll> g[MAXN]; bool c[MAXN][MAXN]; ll used[MAXN]; ll col = 0; void dfs (ll v) { bool ok = 0; used[v] = 1; for (int i = 1; i <= col; i++) ok |= c[i][v]; if (!ok) col++; for (int i = 1; i <= col; i++) { if (c[i][v]) for (auto j : g[v]) c[i][j] = 0; } for (auto i : g[v]) if (used[i] == 0) dfs(i); for (int i = 1; i <= col; i++) { if (c[i][v]) for (auto j : g[v]) c[i][j] = 0; } } int main() { sped_up; ll n, k; cin >> n >> k; ll ans = 0; for (int i = 1; i <= n; i++) { ll a; cin >> a; while (a--) { ll b; cin >> b; c[i][b + 1] = 1; } } for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { if (i != j && !c[i][j]) g[i].pb(j); c[i][j] = 1; } } for (int i = 1; i <= n; i++) { ll mx = 0; if (used[i] == 0) { dfs(i); for (int j = 1; j <= col; j++) { ll cnt = 0; for (int l = 1; l <= n; l++) { if (used[l] == 1) cnt += c[j][l]; c[j][l] = 1; } mx = max(mx, cnt); } for (int j = 1; j <= n; j++) if (used[j] == 1) used[j] = 2; ans += mx; col = 0; } } cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...