# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
260819 | 2020-08-11T04:19:50 Z | arnold518 | Airline Route Map (JOI18_airline) | C++14 | 0 ms | 0 KB |
#include "Boblib.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; static const int MAXN = 1100; static int V, U, *C, *D; static vector<int> adj[MAXN+10]; static vector<int> radj[MAXN+10]; static int N, deg[MAXN+10], A[MAXN+10], B[MAXN+10]; static vector<pii> E; static bool vis[MAXN+10]; static const int POW[10] = {1, 3, 9, 27, 81, 243, 729}; void Bob(int _V, int _U, int _C[], int _D[]) { V=_V; U=_U; C=_C; D=_D; N=V-12; for(int i=0; i<U; i++) { int u=C[i], v=D[i]; adj[u].push_back(v); radj[v].push_back(u); deg[u]++; deg[v]++; } int P, Q, R; for(int i=0; i<V; i++) if(deg[i]==2) { P=i; break; } for(int i=0; i<V; i++) if(deg[i]==N+10) vis[i]=1; Q=adj[P].front(); R=radj[P].front(); assert(adj[P].size()==1); assert(radj[P].size()==1); vis[P]=1; vis[Q]=1; vis[R]=1; vector<int> VV; for(auto it : adj[Q]) { if(vis[it]) continue; VV.push_back(it); A[it]+=1; } for(auto it : radj[Q]) { if(vis[it]) continue; VV.push_back(it); A[it]+=2; } for(auto it : adj[R]) { if(vis[it]) continue; VV.push_back(it); A[it]+=3; } for(auto it : radj[R]) { if(vis[it]) continue; VV.push_back(it); A[it]+=6; } sort(VV.begin(), VV.end()); VV.erase(unique(VV.begin(), VV.end()), VV.end()); if(VV.size()!=7) while(1); for(auto it : VV) { vis[it]=1; B[A[it]-1]=it; } VV.clear(); for(int i=0; i<7; i++) { for(auto it : adj[B[i]]) { if(vis[it]) continue; VV.push_back(it); A[it]+=POW[i]; } for(auto it : radj[B[i]]) { if(vis[it]) continue; VV.push_back(it); A[it]+=POW[i]*2; } } sort(VV.begin(), VV.end()); VV.erase(unique(VV.begin(), VV.end()), VV.end()); if(VV.size()!=N) while(1); vector<int> VVV; for(auto it : VV) VVV.push_back(A[it]); sort(VVV.begin(), VVV.end()); //for(int i=0; i<VVV.size(); i++) if(VVV[i]!=i+1) while(1); for(auto now : VV) { for(auto nxt : adj[now]) { if(vis[nxt]) continue; E.push_back({A[now], A[nxt]}); } } InitMap(N, E.size()); for(auto it : E) MakeMap(it.first-1, it.second-1); }