제출 #500855

#제출 시각아이디문제언어결과실행 시간메모리
500855MohamedAliSaidaneRailway (BOI17_railway)C++14
100 / 100
507 ms36020 KiB
#include <bits/stdc++.h> using namespace std; typedef pair<int,int> pii; typedef vector<int> vi; typedef long long ll; typedef pair<ll,ll> pll; typedef tuple<int,int,int> ti; typedef unsigned long long ull; typedef long double ld; typedef vector<ll> vll; typedef pair<ld,ld> pld; #define pb push_back #define popb pop_back() #define pf push_front #define popf pop_front #define ff first #define ss second #define MOD (ll)(1000000007) #define INF (ll) (1e18) #define all(v) (v).begin(),(v).end() const int nx[8] = {0, 0, 1, -1,1,1,-1,-1}, ny[8] = {1, -1, 0, 0,1,-1,1,-1}; //East, West, South, North+ ll gcd(ll a , ll b) {return b ? gcd(b , a % b) : a ;} ll lcm(ll a, ll b){return (a / gcd(a, b)) * b;} ////////////******SOLUTION******\\\\\\\\\\\ const int MAX_N = 2e5 + 4;; int n, m, k, sz = 1; vi adj[MAX_N]; int heavy[MAX_N]; vi st, lazy; int p[MAX_N]; int head[MAX_N]; int subtree[MAX_N]; int d[MAX_N]; int eul[MAX_N]; int cur_eul = -1; map<pii,int> key; bool comp(int a, int b) { return eul[a] < eul[b]; } void propagate(int p, int l, int r) { if(lazy[p] != 0) { st[p] += lazy[p] * (r-l+1); if(l != r) { lazy[2*p] += lazy[p]; lazy[2*p+1] += lazy[p]; } lazy[p] = 0; } } int query(int p, int l, int r, int i, int j) { propagate(p,l,r); if( i > j) return 0; if(l >= i && r <= j) return st[p]; int mid = (l+r)/2; return query(2*p,l,mid,i,min(mid,j)) + query(2*p+1,mid+1,r,max(i,mid+1),j); } void update(int p, int l, int r, int i, int j, int val) { propagate(p,l,r); if(i > j ) return ; if(l >= i && r <= j) { lazy[p] += val; propagate(p,l,r); } else { int mid = (l+r)/2; update(2*p,l,mid,i,min(j,mid),val); update(2*p+1,mid+1,r,max(i,mid+1),j,val); int lsubtree = (lazy[2*p] * (r-l+1))/2 + st[2*p]; int rsubtree = (lazy[2*p+1] * (r-l+1))/2 + st[2*p+1]; st[p] = lsubtree + rsubtree; } } void dfs(int x, int par) { d[x] = d[par] + 1; p[x] = par; subtree[x] = 1; for(auto e: adj[x]) { if(e == par) continue; dfs(e,x); subtree[x] += subtree[e]; if(subtree[e] > subtree[heavy[x]]) heavy[x] = e; } } void decompose(int x, int h) { head[x] = h; eul[x] = ++cur_eul; if(heavy[x] != 0) decompose(heavy[x],h); for(auto e: adj[x]) { if(e != p[x] && e != heavy[x]) { decompose(e,e); } } } void upd(int a, int b) { for(;head[a] != head[b]; b = p[head[b]]) { if(d[head[a]] > d[head[b]]) swap(a,b); update(1,0,sz-1,eul[head[b]],eul[b],1); } if(d[a] > d[b]) swap(a,b); update(1,0,sz-1,eul[a]+1,eul[b],1); return ; } void solve() { cin >> n >> m >> k; while(sz < n) sz = (sz << 1); st.assign(2*sz+1,0); lazy.assign(2*sz+1,0); for(int i = 1; i <n; i ++) { int a,b; cin >> a >> b; adj[a].pb(b); adj[b].pb(a); key[{a,b}] = key[{b,a}] = i; } d[0] = -1; dfs(1,0); decompose(1,1); for(int i = 1; i<= m; i ++) { int s; cin >> s; int nodes[s]; for(int j = 0; j <s; j ++) cin >> nodes[j]; sort(nodes,nodes+s,comp); for(int j = 0; j <s; j ++) { int u =nodes[j]; int v = nodes[(j+1)%s]; upd(u,v); } } vi ans; for(int i= 2; i <=n; i ++) { int val = query(1,0,sz-1,eul[i],eul[i]); if(val >= 2*k) { ans.pb(key[{i,p[i]}]); } } sort(all(ans)); cout << ans.size() << '\n'; for(auto e: ans) cout << e << ' '; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int tt =1; while(tt--) { solve(); } } /* */

컴파일 시 표준 에러 (stderr) 메시지

railway.cpp:24:1: warning: multi-line comment [-Wcomment]
   24 | ////////////******SOLUTION******\\\\\\\\\\\
      | ^
#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...