# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
420433 | 2021-06-08T11:12:03 Z | kostia244 | Airline Route Map (JOI18_airline) | C++17 | 0 ms | 0 KB |
#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); 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++; sun = g[sun][0]; for(auto i : g[sun]) if(g[i].size()>1)real[i] = 0; int start = -1, prev = -1; for(int i = 0; i < V; i++) if(!real[i]) { int popcnt = -1; for(int j : g[i]) if(real[j] && j != sun) { //cout << i << " to " << j<< endl; if(popcnt == -1) popcnt = j; if(popcnt != j) popcnt = -2; } if(popcnt >= 0) { //cout << "uwu " << i << " " << popcnt << endl; start = popcnt; break; } } //cout << start << "hm\n" << endl; vector<int> bits {start}; while(bits.size() < 10) { for(auto i : g[start]) if(real[i] && i != prev) { prev = start; start = i; break; } bits.push_back(start); } 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]]); } }