# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
124786 | 2019-07-04T01:59:38 Z | model_code | Political Development (BOI17_politicaldevelopment) | C++17 | 3000 ms | 5108 KB |
#include<iostream> #include<vector> #include<cstdio> #include<queue> #include<algorithm> #include<bitset> using namespace std; int n,k; vector<int> degree; vector<vector<int> > G; vector<bool> done; vector<int> current; vector<int> degOrdering; vector<int> degOrderingPos; //for debugging; vector<int> maxCliqueFound; void readInput() { scanf("%d%d", &n, &k); degree = vector<int> (n,0); for(int i = 0; i < n; ++i) { scanf("%d", &(degree[i])); G.push_back(vector<int> (degree[i], 0)); for(int j = 0; j < degree[i]; ++j) {scanf("%d", &(G[i][j]));} } done = vector<bool> (n, false); current = vector<int> (n, -1); } void makeDegeneracyOrdering() { queue<int> Q; vector<int> reducedDegree(degree); for(int i = 0; i < n; ++i) {if(reducedDegree[i] <= k) Q.push(i);} while(!Q.empty()) { int v = Q.front(); Q.pop(); degOrdering.push_back(v); for(int i = 0; i < G[v].size(); ++i) { int u = G[v][i]; reducedDegree[u]--; if(reducedDegree[u] == k) Q.push(u); }} degOrderingPos = vector<int> (n,0); for(int i = 0; i < n; ++i) {degOrderingPos[degOrdering[i]] = i;} } int maxCliqueSize(int pos) { // filter out active vertices vector<int> zactive(G[pos]); zactive.push_back(pos); vector<int> active; for(int i = 0; i < zactive.size(); ++i) {if(!done[zactive[i]]) active.push_back(zactive[i]);} int t = active.size(); // set current for(int i = 0; i < t; ++i) current[active[i]] = i; //cerr << "num active vertices " << t << endl; // make adjacency matrix as bitmask vector<int> adj(t, 0); for(int i = 0; i < t; ++i) { adj[i] |= 1 << i; int u = active[i]; for(int j = 0; j < G[u].size(); ++j) { int v = G[u][j]; adj[i] |= current[v] != -1 ? 1 << current[v] : 0; } } int ans = 0; int N = 1 << t; for(int s = 0; s < N; ++s) { // check if s is a clique: int isSet = s; for(int p = 0; p < t; ++p) {if(s & (1 << p)) isSet &= adj[p];} if(isSet != s) continue; int card = bitset<12>(s).count(); ans = max(ans, card); // keep largest clique for debugginf if(card > maxCliqueFound.size()) { maxCliqueFound.clear(); for(int i = 0; i < t; ++i) {if(s & (1 << i)) maxCliqueFound.push_back(active[i]);} } } // clear current for(int i = 0; i < t; ++i) current[active[i]] = -1; return ans; } // ensure that the max clique found is actually a clique. void assertClique() { for(int i = 0; i < maxCliqueFound.size(); ++i) { for(int j = 0; j < maxCliqueFound.size(); ++j) { if(i==j) continue; bool found = false; for(int p = 0; p < G[maxCliqueFound[j]].size(); ++p) { found |= G[maxCliqueFound[j]][p] == maxCliqueFound[i]; } if(!found) { cerr << "WTF" << endl; }}}} int main() { readInput(); makeDegeneracyOrdering(); int best = 0; for(int i = 0; i < n; ++i) { int v = degOrdering[i]; int c = maxCliqueSize(v); best = max(best, c); done[v] = true; } assertClique(); printf("%d\n", best); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 256 KB | Output is correct |
2 | Correct | 2 ms | 376 KB | Output is correct |
3 | Correct | 6 ms | 760 KB | Output is correct |
4 | Correct | 29 ms | 760 KB | Output is correct |
5 | Correct | 28 ms | 760 KB | Output is correct |
6 | Correct | 6 ms | 760 KB | Output is correct |
7 | Correct | 6 ms | 760 KB | Output is correct |
8 | Correct | 3 ms | 632 KB | Output is correct |
9 | Correct | 2 ms | 256 KB | Output is correct |
10 | Correct | 3 ms | 632 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 256 KB | Output is correct |
2 | Correct | 2 ms | 376 KB | Output is correct |
3 | Correct | 6 ms | 760 KB | Output is correct |
4 | Correct | 29 ms | 760 KB | Output is correct |
5 | Correct | 28 ms | 760 KB | Output is correct |
6 | Correct | 6 ms | 760 KB | Output is correct |
7 | Correct | 6 ms | 760 KB | Output is correct |
8 | Correct | 3 ms | 632 KB | Output is correct |
9 | Correct | 2 ms | 256 KB | Output is correct |
10 | Correct | 3 ms | 632 KB | Output is correct |
11 | Correct | 28 ms | 804 KB | Output is correct |
12 | Correct | 28 ms | 840 KB | Output is correct |
13 | Correct | 2 ms | 256 KB | Output is correct |
14 | Correct | 28 ms | 760 KB | Output is correct |
15 | Correct | 2 ms | 252 KB | Output is correct |
16 | Correct | 6 ms | 760 KB | Output is correct |
17 | Correct | 2 ms | 252 KB | Output is correct |
18 | Correct | 6 ms | 760 KB | Output is correct |
19 | Correct | 3 ms | 632 KB | Output is correct |
20 | Correct | 5 ms | 760 KB | Output is correct |
21 | Correct | 5 ms | 688 KB | Output is correct |
22 | Correct | 4 ms | 632 KB | Output is correct |
23 | Correct | 7 ms | 760 KB | Output is correct |
24 | Correct | 3 ms | 632 KB | Output is correct |
25 | Correct | 7 ms | 760 KB | Output is correct |
26 | Correct | 6 ms | 760 KB | Output is correct |
27 | Correct | 6 ms | 760 KB | Output is correct |
28 | Correct | 7 ms | 760 KB | Output is correct |
29 | Correct | 6 ms | 760 KB | Output is correct |
30 | Correct | 12 ms | 760 KB | Output is correct |
31 | Correct | 7 ms | 760 KB | Output is correct |
32 | Correct | 12 ms | 760 KB | Output is correct |
33 | Correct | 7 ms | 760 KB | Output is correct |
34 | Correct | 7 ms | 760 KB | Output is correct |
35 | Correct | 4 ms | 504 KB | Output is correct |
36 | Correct | 4 ms | 504 KB | Output is correct |
37 | Correct | 4 ms | 504 KB | Output is correct |
38 | Correct | 3 ms | 376 KB | Output is correct |
39 | Correct | 3 ms | 504 KB | Output is correct |
40 | Correct | 8 ms | 760 KB | Output is correct |
41 | Correct | 3 ms | 376 KB | Output is correct |
42 | Correct | 8 ms | 760 KB | Output is correct |
43 | Correct | 8 ms | 760 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 632 KB | Output is correct |
2 | Correct | 2 ms | 256 KB | Output is correct |
3 | Correct | 2 ms | 376 KB | Output is correct |
4 | Correct | 2 ms | 376 KB | Output is correct |
5 | Correct | 2 ms | 376 KB | Output is correct |
6 | Correct | 2 ms | 376 KB | Output is correct |
7 | Correct | 2 ms | 376 KB | Output is correct |
8 | Correct | 2 ms | 256 KB | Output is correct |
9 | Correct | 2 ms | 256 KB | Output is correct |
10 | Correct | 2 ms | 376 KB | Output is correct |
11 | Correct | 590 ms | 5036 KB | Output is correct |
12 | Correct | 2 ms | 256 KB | Output is correct |
13 | Correct | 598 ms | 5108 KB | Output is correct |
14 | Correct | 2 ms | 256 KB | Output is correct |
15 | Correct | 603 ms | 5068 KB | Output is correct |
16 | Correct | 590 ms | 5040 KB | Output is correct |
17 | Correct | 588 ms | 5036 KB | Output is correct |
18 | Correct | 587 ms | 5072 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 256 KB | Output is correct |
2 | Correct | 2 ms | 376 KB | Output is correct |
3 | Correct | 6 ms | 760 KB | Output is correct |
4 | Correct | 29 ms | 760 KB | Output is correct |
5 | Correct | 28 ms | 760 KB | Output is correct |
6 | Correct | 6 ms | 760 KB | Output is correct |
7 | Correct | 6 ms | 760 KB | Output is correct |
8 | Correct | 3 ms | 632 KB | Output is correct |
9 | Correct | 2 ms | 256 KB | Output is correct |
10 | Correct | 3 ms | 632 KB | Output is correct |
11 | Correct | 28 ms | 804 KB | Output is correct |
12 | Correct | 28 ms | 840 KB | Output is correct |
13 | Correct | 2 ms | 256 KB | Output is correct |
14 | Correct | 28 ms | 760 KB | Output is correct |
15 | Correct | 2 ms | 252 KB | Output is correct |
16 | Correct | 6 ms | 760 KB | Output is correct |
17 | Correct | 2 ms | 252 KB | Output is correct |
18 | Correct | 6 ms | 760 KB | Output is correct |
19 | Correct | 3 ms | 632 KB | Output is correct |
20 | Correct | 5 ms | 760 KB | Output is correct |
21 | Correct | 5 ms | 688 KB | Output is correct |
22 | Correct | 4 ms | 632 KB | Output is correct |
23 | Correct | 7 ms | 760 KB | Output is correct |
24 | Correct | 3 ms | 632 KB | Output is correct |
25 | Correct | 7 ms | 760 KB | Output is correct |
26 | Correct | 6 ms | 760 KB | Output is correct |
27 | Correct | 6 ms | 760 KB | Output is correct |
28 | Correct | 7 ms | 760 KB | Output is correct |
29 | Correct | 6 ms | 760 KB | Output is correct |
30 | Correct | 12 ms | 760 KB | Output is correct |
31 | Correct | 7 ms | 760 KB | Output is correct |
32 | Correct | 12 ms | 760 KB | Output is correct |
33 | Correct | 7 ms | 760 KB | Output is correct |
34 | Correct | 7 ms | 760 KB | Output is correct |
35 | Correct | 4 ms | 504 KB | Output is correct |
36 | Correct | 4 ms | 504 KB | Output is correct |
37 | Correct | 4 ms | 504 KB | Output is correct |
38 | Correct | 3 ms | 376 KB | Output is correct |
39 | Correct | 3 ms | 504 KB | Output is correct |
40 | Correct | 8 ms | 760 KB | Output is correct |
41 | Correct | 3 ms | 376 KB | Output is correct |
42 | Correct | 8 ms | 760 KB | Output is correct |
43 | Correct | 8 ms | 760 KB | Output is correct |
44 | Correct | 36 ms | 760 KB | Output is correct |
45 | Correct | 2 ms | 376 KB | Output is correct |
46 | Correct | 9 ms | 760 KB | Output is correct |
47 | Correct | 15 ms | 760 KB | Output is correct |
48 | Correct | 9 ms | 760 KB | Output is correct |
49 | Correct | 14 ms | 764 KB | Output is correct |
50 | Correct | 22 ms | 760 KB | Output is correct |
51 | Correct | 165 ms | 1032 KB | Output is correct |
52 | Correct | 28 ms | 760 KB | Output is correct |
53 | Correct | 471 ms | 1144 KB | Output is correct |
54 | Correct | 336 ms | 1016 KB | Output is correct |
55 | Correct | 6 ms | 760 KB | Output is correct |
56 | Correct | 28 ms | 840 KB | Output is correct |
57 | Correct | 3 ms | 632 KB | Output is correct |
58 | Correct | 470 ms | 1032 KB | Output is correct |
59 | Correct | 8 ms | 724 KB | Output is correct |
60 | Correct | 6 ms | 764 KB | Output is correct |
61 | Correct | 8 ms | 760 KB | Output is correct |
62 | Correct | 8 ms | 760 KB | Output is correct |
63 | Correct | 36 ms | 760 KB | Output is correct |
64 | Correct | 19 ms | 760 KB | Output is correct |
65 | Correct | 8 ms | 760 KB | Output is correct |
66 | Correct | 8 ms | 656 KB | Output is correct |
67 | Correct | 63 ms | 760 KB | Output is correct |
68 | Correct | 19 ms | 760 KB | Output is correct |
69 | Correct | 8 ms | 760 KB | Output is correct |
70 | Correct | 21 ms | 760 KB | Output is correct |
71 | Correct | 60 ms | 864 KB | Output is correct |
72 | Correct | 55 ms | 764 KB | Output is correct |
73 | Correct | 6 ms | 760 KB | Output is correct |
74 | Correct | 22 ms | 760 KB | Output is correct |
75 | Correct | 57 ms | 760 KB | Output is correct |
76 | Correct | 16 ms | 760 KB | Output is correct |
77 | Correct | 113 ms | 888 KB | Output is correct |
78 | Correct | 6 ms | 760 KB | Output is correct |
79 | Correct | 56 ms | 632 KB | Output is correct |
80 | Correct | 15 ms | 760 KB | Output is correct |
81 | Correct | 110 ms | 888 KB | Output is correct |
82 | Correct | 3 ms | 376 KB | Output is correct |
83 | Correct | 56 ms | 624 KB | Output is correct |
84 | Correct | 60 ms | 760 KB | Output is correct |
85 | Correct | 3 ms | 504 KB | Output is correct |
86 | Correct | 59 ms | 888 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 256 KB | Output is correct |
2 | Correct | 2 ms | 376 KB | Output is correct |
3 | Correct | 6 ms | 760 KB | Output is correct |
4 | Correct | 29 ms | 760 KB | Output is correct |
5 | Correct | 28 ms | 760 KB | Output is correct |
6 | Correct | 6 ms | 760 KB | Output is correct |
7 | Correct | 6 ms | 760 KB | Output is correct |
8 | Correct | 3 ms | 632 KB | Output is correct |
9 | Correct | 2 ms | 256 KB | Output is correct |
10 | Correct | 3 ms | 632 KB | Output is correct |
11 | Correct | 28 ms | 804 KB | Output is correct |
12 | Correct | 28 ms | 840 KB | Output is correct |
13 | Correct | 2 ms | 256 KB | Output is correct |
14 | Correct | 28 ms | 760 KB | Output is correct |
15 | Correct | 2 ms | 252 KB | Output is correct |
16 | Correct | 6 ms | 760 KB | Output is correct |
17 | Correct | 2 ms | 252 KB | Output is correct |
18 | Correct | 6 ms | 760 KB | Output is correct |
19 | Correct | 3 ms | 632 KB | Output is correct |
20 | Correct | 5 ms | 760 KB | Output is correct |
21 | Correct | 5 ms | 688 KB | Output is correct |
22 | Correct | 4 ms | 632 KB | Output is correct |
23 | Correct | 7 ms | 760 KB | Output is correct |
24 | Correct | 3 ms | 632 KB | Output is correct |
25 | Correct | 7 ms | 760 KB | Output is correct |
26 | Correct | 6 ms | 760 KB | Output is correct |
27 | Correct | 6 ms | 760 KB | Output is correct |
28 | Correct | 7 ms | 760 KB | Output is correct |
29 | Correct | 6 ms | 760 KB | Output is correct |
30 | Correct | 12 ms | 760 KB | Output is correct |
31 | Correct | 7 ms | 760 KB | Output is correct |
32 | Correct | 12 ms | 760 KB | Output is correct |
33 | Correct | 7 ms | 760 KB | Output is correct |
34 | Correct | 7 ms | 760 KB | Output is correct |
35 | Correct | 4 ms | 504 KB | Output is correct |
36 | Correct | 4 ms | 504 KB | Output is correct |
37 | Correct | 4 ms | 504 KB | Output is correct |
38 | Correct | 3 ms | 376 KB | Output is correct |
39 | Correct | 3 ms | 504 KB | Output is correct |
40 | Correct | 8 ms | 760 KB | Output is correct |
41 | Correct | 3 ms | 376 KB | Output is correct |
42 | Correct | 8 ms | 760 KB | Output is correct |
43 | Correct | 8 ms | 760 KB | Output is correct |
44 | Correct | 2 ms | 376 KB | Output is correct |
45 | Correct | 99 ms | 4524 KB | Output is correct |
46 | Correct | 841 ms | 4460 KB | Output is correct |
47 | Correct | 101 ms | 4524 KB | Output is correct |
48 | Correct | 101 ms | 4528 KB | Output is correct |
49 | Execution timed out | 3009 ms | 4688 KB | Time limit exceeded |
50 | Halted | 0 ms | 0 KB | - |