Submission #1146237

#TimeUsernameProblemLanguageResultExecution timeMemory
1146237rado15Easter Eggs (info1cup17_eastereggs)C++20
Compilation error
0 ms0 KiB
#include <vector> #include <algorithm> using namespace std; // Function to find the centroid of a tree int findCentroid(int u, int parent, const vector<vector<int>>& adj, vector<int>& subtreeSize, int totalNodes) { subtreeSize[u] = 1; for (int v : adj[u]) { if (v != parent) { subtreeSize[u] += findCentroid(v, u, adj, subtreeSize, totalNodes); } } if (subtreeSize[u] * 2 >= totalNodes) { return u; } return -1; } // Function to perform the query int query(const vector<int>& islands); // Recursive function to find the Easter Egg int findEggHelper(int u, int parent, const vector<vector<int>>& adj, vector<int>& subtreeSize) { int totalNodes = subtreeSize[u]; int centroid = findCentroid(u, parent, adj, subtreeSize, totalNodes); // Prepare the query set vector<int> querySet; querySet.push_back(centroid); // Query the centroid if (query(querySet)) { return centroid; } // If not found, search in the subtrees for (int v : adj[centroid]) { if (v != parent && subtreeSize[v] * 2 > totalNodes) { return findEggHelper(v, centroid, adj, subtreeSize); } } return -1; // Should not reach here } // Main function to find the Easter Egg int findEgg(int N, vector<pair<int, int>> bridges) { // Build the adjacency list vector<vector<int>> adj(N + 1); for (auto& bridge : bridges) { adj[bridge.first].push_back(bridge.second); adj[bridge.second].push_back(bridge.first); } // Initialize subtree sizes vector<int> subtreeSize(N + 1, 0); // Start the search from the root (island 1) return findEggHelper(1, -1, adj, subtreeSize); }

Compilation message (stderr)

/usr/bin/ld: /tmp/cckOhiVD.o: in function `findEggHelper(int, int, std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > > const&, std::vector<int, std::allocator<int> >&)':
eastereggs.cpp:(.text+0x115): undefined reference to `query(std::vector<int, std::allocator<int> > const&)'
collect2: error: ld returned 1 exit status