Submission #1046953

#TimeUTC-0UsernameProblemLanguageResultExecution timeMemory
10469532024-08-07 06:50:05isaachewMergers (JOI19_mergers)C++17
100 / 100
501 ms136360 KiB
#include <bits/stdc++.h>
/*
An edge is separable if the states on either side are disjoint
"Unify" an entire path between edges
Every city is a unique state -> min number of paths to cover induced tree of separable edges
Root at "centroid" (vertex that splits leaves into sections of less than half), get leaves -> solved
STL and look at num. distinct values to see if separable
*/
std::vector<std::vector<int>> edges;
std::vector<int> states;
std::vector<int> stamounts;
std::vector<int> parents;
std::vector<int> separable;
int nleaves=0;
std::map<int,int>* dfs(int cur,int parent=0){
std::map<int,int>* merge=new std::map<int,int>;
(*merge)[states[cur]]++;
if(stamounts[states[cur]]==1){
merge->erase(states[cur]);
}
for(int i:edges[cur]){
if(i==parent)continue;
parents[i]=cur;
std::map<int,int>* newm=dfs(i,cur);
if(newm->size()>merge->size())std::swap(merge,newm);
for(std::pair<int,int> j:*newm){
(*merge)[j.first]+=j.second;
if((*merge)[j.first]==stamounts[j.first])merge->erase(j.first);
}
delete newm;
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#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...