Submission #891407

#TimeUsernameProblemLanguageResultExecution timeMemory
891407boris_mihovAirline Route Map (JOI18_airline)C++17
91 / 100
399 ms45796 KiB
#include "Alicelib.h" #include <iostream> #include <numeric> #include <cassert> #include <vector> typedef long long llong; const int MAXN = 2000 + 10; const int INF = 1e9; std::vector <std::pair <int,int>> newG; void Alice (int N, int M, int A[], int B[] ) { for (int i = 0 ; i < M ; ++i) { newG.push_back({A[i], B[i]}); } if (N <= 2) { InitG(N, newG.size()); for (int i = 0 ; i < newG.size() ; ++i) { MakeG(i, newG[i].first, newG[i].second); } return; } int log = 10; for (int i = 0 ; i < N ; ++i) { for (int bit = 0 ; bit < log ; ++bit) { if ((i + 1) & (1 << bit)) { newG.push_back({i, N + bit}); } } } for (int bit = 0 ; bit < log ; ++bit) { newG.push_back({N + log, N + bit}); } for (int bit = 0 ; bit + 1 < log ; ++bit) { newG.push_back({N + bit, N + bit + 1}); } if (N >= 512) { newG.push_back({N + log + 1, N + log - 1}); newG.push_back({N + log + 1, N + log}); for (int i = 0 ; i < N + log ; ++i) { newG.push_back({N + log + 2, i}); } newG.push_back({N + log + 2, N + log + 1}); InitG(N + log + 3, newG.size()); for (int i = 0 ; i < newG.size() ; ++i) { MakeG(i, newG[i].first, newG[i].second); } } else { for (int i = 0 ; i < N + log ; ++i) { newG.push_back({N + log + 1, i}); } InitG(N + log + 2, newG.size()); for (int i = 0 ; i < newG.size() ; ++i) { MakeG(i, newG[i].first, newG[i].second); } } return; }
#include "Boblib.h" #include <algorithm> #include <iostream> #include <numeric> #include <cassert> #include <cstring> #include <vector> typedef long long llong; const int MAXN = 2013 + 10; const int INF = 1e9; int number[MAXN]; bool inReal[MAXN]; bool connected[MAXN][MAXN]; std::vector <std::pair <int,int>> edges; std::vector <int> g[MAXN]; std::vector <int> logs; int realLog[MAXN]; bool isLog[MAXN]; int deg[MAXN]; void dfs(int node, int par) { logs.push_back(node); for (const int &u : g[node]) { if (u == par) { continue; } if (isLog[u]) { dfs(u, node); } } } void Bob( int V, int U, int C[], int D[] ) { // std::cout << "call: " << V << ' ' << U << '\n'; if (V <= 2) { if (U == 0) { InitMap(V, 0); } else { InitMap(V, 1); MakeMap(0, 1); } return; } memset(connected, 0, sizeof(connected)); for (int i = 0 ; i < U ; ++i) { // if (C[i] == 0 || D[i] == 0) std::cout << "edge: " << C[i] << ' ' << D[i] << '\n'; assert(C[i] < MAXN); assert(D[i] < MAXN); g[C[i]].push_back(D[i]); g[D[i]].push_back(C[i]); deg[C[i]]++; deg[D[i]]++; connected[C[i]][D[i]] = true; connected[D[i]][C[i]] = true; } for (int i = 0 ; i < V ; ++i) { inReal[i] = true; } int log = 10; int n = V - log - 3 + (V < 525); int root = -1; for (int i = 0 ; i < V ; ++i) { if (deg[i] == V - 2) { root = i; } } assert(root != -1); int source = -1; int pointing = -1; for (int i = 0 ; i < V ; ++i) { // if (!connected[root][i]) std::cout << "size: " << i << ' ' << root << ' ' << deg[i] << ' ' << connected[i][root] << '\n'; if (i != root && !connected[i][root] && deg[i] == log + 1 - (n < 512)) { while (source != -1); source = i; } } assert(source != -1); for (const int &u : g[source]) { // std::cout << "neighboor: " << u << ' ' << deg[u] << '\n'; if (deg[u] == 3) { pointing = u; } else { isLog[u] = true; } } // std::cout << "poiting is: " << pointing << ' ' << source << '\n' << std::flush; assert(pointing != -1); if (isLog[g[pointing][0]]) dfs(g[pointing][0], -1); else if (isLog[g[pointing][1]]) dfs(g[pointing][1], -1); else dfs(g[pointing][2], -1); // std::cout << "logs are: " << log << ' ' << logs.size() << "\n"; std::reverse(logs.begin(), logs.end()); if (logs.size() < log) logs.push_back(pointing); for (int i = 0 ; i < log ; ++i) { // std::cout << logs[i] << ' '; inReal[logs[i]] = false; realLog[logs[i]] = i; } // std::cout << '\n'; assert(logs.size() == log); inReal[root] = false; inReal[source] = false; inReal[pointing] = false; for (int i = 0 ; i < V ; ++i) { if (!inReal[i]) { continue; } for (int j = 0 ; j < log ; ++j) { if (connected[i][logs[j]]) { // if (i == 0) std::cout << "connected: " << i << ' ' << logs[j] << ' ' << connected[i][logs[j]] << '\n'; number[i] |= (1 << j); } } // if (number[i] == 0) std::cout << "interesting: " << number[i] << ' ' << i << '\n'; assert(number[i] > 0); number[i]--; } for (int i = 0 ; i < V ; ++i) { for (int j = i + 1 ; j < V ; ++j) { if (!inReal[i] || !inReal[j] || !connected[i][j]) { continue; } edges.push_back({number[i], number[j]}); } } InitMap(n, edges.size()); for (int i = 0 ; i < edges.size() ; ++i) { MakeMap(edges[i].first, edges[i].second); } return; }

Compilation message (stderr)

Alice.cpp: In function 'void Alice(int, int, int*, int*)':
Alice.cpp:23:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |         for (int i = 0 ; i < newG.size() ; ++i)
      |                          ~~^~~~~~~~~~~~~
Alice.cpp:65:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   65 |         for (int i = 0 ; i < newG.size() ; ++i)
      |                          ~~^~~~~~~~~~~~~
Alice.cpp:77:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   77 |         for (int i = 0 ; i < newG.size() ; ++i)
      |                          ~~^~~~~~~~~~~~~

Bob.cpp: In function 'void Bob(int, int, int*, int*)':
Bob.cpp:122:21: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  122 |     if (logs.size() < log) logs.push_back(pointing);
      |         ~~~~~~~~~~~~^~~~~
In file included from /usr/include/c++/10/cassert:44,
                 from Bob.cpp:5:
Bob.cpp:131:24: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  131 |     assert(logs.size() == log);
      |            ~~~~~~~~~~~~^~~~~~
Bob.cpp:172:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  172 |     for (int i = 0 ; i < edges.size() ; ++i)
      |                      ~~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...