# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
35557 |
2017-11-24T16:44:08 Z |
szawinis |
Conspiracy (POI11_kon) |
C++14 |
|
2519 ms |
5284 KB |
#include <bits/stdc++.h>
using namespace std;
const int N = 5e3+1;
int n, dsu[N];
bitset<N> g[N], valid;
int root(int v) { return (dsu[v] < 0 ? v : dsu[v] = root(dsu[v])); }
void merge(int u, int v) {
if((u = root(u)) == (v = root(v))) return;
dsu[u] += dsu[v];
dsu[v] = u;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n;
fill(dsu, dsu+n, -1);
vector<int> deg(n+1), ord(n+1);
deg[n] = -1;
for(int i = 0; i < n; i++) {
cin >> deg[i];
for(int j = 0, v; j < deg[i]; j++) {
cin >> v; --v;
g[i].set(v);
}
}
iota(ord.begin(), ord.end(), 0);
sort(ord.begin(), ord.end(), [&] (int i, int j) { return deg[i] > deg[j]; });
valid[n] = true;
for(int i = n-1; i >= 0; i--) {
for(int j = i+1; j < n; j++) if(g[ord[i]][ord[j]]) merge(ord[i], ord[j]);
valid[ord[i]] = dsu[root(ord[i])] == -1;
}
int lim = -1;
bool run = true;
bitset<N> fin;
for(int i = 0; i < n; i++) {
for(int j = 0; j < i; j++) run &= g[ord[i]][ord[j]] || dsu[root(ord[i])] == -1 || dsu[root(ord[j])] == -1;
if(!run) break;
if(i == n-1 || (valid[ord[i+1]] && deg[ord[i+1]] != deg[ord[i]])) {
lim = i;
for(int k = 0; k <= i; k++) fin.set(ord[k]);
break;
}
}
if(lim == -1) cout << 0, exit(0);
int ans = lim < n-1;
for(int i = 0; i <= lim; i++) ans += (g[ord[i]] | fin) == fin;
if(lim < n-2) for(int i = lim+1; i < n; i++) ans += g[ord[i]] == fin;
cout << ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
5284 KB |
Output is correct |
2 |
Correct |
0 ms |
5284 KB |
Output is correct |
3 |
Correct |
0 ms |
5284 KB |
Output is correct |
4 |
Correct |
0 ms |
5284 KB |
Output is correct |
5 |
Correct |
0 ms |
5284 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
5284 KB |
Output is correct |
2 |
Correct |
0 ms |
5284 KB |
Output is correct |
3 |
Correct |
0 ms |
5284 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
5284 KB |
Output is correct |
2 |
Correct |
0 ms |
5284 KB |
Output is correct |
3 |
Correct |
0 ms |
5284 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
5284 KB |
Output is correct |
2 |
Correct |
3 ms |
5284 KB |
Output is correct |
3 |
Correct |
0 ms |
5284 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
5284 KB |
Output is correct |
2 |
Correct |
3 ms |
5284 KB |
Output is correct |
3 |
Correct |
0 ms |
5284 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
5284 KB |
Output is correct |
2 |
Correct |
69 ms |
5284 KB |
Output is correct |
3 |
Correct |
313 ms |
5284 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
5284 KB |
Output is correct |
2 |
Correct |
76 ms |
5284 KB |
Output is correct |
3 |
Correct |
373 ms |
5284 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
73 ms |
5284 KB |
Output is correct |
2 |
Correct |
203 ms |
5284 KB |
Output is correct |
3 |
Correct |
716 ms |
5284 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
126 ms |
5284 KB |
Output is correct |
2 |
Correct |
469 ms |
5284 KB |
Output is correct |
3 |
Correct |
1563 ms |
5284 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1116 ms |
5284 KB |
Output is correct |
2 |
Correct |
659 ms |
5284 KB |
Output is correct |
3 |
Correct |
2226 ms |
5284 KB |
Output is correct |
4 |
Correct |
2519 ms |
5284 KB |
Output is correct |
5 |
Correct |
63 ms |
5284 KB |
Output is correct |