Submission #449944

#TimeUsernameProblemLanguageResultExecution timeMemory
449944cpp219Railway (BOI17_railway)C++14
100 / 100
181 ms29236 KiB
#pragma GCC optimization O2 #pragma GCC optimization "unroll-loop" #pragma target ("avx2") #include <bits/stdc++.h> #define ll int #define ld long double #define fs first #define sc second using namespace std; typedef pair<ll,ll> LL; const ll N = 1e5 + 9; const ll Log2 = 21; const ll inf = 1e9 + 7; vector<ll> g[N]; ll n,Q,k,x,y,par[N][Log2],pos[N],child[N],nTime,d[N]; ll tot[N]; void DFS(ll u,ll p){ child[u] = 1; pos[u] = nTime++; for (ll i = 1;i < Log2;i++) if ((1 << i) <= d[u]) par[u][i] = par[par[u][i - 1]][i - 1]; for (auto i : g[u]){ if (i == p) continue; d[i] = d[u] + 1; par[i][0] = u; DFS(i,u); child[u] += child[i]; } } ll LCA(ll u,ll v){ if (d[u] > d[v]) swap(u,v); for (ll i = Log2 - 1;i >= 0;i--) if ((1 << i) <= d[v] && d[par[v][i]] >= d[u]) v = par[v][i]; if (u == v) return u; for (ll i = Log2 - 1;i >= 0;i--) if (par[u][i] != par[v][i]) u = par[u][i],v = par[v][i]; return par[u][0]; } void reDFS(ll u,ll p){ //cout<<u<<" "<<p<<"\n"; for (auto i : g[u]) if (i != p){ reDFS(i,u); tot[u] += tot[i]; } } bool lf(ll x,ll y){ return pos[x] < pos[y]; } vector<LL> edge; int main(){ ios_base::sync_with_stdio(NULL); cin.tie(0); cout.tie(0); #define task "test" if (fopen(task".INP","r")){ freopen(task".INP","r",stdin); //freopen(task".OUT","w",stdout); } cin>>n>>Q>>k; for (ll i = 1;i < n;i++){ cin>>x>>y; edge.push_back({x,y}); g[x].push_back(y); g[y].push_back(x); } DFS(1,0); while(Q--){ vector<ll> v; ll sz,x; cin>>sz; for (ll i = 1;i <= sz;i++) cin>>x,v.push_back(x),tot[x]++; sort(v.begin(),v.end(),lf); tot[LCA(v[0],v.back())]--; for (ll i = 1;i < v.size();i++){ ll cur = LCA(v[i],v[i - 1]); tot[cur]--; } } vector<ll> ans; reDFS(1,0); //for (ll i = 1;i <= n;i++) cout<<tot[i]<<" "; return 0; for (ll i = 0;i < n - 1;i++){ ll x = edge[i].fs,y = edge[i].sc; if (pos[x] < pos[y]) swap(x,y); if (tot[x] >= k) ans.push_back(i + 1); } cout<<ans.size()<<"\n"; for (auto i : ans) cout<<i<<" "; }

Compilation message (stderr)

railway.cpp:1: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    1 | #pragma GCC optimization O2
      | 
railway.cpp:2: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    2 | #pragma GCC optimization "unroll-loop"
      | 
railway.cpp:3: warning: ignoring '#pragma target ' [-Wunknown-pragmas]
    3 | #pragma target ("avx2")
      | 
railway.cpp: In function 'int main()':
railway.cpp:71:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   71 |         for (ll i = 1;i < v.size();i++){
      |                       ~~^~~~~~~~~~
railway.cpp:57:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   57 |         freopen(task".INP","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
#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...