QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#84947 | #5659. Watching Cowflix | CharlieVinnie | 20.833333 | 127ms | 97844kb | C++14 | 1.9kb | 2023-03-06 21:11:55 | 2023-03-06 21:12:05 |
Judging History
answer
#include <bits/stdc++.h>
#define For(i,a,b) for(int i=a;i<=b;i++)
#define Rev(i,a,b) for(int i=a;i>=b;i--)
#define Fin(file) freopen(file,"r",stdin)
#define Fout(file) freopen(file,"w",stdout)
using namespace std; using ll = long long;
#define printf(...) (0==0)
const int N=2e6+5;
class DSU{
public:
int n,fa[N];
void init(int _n) { n=_n; iota(fa+1,fa+1+n,1); }
int getfa(int x) { return x==fa[x]?x:fa[x]=getfa(fa[x]); }
}S;
char ss[N]; int n,K,fa[N],lis[N],lcnt,tmp[N],tcnt,g[N]; vector<int> to[N],son[N]; ll f[N][2],Ans[N];
void dfs0(int u,int pa) { fa[u]=pa; lis[++lcnt]=u; for(int v:to[u]) if(v!=pa) son[u].push_back(v),dfs0(v,u); }
int main(){
//~ Fin("hh.in"); Fout("hh.out");
cin>>n>>(ss+1); For(i,1,n-1) { int x,y; cin>>x>>y; to[x].push_back(y); to[y].push_back(x); }
dfs0(1,0); S.init(n); int Dlt=0;
for(K=1;K<=n;K++){
//~ if(K==5){
//~ printf("K=5\n");
//~ For(i,1,lcnt){
//~ printf("lis[%d]=%d\n",i,lis[i]);
//~ for(int v:son[lis[i]]) printf("%d ",v);; puts("");
//~ }
//~ }
Rev(i,lcnt,1){
int u=lis[i];
f[u][1]=1; f[u][0]=(ss[u]=='0'?0:1e18);
for(int v:son[u]){
ll f1 = min( f[u][1]+f[v][1], f[u][1]+f[v][0] );
ll f0 = min( f[u][0]+f[v][1]+K, f[u][0]+f[v][0] );
f[u][1]=f1; f[u][0]=f0;
}
}
Ans[K]=min(f[1][0],f[1][1]+K)+Dlt;
g[1] = f[1][0]<f[1][1]+K ? 0 : 1;
tcnt=0; tmp[++tcnt]=1;
For(i,1,lcnt) if(son[lis[i]].size()){
int u=lis[i];
for(int v:son[u]){
if(g[u]==1) g[v] = f[u][1]+f[v][1]<f[u][1]+f[v][0] ? 1 : 0;
else g[v] = f[u][0]+f[v][1]+K<f[u][0]+f[v][0] ? 1 : 0;
if(g[v]==1&&g[u]==1) S.fa[v]=S.getfa(fa[v]),Dlt++,ss[u]='1',printf("K=%d: Deleted %d\n",K,v);
else tmp[++tcnt]=v;
}
}
For(i,1,lcnt) son[lis[i]].clear();
lcnt=tcnt; For(i,1,lcnt) lis[i]=tmp[i];
For(i,2,lcnt) son[S.getfa(fa[lis[i]])].push_back(lis[i]);
}
For(i,1,n) cout<<Ans[i]<<'\n';
return 0;
}
详细
Test #1:
score: 4.16667
Accepted
time: 11ms
memory: 97264kb
input:
5 10001 1 2 2 3 3 4 4 5
output:
4 6 8 9 10
result:
ok 5 number(s): "4 6 8 9 10"
Test #2:
score: 4.16667
Accepted
time: 16ms
memory: 97120kb
input:
7 0001010 7 4 5 6 7 2 5 1 6 3 2 5
output:
4 6 8 9 10 11 12
result:
ok 7 numbers
Test #3:
score: 4.16667
Accepted
time: 125ms
memory: 97628kb
input:
5000 0100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000010000000...
output:
711 837 944 1040 1121 1192 1249 1303 1352 1398 1439 1479 1518 1557 1596 1634 1671 1707 1742 1775 1807 1839 1871 1902 1932 1961 1990 2018 2046 2073 2099 2125 2150 2174 2197 2220 2242 2264 2286 2308 2329 2349 2368 2386 2404 2422 2439 2456 2472 2487 2502 2516 2529 2541 2552 2563 2573 2583 2593 2603 261...
result:
ok 5000 numbers
Test #4:
score: 4.16667
Accepted
time: 110ms
memory: 97684kb
input:
5000 0100000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000...
output:
890 1226 1433 1547 1619 1676 1727 1775 1821 1865 1908 1950 1989 2027 2064 2100 2136 2171 2206 2240 2273 2305 2336 2366 2395 2424 2452 2479 2506 2532 2557 2581 2604 2626 2648 2670 2691 2711 2730 2749 2768 2786 2804 2821 2837 2853 2869 2884 2898 2911 2923 2934 2944 2953 2962 2971 2980 2988 2995 3001 3...
result:
ok 5000 numbers
Test #5:
score: 4.16667
Accepted
time: 127ms
memory: 97844kb
input:
5000 0100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000001000000000000000001000000000000000000000000000000000000000000000000...
output:
794 1025 1178 1284 1364 1422 1473 1517 1559 1600 1640 1679 1717 1754 1790 1826 1861 1895 1928 1960 1992 2024 2056 2088 2119 2150 2181 2211 2241 2270 2298 2325 2351 2376 2401 2425 2448 2471 2493 2515 2536 2556 2575 2594 2612 2629 2645 2660 2674 2688 2701 2713 2724 2734 2743 2751 2759 2766 2772 2777 2...
result:
ok 5000 numbers
Test #6:
score: 0
Time Limit Exceeded
input:
200000 01000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
output:
result:
Test #7:
score: 0
Time Limit Exceeded
input:
200000 01000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
output:
result:
Test #8:
score: 0
Time Limit Exceeded
input:
200000 01000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
output:
result:
Test #9:
score: 0
Time Limit Exceeded
input:
100000 01000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
output:
result:
Test #10:
score: 0
Time Limit Exceeded
input:
100000 01000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
output:
result:
Test #11:
score: 0
Time Limit Exceeded
input:
100000 01000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
output:
result:
Test #12:
score: 0
Time Limit Exceeded
input:
100000 01000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
output:
result:
Test #13:
score: 0
Time Limit Exceeded
input:
100000 01000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
output:
result:
Test #14:
score: 0
Time Limit Exceeded
input:
100000 01000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
output:
result:
Test #15:
score: 0
Time Limit Exceeded
input:
100000 01000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
output:
result:
Test #16:
score: 0
Time Limit Exceeded
input:
100000 01000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
output:
result:
Test #17:
score: 0
Time Limit Exceeded
input:
100000 01000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
output:
result:
Test #18:
score: 0
Time Limit Exceeded
input:
100000 01000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
output:
result:
Test #19:
score: 0
Time Limit Exceeded
input:
100000 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
output:
result:
Test #20:
score: 0
Time Limit Exceeded
input:
200000 01000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
output:
result:
Test #21:
score: 0
Time Limit Exceeded
input:
200000 01000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
output:
result:
Test #22:
score: 0
Time Limit Exceeded
input:
200000 01000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
output:
result:
Test #23:
score: 0
Time Limit Exceeded
input:
200000 01000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
output:
result:
Test #24:
score: 0
Time Limit Exceeded
input:
200000 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...