Submission #1116810

#TimeUsernameProblemLanguageResultExecution timeMemory
1116810byebye75Mergers (JOI19_mergers)C++14
0 / 100
20 ms2652 KiB
#include <iostream> #include <vector> #include <algorithm> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int N, K; cin >> N >> K; vector<pair<int, int>> state_edges; vector<int> A(N - 1), B(N - 1); for (int i = 0; i < N - 1; ++i) { cin >> A[i] >> B[i]; --A[i]; // Convert to 0-based index --B[i]; } vector<int> S(N); for (int i = 0; i < N; ++i) { cin >> S[i]; --S[i]; // Convert to 0-based index } // Collect edges between different states for (int i = 0; i < N - 1; ++i) { int u = A[i]; int v = B[i]; int su = S[u]; int sv = S[v]; if (su != sv) { int s = min(su, sv); int t = max(su, sv); state_edges.emplace_back(s, t); } } // Sort and remove duplicates sort(state_edges.begin(), state_edges.end()); state_edges.erase(unique(state_edges.begin(), state_edges.end()), state_edges.end()); 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...