Submission #1103716

#TimeUsernameProblemLanguageResultExecution timeMemory
1103716ortsacPolitical Development (BOI17_politicaldevelopment)C++17
77 / 100
3070 ms5448 KiB
#pragma GCC optimize ("O3") #include <bits/stdc++.h> using namespace std; #define all(x) x.begin(), x.end() const int MAXN = 5e4 + 10; int n, k; vector<int> adj[MAXN]; void merge(vector<int>& v1, vector<int>& v2, vector<int>& res) { int n = v1.size(), m = v2.size(); int p1 = 0, p2 = 0; while ((p1 < n) && (p2 < m)) { if (v1[p1] == v2[p2]) { res.push_back(v1[p1]); p1++; p2++; continue; } if (v1[p1] > v2[p2]) p1++; else p2++; } } int best(vector<int> pos) { int mx = 0; while (!pos.empty()) { auto u = pos.back(); pos.pop_back(); vector<int> nxt; merge(pos, adj[u], nxt); mx = max(mx, 1 + best(nxt)); } return mx; } int32_t main() { cin >> n >> k; for (int i = 0; i < n; i++) { int x; cin >> x; while (x--) { int v; cin >> v; adj[i].push_back(v); } sort(adj[i].begin(), adj[i].end(), greater<int>()); } int ans = 0; for (int i = 0; i < n; i++) { ans = max(ans, best(adj[i]) + 1); if (ans == k) break; } cout << ans << "\n"; }
#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...