Submission #924482

#TimeUsernameProblemLanguageResultExecution timeMemory
924482Sir_Ahmed_ImranRailway (BOI17_railway)C++17
100 / 100
135 ms27380 KiB
///~~~LOTA~~~/// #include <bits/stdc++.h> using namespace std; #define ll long long #define append push_back #define add insert #define nl "\n" #define ff first #define ss second #define pii pair<int,int> #define all(x) (x).begin(),(x).end() #define L0TA ios_base::sync_with_stdio(false);cin.tie(NULL) #define N 100001 int k; int s[N]; vector<int> ans; vector<pii> a[N]; vector<int> c[N]; map<int,int> *x[N]; void dfs(int v,int u){ int z=0; for(auto& i:a[v]){ if(i.ss==u) continue; dfs(i.ff,i.ss); if((*x[i.ff]).size()>(*x[z]).size()) z=i.ff; } if(z>0) x[v]=x[z]; else x[v]=new map<int,int>; for(auto &i:a[v]){ if(i.ss==u || i.ff==z) continue; for(auto& j:*x[i.ff]){ (*x[v])[j.ff]+=j.ss; if(s[j.ff]==(*x[v])[j.ff]) (*x[v]).erase(j.ff); } (*x[i.ff]).clear(); } for(auto& i:c[v]){ (*x[v])[i]++; if(s[i]==(*x[v])[i]) (*x[v]).erase(i); } if((*x[v]).size()>=k) ans.append(u); } void solve(){ int n,m,p,q; cin>>n>>m>>k; for(int i=1;i<n;i++){ cin>>p>>q; a[p].append({q,i}); a[q].append({p,i}); } for(int i=0;i<m;i++){ cin>>s[i]; for(int j=0;j<s[i];j++){ cin>>q; c[q].append(i); } } x[0]=new map<int,int>; dfs(1,0); sort(all(ans)); cout<<ans.size()<<nl; for(auto& i:ans) cout<<i<<' '; } int main(){ L0TA; solve(); return 0; }

Compilation message (stderr)

railway.cpp: In function 'void dfs(int, int)':
railway.cpp:45:22: warning: comparison of integer expressions of different signedness: 'std::map<int, int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   45 |     if((*x[v]).size()>=k)
      |        ~~~~~~~~~~~~~~^~~
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...