# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
732085 | sentheta | Airline Route Map (JOI18_airline) | C++17 | 0 ms | 0 KiB |
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 <cstdio>
// author : sentheta aka vanwij
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cassert>
#include<random>
#include<chrono>
#include<cmath>
#include<string>
#include<vector>
#include<bitset>
#include<queue>
#include<stack>
#include<map>
#include<set>
using namespace std;
#define Int long long
#define V vector
#define pii pair<int,int>
#define ff first
#define ss second
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
#define pow2(x) (1LL<<(x))
#define msb(x) (63-__builtin_clzll(x))
#define bitcnt(x) (__builtin_popcountll(x))
#define nl '\n'
#define _ << ' ' <<
#define all(x) (x).begin(), (x).end()
#define rep(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define dbg(x) if(1) cout << "?" << #x << " : " << (x) << endl << flush;
set<pii> AliceAns;
void AliceMake(int u,int v){
AliceAns.insert({u,v});
}
void AliceFinish(int n){
InitG(1+n+10+1, (int)AliceAns.size());
int i = 0;
for(auto[u,v] : AliceAns){
MakeG(i++, u,v);
}
}
void Alice(int n,int m,int u[],int v[]){
int k = 10;
rep(i,0,m){
u[i]++; v[i]++;
AliceMake(u[i],v[i]);
}
int a = 0;
// connect 2^i to a and nodes with ith-bit ON
rep(i,0,k){
int vtx = n+1+i;
AliceMake(a,vtx);
for(int j=1; j<=n; j++) if(j&1<<i){
AliceMake(vtx, j);
}
}
// connect b to all except a and 2^0
int b = n+11;
for(int i=0; i<=n+10; i++) if(i!=n+1){
AliceMake(b, i);
}
AliceFinish(n);
return; InitG(3,2); MakeG(1,2); MakeG(1,3);
}
#include "Boblib.h"
#include <cstdio>
// author : sentheta aka vanwij
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cassert>
#include<random>
#include<chrono>
#include<cmath>
#include<string>
#include<vector>
#include<bitset>
#include<queue>
#include<stack>
#include<map>
#include<set>
using namespace std;
#define Int long long
#define V vector
#define pii pair<int,int>
#define ff first
#define ss second
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
#define pow2(x) (1LL<<(x))
#define msb(x) (63-__builtin_clzll(x))
#define bitcnt(x) (__builtin_popcountll(x))
#define nl '\n'
#define _ << ' ' <<
#define all(x) (x).begin(), (x).end()
#define rep(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define dbg(x) if(1) cout << "?" << #x << " : " << (x) << endl << flush;
set<pii> BobAns;
void BobMake(int u,int v){
BobAns.insert({u,v});
}
void BobFinish(int n){
InitMap(n, (int)BobAns.size());
for(auto[u,v] : BobAns){
MakeMap(u-1, v-1);
}
}
const int N = 1069;
V<int> adj[N];
bool g[N][N];
int two[10];
int ori[N];
void Bob(int ntot,int m,int u[],int v[]){
int k = 10, n = ntot-12;
rep(i,0,N){
adj[i].clear();
rep(j,0,N) g[i][j] = 0;
}
rep(i,0,m){
adj[u[i]].push_back[v[i]];
adj[v[i]].push_back[u[i]];
g[u[i]][v[i]] = g[v[i]][u[i]] = 1;
}
// find node with degree ntot-3
int b = 0;
while(adj[b].size()!=ntot-3) b++;
// find two nodes disconnected from b
V<int> a0;
rep(i,0,ntot) if(i!=b && !g[i][b]){
a0.push_back(i);
}
// determine a and 2^0
int a=a0[0], two0=a0[1];
bool ok = adj[a].size()==k;
if(ok){
V<int>&vec = adj[a];
sort(all(vec));
// find permutation such that it makes a line
bool foundPerm = 0;
do{
bool isLine = 1;
rep(i,1,vec.size()){
isLine &= g[vec[i-1]][vec[i]];
}
if(isLine){
foundPerm = 1;
break;
}
}while(next_permutation(all(vec)));
ok &= foundPerm;
}
if(!ok) swap(a, two0);
rep(i,0,k){
two[i] = adj[a][i];
}
// recover nodes
rep(i,0,ntot){
// check importance
bool flag = i==a || i==b;
rep(j,0,k) flag |= i==two[j];
if(flag) continue;
ori[i] = 0;
rep(j,0,k) if(g[i][two[j]]){
ori[i] ^= 1<<j;
}
}
// recover edges
rep(i,0,m){
// check importance
bool flag = 0;
flag = u[i]==a || u[i]==b;
rep(j,0,k) flag |= u[i]==two[j];
flag = v[i]==a || v[i]==b;
rep(j,0,k) flag |= v[i]==two[j];
if(flag) continue;
BobMake(ori[u[i]],ori[v[i]]);
}
BobFinish(n);
return; InitMap(3,2); MakeMap(1,2); MakeMap(1,3);
}