This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "Alicelib.h"
#include<bits/stdc++.h>
using namespace std;
void Alice(int n, int m, int A[], int B[] ){
if(n < 3 || m == 0) {
InitG(n, m);
for(int i = 0; i < m; i++)
MakeG(i, A[i], B[i]);
return;
}
vector<int> label(3024);
for(int z = 0, i = 0; i < 1000; i++) {
while(z > 1 && !(z&(z-1))) z++;
label[i] = z ? z : 1023;
z++;
if(i < 5) {
//cout << i << " = " << label[i] << endl;
}
}
vector<array<int, 2>> edges;
vector<int> baka(n);
for(int i = 0; i < m; i++) {
baka[A[i]]++;
baka[B[i]]++;
}
for(int i = 0; i < m; i++) edges.push_back({A[i], B[i]});
for(int i = 0; i < n; i++) if(baka[i]) edges.push_back({n, i});
for(int i = 0; i < n; i++) if(!baka[i]) {
edges.push_back({i, n+2});
edges.push_back({i, n+3});
edges.push_back({i, n+4});
edges.push_back({i, n+11});
}
edges.push_back({n+1, n});
for(int bit = 0; bit < 10; bit++) {
if(bit)
edges.push_back({n+1+bit, n+2+bit});
for(int i = 0; i < n; i++) if(baka[i] && (label[i]>>bit)&1) {
edges.push_back({n+2+bit, i});
}
}
//for(auto [u, v] : edges) cout << u << " " << v << endl;
InitG(n+12, edges.size());
for(int i = 0; i < edges.size(); i++)
MakeG(i, edges[i][0], edges[i][1]);
}
#include "Boblib.h"
#include<bits/stdc++.h>
using namespace std;
void Bob( int V, int U, int C[], int D[] ){
if(V < 3 || U == 0) {
InitMap(V, U);
for(int i = 0; i < U; i++)
MakeMap(C[i], D[i]);
return;
}
vector<int> label(3024);
for(int z = 0, i = 0; i < 1000; i++) {
while(z > 1 && !(z&(z-1))) z++;
label[z ? z : 1023] = i;
z++;
}
vector<vector<int>> g(V);
vector<int> real(V, -1), crap(V, 0);
for(int i = 0; i < U; i++) {
g[C[i]].push_back(D[i]);
g[D[i]].push_back(C[i]);
}
int sun = 0;
while(g[sun].size()!=1) sun++;
int psun = sun;
sun = g[sun][0];
for(auto i : g[sun]) if(g[i].size()>1)real[i] = 0;
int start = -1, prev = -1;
int isol = (V-12) - (g[sun].size()-1);
if(isol == 0) {
for(int i = 0; i < V; i++) if(!real[i]) {
int popcnt = -1;
for(int j : g[i]) if(real[j] && j != sun) {
if(popcnt == -1) popcnt = j;
if(popcnt != j) popcnt = -2;
}
if(popcnt >= 0) {
start = popcnt;
break;
}
}
} else {
vector<int> fdeg(V);
for(int i = 0; i < V; i++) if(real[i]) {
for(int j : g[i]) fdeg[j]++;
}
for(int i = 0; i < V; i++) if(real[i] && i != sun && i != psun) {
int has2 = 0, has4 = 0;
for(int j : g[i]) if(real[j]) {
has2 |= fdeg[j] == 2;
has4 |= fdeg[j] == 4;
}
//cout << i << " " << has2 << " " << has4 << " " << g[i].size() << endl;
if(has2 && has4 && fdeg[i] == 1+isol) {
start = i;
for(auto j : g[i]) if(real[j] && fdeg[j] == 4)
crap[j] = 1;
break;
}
}
}
//cout << start << "hm\n" << endl;
vector<int> bits {start};
while(bits.size() < 10) {
for(auto i : g[start]) if(real[i] && i != prev && !crap[i]) {
prev = start;
start = i;
break;
}
bits.push_back(start);
}
if(isol) reverse(bits.begin(), bits.end());
for(int i = 0; i < 10; i++) {
for(int j : g[bits[i]]) if(real[j] != -1)
real[j] += 1<<i;
}
//for(auto i : real) cout << i << " "; cout << endl;
for(int &i : real) if(i != -1) i = label[i];
//for(auto i : real) cout << i << " "; cout << endl;
int ed = 0;
for(int i = 0; i < U; i++)
ed += real[C[i]] >= 0 && real[D[i]] >= 0;
InitMap(V-12, ed );
for(int i = 0; i < U; i++) {
if(real[C[i]] >= 0 && real[D[i]] >= 0)
MakeMap(real[C[i]], real[D[i]]);
}
}
Compilation message (stderr)
Alice.cpp: In function 'void Alice(int, int, int*, int*)':
Alice.cpp:47:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
47 | for(int i = 0; i < edges.size(); i++)
| ~~^~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |