# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
35547 |
2017-11-24T13:42:48 Z |
szawinis |
Conspiracy (POI11_kon) |
C++14 |
|
2583 ms |
5280 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);
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;
// cout << deg[ord[i]] << ' ' << ord[i] << ' ' << valid[ord[i]] << endl;
}
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]];
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 = 1;
for(int i = 0; i <= lim; i++) ans += (g[ord[i]] | fin) == fin;//, cout << (g[ord[i]] | fin).to_string() << endl;
cout << ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
5280 KB |
Output is correct |
2 |
Correct |
0 ms |
5280 KB |
Output is correct |
3 |
Incorrect |
0 ms |
5280 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
5280 KB |
Output is correct |
2 |
Correct |
0 ms |
5280 KB |
Output is correct |
3 |
Correct |
0 ms |
5280 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
5280 KB |
Output is correct |
2 |
Correct |
0 ms |
5280 KB |
Output is correct |
3 |
Correct |
0 ms |
5280 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
5280 KB |
Output is correct |
2 |
Correct |
3 ms |
5280 KB |
Output is correct |
3 |
Correct |
0 ms |
5280 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
5280 KB |
Output is correct |
2 |
Correct |
3 ms |
5280 KB |
Output is correct |
3 |
Correct |
0 ms |
5280 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
5280 KB |
Output is correct |
2 |
Correct |
59 ms |
5280 KB |
Output is correct |
3 |
Correct |
276 ms |
5280 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
5280 KB |
Output is correct |
2 |
Correct |
89 ms |
5280 KB |
Output is correct |
3 |
Correct |
466 ms |
5280 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
73 ms |
5280 KB |
Output is correct |
2 |
Correct |
203 ms |
5280 KB |
Output is correct |
3 |
Correct |
683 ms |
5280 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
136 ms |
5280 KB |
Output is correct |
2 |
Correct |
469 ms |
5280 KB |
Output is correct |
3 |
Correct |
1509 ms |
5280 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1076 ms |
5280 KB |
Output is correct |
2 |
Correct |
676 ms |
5280 KB |
Output is correct |
3 |
Correct |
2336 ms |
5280 KB |
Output is correct |
4 |
Incorrect |
2583 ms |
5280 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |