QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#184710 | #3100. Meetings 2 | bear0131# | 0 | 2ms | 5620kb | C++20 | 3.3kb | 2023-09-21 09:22:38 | 2024-07-04 02:06:06 |
answer
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n;++i)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef array<int, 3> ai3;
const int inf = 0x3f3f3f3f;
const int Mod = 998244353;
const int inv2 = (Mod+1) / 2;
inline int sign(int a){ return (a&1) ? (Mod-1) : 1; }
inline void uadd(int &a, int b){ a += b-Mod; a += (a>>31) & Mod; }
inline void usub(int &a, int b){ a -= b, a += (a>>31) & Mod; }
inline void umul(int &a, int b){ a = (int)(1ll * a * b % Mod); }
inline int add(int a, int b){ a += b-Mod; a += (a>>31) & Mod; return a; }
inline int sub(int a, int b){ a -= b, a += (a>>31) & Mod; return a; }
inline int mul(int a, int b){ a = (int)(1ll * a * b % Mod); return a; }
int qpow(int b, int p){ int ret = 1; while(p){ if(p&1) umul(ret, b); umul(b, b), p >>= 1; } return ret; }
const int fN = 100;
int fact[fN], invfact[fN], pw2[fN], invpw2[fN];
void initfact(int n){
pw2[0] = 1; for(int i = 1; i <= n; ++i) pw2[i] = mul(pw2[i-1], 2);
invpw2[0] = 1; for(int i = 1; i <= n; ++i) invpw2[i] = mul(invpw2[i-1], (Mod+1) / 2);
fact[0] = 1; for(int i = 1; i <= n; ++i) fact[i] = mul(fact[i-1], i);
invfact[n] = qpow(fact[n], Mod-2); for(int i = n; i > 0; --i) invfact[i-1] = mul(invfact[i], i);
}
int binom(int n, int m){ return mul(fact[n], mul(invfact[m], invfact[n-m])); }
const double pi = acos(-1);
inline void chmax(ll &a, ll b){ (b>a) ? (a=b) : 0; }
int n;
vi g[200200];
int ban[200200], allsz, dept[200200], bel[200200], sz[200200], nrt = 0, rtsz = inf;
vi ord;
void dfs0(int u, int par){
ord.emplace_back(u);
sz[u] = 1;
rep(i, (int)g[u].size()){
int t = g[u][i];
if(t == par || ban[t]) continue;
dfs0(t, u);
sz[u] += sz[t];
}
}
void dfs1(int u, int par){
sz[u] = 1;
int mxsz = 0;
rep(i, (int)g[u].size()){
int t = g[u][i];
if(t == par || ban[t]) continue;
dept[t] = dept[u] + 1, bel[t] = (par == -1 ? t : bel[u]);
dfs1(t, u);
sz[u] += sz[t], mxsz = max(mxsz, sz[t]);
}
mxsz = max(mxsz, allsz - sz[u]);
if(mxsz < rtsz) rtsz = mxsz, nrt = u;
}
int mxdep[200200], ans[200200];
void solve(int rt){
ord.clear();
rtsz = inf;
dfs0(rt, -1), allsz = sz[rt], dfs1(rt, -1);
rt = nrt;
dept[rt] = 0, dfs1(rt, -1);
//cout << "solve " << rt << "\n";
sort(ord.begin(), ord.end(), [&](int lh, int rh){ return sz[lh] > sz[rh]; });
int p = allsz / 2, curans = 0;
priority_queue< pii > pq;
pq.emplace(0, -1);
for(int i = 1; i < (int)ord.size(); ++i){
int u = ord[i];
while(p > sz[u]) ans[p] = max(ans[p], curans + 1), --p;
while(pq.top().second == bel[u]) pq.pop();
curans = max(curans, dept[u] + pq.top().first);
mxdep[bel[u]] = max(mxdep[bel[u]], dept[u]);
pq.emplace(mxdep[bel[u]], bel[u]);
}
while(p) ans[p] = max(ans[p], curans + 1), --p;
ban[rt] = 1;
rep(i, (int)g[rt].size()){
int t = g[rt][i];
if(!ban[t])
solve(t);
}
//cout << "solved " << rt << endl;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n;
rep(i, n-1){
int u, v;
cin >> u >> v;
--u, --v;
g[u].emplace_back(v), g[v].emplace_back(u);
}
solve(0);
for(int i = 1; i <= n; ++i)
if(i & 1)
cout << "1\n";
else
cout << ans[i/2] << "\n";
return 0;
}
详细
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 4
Accepted
time: 2ms
memory: 5620kb
input:
1
output:
1
result:
ok single line: '1'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3892kb
input:
2 2 1
output:
1 2
result:
ok 2 lines
Test #3:
score: 0
Accepted
time: 1ms
memory: 3604kb
input:
3 1 3 3 2
output:
1 3 1
result:
ok 3 lines
Test #4:
score: -4
Wrong Answer
time: 1ms
memory: 3592kb
input:
14 12 14 12 9 14 2 12 6 12 7 6 4 3 4 1 4 12 8 13 1 10 12 11 6 6 5
output:
1 7 1 6 1 3 1 3 1 2 1 2 1 2
result:
wrong answer 4th lines differ - expected: '5', found: '6'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #1:
0%