Submission #952226

#TimeUsernameProblemLanguageResultExecution timeMemory
952226stefanneaguPolitical Development (BOI17_politicaldevelopment)C++17
39 / 100
3069 ms57064 KiB
#include <bits/stdc++.h> using namespace std; int main() { int n, useless; cin >> n >> useless; vector<vector<int>> adj(n + 1); set<pair<int, int>> pr; vector<pair<int, int>> vp; for(int i = 1; i <= n; i++) { int x; cin >> x; vp.push_back({x, i}); while(x--) { int a; cin >> a; a++; adj[i].push_back(a); pr.insert({min(a, i), max(a, i)}); } } sort(vp.begin(), vp.end()); vector<vector<vector<int>>> v(n + 1); for(int i = 1; i <= n; i++) { v[i].push_back({i}); } int ans = 0; while(true) { vector<vector<vector<int>>> curr(n + 1); ans++; bool ok = 0; for(int ii = 1; ii <= n; ii++) { int i = vp[ii - 1].second; // cout << "la " << i << "\n"; for(auto it : adj[i]) { // cout << "vecin " << it << ':'; vector<int> cp; bool used = 0; for(auto s : v[it]) { bool nf = 0; for(auto j : s) { if(pr.find({min(i, j), max(i, j)}) == pr.end()) { nf = 1; break; } } if(!nf) { // cout << " merge, face: "; cp = s; used = 1; ok = 1; break; } } if(used) { cp.push_back(i); curr[i].push_back(cp); } } } if(!ok) { break; } swap(v, curr); // o(1) plsplspls } cout << ans; return 0; }
#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...