Submission #1116808

#TimeUsernameProblemLanguageResultExecution timeMemory
1116808byebye75Mergers (JOI19_mergers)C++14
0 / 100
16 ms2896 KiB
#include <iostream> #include <vector> #include <unordered_set> #include <cstdint> using namespace std; // Custom hash function for pairs (if needed) struct pair_hash { size_t operator()(const pair<int, int>& p) const { // Combine the hashes of the two integers return hash<int>()(p.first) ^ (hash<int>()(p.second) << 1); } }; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int N, K; cin >> N >> K; vector<pair<int, int>> edges(N - 1); for (int i = 0; i < N - 1; ++i) { int Ai, Bi; cin >> Ai >> Bi; --Ai; // Convert to 0-based index --Bi; edges[i] = {Ai, Bi}; } vector<int> S(N); for (int i = 0; i < N; ++i) { cin >> S[i]; --S[i]; // Convert to 0-based index } unordered_set<int64_t> state_edges; for (const auto& edge : edges) { int u = edge.first; int v = edge.second; int su = S[u]; int sv = S[v]; if (su != sv) { int s = min(su, sv); int t = max(su, sv); int64_t key = (int64_t)s * 500000 + t; state_edges.insert(key); } } int E = state_edges.size(); // Number of edges in the state graph int N_states = K; // Number of nodes in the state graph int cycles_initial = E - N_states + 1; int answer = max(0, 1 - cycles_initial); cout << answer << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...