Submission #924554

# Submission time Handle Problem Language Result Execution time Memory
924554 2024-02-09T07:46:05 Z UmairAhmadMirza Railway (BOI17_railway) C++17
0 / 100
1000 ms 33940 KB
#include <bits/stdc++.h>
using namespace std;
int const N=100005;
int const M=50005;
vector<int> adj[N];
vector<int> cnt[N];
int sz[M];
vector<int> ans;
int n,m,k;
map<pair<int,int>,int> mp;
multiset<int> minister;
void dfs(int node,int par){
  for(auto i:adj[node])
    if(i!=par)
      dfs(i,node);
  for(auto j:cnt[node])
    minister.insert(j);
  int p=0;
  for(int j=0;j<m;j++){
    int c=minister.count(j);
    if(c<sz[j] && c>0)
      p++;
  }
  if(p>=k && par!=-1)
    ans.push_back(mp[{par,node}]);
}
int main(){
  cin>>n>>m>>k;
  for(int i=0;i<n-1;i++){
    int a,b;
    cin>>a>>b;
    mp[{a,b}]=i+1;
    mp[{b,a}]=i+1;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  for(int i=0;i<m;i++){
    cin>>sz[i];
    for(int j=0;j<sz[i];j++){
      int a;
      cin>>a;
      cnt[a].push_back(i);
    }
  }
  for(int i=1;i<=n;i++){
    if(adj[i].size()>1)
      continue;
    dfs(i,-1);
    break;
  }
  cout<<ans.size()<<endl;
  sort(ans.begin(),ans.end());
  for(auto i:ans)
    cout<<i<<' ';
  cout<<endl;
  return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 4956 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 4956 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1086 ms 33940 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1083 ms 28188 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1083 ms 28188 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 4956 KB Output isn't correct
2 Halted 0 ms 0 KB -