제출 #1004354

#제출 시각아이디문제언어결과실행 시간메모리
1004354ayankarimovaRailway (BOI17_railway)C++14
7 / 100
163 ms39364 KiB
#include <bits/stdc++.h> using namespace std; #define endl '\n' #define ll long long const ll sz=1e5+5; ll p[sz], tt, pos[sz], in[sz], root; vector<ll>g[sz], vec={0}; set<ll>s; map<ll, ll>mp; map<pair<ll, ll>, ll>m1; /* {} [] */ void dfs(ll u, ll par) { vec.push_back(u); pos[u]=++tt; for(auto v:g[u]){ if(v!=par){ dfs(v, u); } } } int main() { ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); ll n, m, k; cin>>n>>m>>k; for(int i=1; i<n; i++){ ll a, b; cin>>a>>b; g[a].push_back(b); g[b].push_back(a); m1[{a, b}]=i; m1[{b, a}]=i; in[a]++; in[b]++; } for(int i=1; i<=n; i++) if(in[i]==1) root=i; dfs(root, 0); for(int i=1; i<=m; i++){ ll num; cin>>num; ll k[num+1]; for(int j=1; j<=num; j++){ cin>>k[j]; } for(int j=2; j<=num; j++){ ll x=k[j-1], y=k[j]; ll a=pos[x], b=pos[y]; if(a>b) swap(a, b); p[a]++; p[b]--; } } for(int i=1; i<n; i++){ p[i]+=p[i-1]; mp[m1[{vec[i], vec[i+1]}]]+=p[i]; //cout<<p[i]<<' '; } for(auto i:mp){ if(i.second>=k){ s.insert(i.first); } } cout<<s.size()<<endl; for(auto i:s) cout<<i<<' '; } /* {} [] 4 3 3 2 1 1 4 4 3 3 1 2 3 2 1 4 2 2 3 */
#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...