제출 #1275220

#제출 시각아이디문제언어결과실행 시간메모리
1275220luattapcodeRailway (BOI17_railway)C++20
36 / 100
123 ms39760 KiB
/*The best way to get something done is to begin*/ #include <bits/stdc++.h> #define ll long long #define int long long #define fr(i,a,b) for(int i=a;i<=b;i++) #define frd(i,a,b) for(int i=a;i>=b;i--) #define pb push_back #define fi first #define se second #define el '\n' using namespace std; template <class X, class Y> bool minimize(X &x, const Y &y) {if (x > y) {x = y;return true;} else return false;} template <class X, class Y> bool maximize(X &x, const Y &y) {if (x < y) {x = y;return true;} else return false;} /* Author: Huynh Quoc Luat */ /*Khai Bao*/ const long long inf=1e18; const int oo=1e9; const int LO=21; const int CH=27; const int N=1e6+5; const int sm=1e9+7; int n,m,k; vector <pair <int,int>> g[N]; //void add(int &x,const int &y){x+=y;if(x>=sm)x-=sm;} //void sub(int &x,const int &y){x-=y;if(x<0)x+=sm;} void read() { cin >> n >> m >> k; fr(i,1,n-1){ int x,y; cin >> x >> y; g[x].pb({y,i}); g[y].pb({x,i}); } } namespace sub1 { vector <int> adj[N]; int in[N],out[N],P[N][LO]; int h[N]; int path[N]; int cnt[N]; int dem=0; bool cmp(int u,int v){ return in[u] <= in[v]; } void dfs(int u,int p){ in[u]=++dem; for(auto it:g[u]){ int v=it.fi; int id=it.se; if(v==p) continue; h[v]=h[u]+1; P[v][0]=u; path[v]=id; dfs(v,u); } out[u]=++dem; } int lca(int u,int v){ if(h[u]<h[v]) swap(u,v); frd(i,__lg(n),0) if(h[P[u][i]]>=h[v]) u=P[u][i]; frd(i,__lg(n),0) if(P[u][i]!=P[v][i]) u=P[u][i],v=P[v][i]; if(u==v) return u; return P[u][0]; } void update(int u,int p){ for(auto v:adj[u]){ if(v==p) continue; cnt[u]++; cnt[v]++; cnt[lca(u,v)]-=2; update(v,u); } } void DFS(int u,int p){ for(auto it:g[u]){ int v=it.fi; int id=it.se; if(v==p) continue; DFS(v,u); cnt[u]+=cnt[v]; } } vector <int> key; void process() { dfs(1,0); P[1][0]=1; fr(j,1,__lg(n)){ fr(i,1,n) P[i][j]=P[P[i][j-1]][j-1]; } while(m--){ int x,y; cin >> x; key.clear(); fr(i,1,x){ cin >> y; key.pb(y); } sort(key.begin(),key.end(),cmp); int sz=key.size(); fr(i,1,sz-1){ key.pb(lca(key[i-1],key[i])); } sort(key.begin(),key.end(),cmp); key.resize(unique(key.begin(),key.end())-key.begin()); deque <int> dq; for(auto v:key) adj[v].clear(); for(auto v:key){ while(!dq.empty() and out[dq.back()]<in[v]) dq.pop_back(); if(dq.size()){ adj[dq.back()].pb(v); adj[v].pb(dq.back()); } dq.pb(v); } update(key[0],0); } DFS(1,0); vector <int> ans; fr(i,2,n) if(cnt[i]>=k){ ans.pb(path[i]); } cout << ans.size() << el; for(auto v:ans) cout << v << " "; } } void time() {cerr<< endl<<"Luattapcode: "<<clock()<<"ms"<<endl;} main() { ios_base::sync_with_stdio(NULL);cin.tie(NULL);cout.tie(NULL); #define TASK "qn" if(fopen(TASK".INP","r")) { freopen(TASK".INP", "r", stdin); freopen(TASK".OUT", "w", stdout); } int mtt=0; int test=1; if(mtt) cin>>test; while(test--) { read(); sub1::process(); } time(); return 0; }

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

railway.cpp:132:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
  132 | main()
      | ^~~~
railway.cpp: In function 'int main()':
railway.cpp:138:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  138 |         freopen(TASK".INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
railway.cpp:139:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  139 |         freopen(TASK".OUT", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#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...