結果
| 問題 | No.3405 Engineering University of Tree |
| コンテスト | |
| ユーザー |
👑 kmjp
|
| 提出日時 | 2025-12-17 00:03:55 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,287 bytes |
| 記録 | |
| コンパイル時間 | 2,020 ms |
| コンパイル使用メモリ | 209,384 KB |
| 実行使用メモリ | 57,984 KB |
| 最終ジャッジ日時 | 2025-12-17 00:04:09 |
| 合計ジャッジ時間 | 10,676 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 14 WA * 7 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------
int N;
vector<int> Es[202020];
int P[202020];
vector<pair<int,int>> E2[202020];
vector<int> E[202020];
int NC[202020];
vector<pair<int,int>> cand;
void dfs(int cur,int pre) {
P[cur]=pre;
FORR(e,E[cur]) if(e!=pre) {
dfs(e,cur);
E2[cur].push_back({E[e].size(),e});
NC[cur]++;
}
sort(ALL(Es[cur]));
reverse(ALL(Es[cur]));
}
pair<int,int> dfs2(int cur,int pre,int k) {
int sum=0;
int more=0;
while(E2[cur].size()&&E2[cur].back().first<k) E2[cur].pop_back();
FORR2(a,e,E2[cur]) {
auto p=dfs2(e,cur,k);
//cout<<cur<<" "<<k<<" "<<e<<" "<<p.first<<" "<<p.second<<endl;
sum+=p.second;
if(p.first!=p.second) more++;
}
if(NC[cur]-more>=k) {
//cout<<cur<<" "<<sum+1<<" "<<sum+1<<endl;
return {sum+1,sum+1};
}
else if(NC[cur]-more+1>=k) {
//cout<<cur<<" "<<sum<<" "<<sum+1<<endl;
return {sum,sum+1};
}
else {
//cout<<cur<<" "<<sum<<" "<<sum<<endl;
return {sum,sum};
}
}
void solve() {
int i,j,k,l,r,x,y; string s;
cin>>N;
FOR(i,N) {
cin>>k;
FOR(j,k) {
cin>>x;
Es[x].push_back(i);
E[i].push_back(x);
}
cand.push_back({k,i});
}
FOR(i,N) {
FORR(e,E[i]) {
if(Es[e][0]==i) e=Es[e][1];
else e=Es[e][0];
}
}
dfs(0,0);
sort(ALL(cand));
reverse(ALL(cand));
for(i=1;i<=N-1;i++) {
while(cand.size()&&cand.back().first<i) cand.pop_back();
int ret=0;
FORR2(a,b,cand) if(b==0||E[P[b]].size()<i) {
auto p=dfs2(b,b,i);
if(b==0) ret+=p.first;
else ret+=p.second;
}
cout<<ret<<" ";
}
cout<<endl;
}
int main(int argc,char** argv){
string s;int i;
if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
cout.tie(0); solve(); return 0;
}
kmjp