Submission #1045921
Source Code Expand
#include<bits/stdc++.h> #define REP(i,m) for(int i=0;i<(m);++i) #define REPN(i,m,in) for(int i=(in);i<(m);++i) #define ALL(t) (t).begin(),(t).end() #define CLR(a) memset((a),0,sizeof(a)) #define pb push_back #define mp make_pair #define fr first #define sc second using namespace std; #ifdef DEB #define dump(x) cerr << #x << " = " << (x) << endl #define prl cerr<<"called:"<< __LINE__<<endl #define dumpR(x) cerr<<"\x1b[31m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl #define dumpY(x) cerr<<"\x1b[33m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl #define dumpG(x) cerr<<"\x1b[32m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl template<class T> void debug(T a,T b){ for(;a!=b;++a) cerr<<*a<<' ';cerr<<endl;} #else #define dump(x) ; #define dumpR(x) ; #define dumpY(x) ; #define dumpG(x) ; #define prl ; template<class T> void debug(T a,T b){ ;} #endif template<class T> void chmin(T& a,const T& b) { if(a>b) a=b; } template<class T> void chmax(T& a,const T& b) { if(a<b) a=b; } typedef long long int lint; typedef pair<lint,lint> pi; namespace std{ template<class S,class T> ostream &operator <<(ostream& out,const pair<S,T>& a){ out<<'('<<a.fr<<','<<a.sc<<')'; return out; } } const int INF=5e8; char s[200005]; int tot1; int n; vector<int> g[200005]; int size[200005],dist[200005]; int start[200005],fin[200005],cnt; int msum[200005]; void dfs(int v,int p){ size[v]=1; start[v]=cnt; msum[cnt+1]=msum[cnt]+(s[v]=='1'?1:0); ++cnt; dist[v]=0; for(auto to:g[v]){ if(to==p) continue; dfs(to,v); size[v]+=size[to]; chmax(dist[v],dist[to]+1); } fin[v]=cnt; } lint add=0; int subt1(int v){ return msum[fin[v]]-msum[start[v]]; } int g2[200005]; int ub[200005],lb[200005]; void dfs3(int v,int p,int down){//...lim) pair<int,int> most,sec; most=sec=mp(-1,-1); most.sc=down; most.fr=p; sec.sc=0; for(auto to:g[v]){ if(to==p) continue; int val=dist[to]+1; if(most.sc<val){ sec=most; most=mp(to,val); }else if(sec.sc<val){ sec=mp(to,val); } } ub[v]=sec.sc; lb[v]=INF; if(s[v]=='1') lb[v]=0; if(most.sc>sec.sc){ g2[v]=most.fr; } if(~p){ if(down-1<dist[v]){ if(tot1-subt1(v)>0) ++add; }else if(down-1>dist[v]){ if(subt1(v)>0) ++add; }else{ ++add; } dump(v);dump(add); } for(auto to:g[v]){ if(to==p) continue; int d; if(to==most.fr){ d=sec.sc+1; }else{ d=most.sc+1; } dfs3(to,v,d); } } int main(){ cin>>n; REP(i,n-1){ int a,b;scanf("%d%d",&a,&b);--a;--b; g[a].pb(b); g[b].pb(a); } scanf("%s",s); REP(i,n) if(s[i]=='1') ++tot1; dfs(0,-1); memset(g2,-1,sizeof(g2)); dfs3(0,-1,0); priority_queue<pi,vector<pi>,greater<pi>>pq; REP(i,n){ pq.push(mp(lb[i],i)); } debug(g2,g2+n); while(!pq.empty()){ pi cur=pq.top();pq.pop(); int v=cur.sc; if(lb[v]>ub[v]) continue; if(~g2[cur.sc] && lb[g2[cur.sc]]>ub[cur.sc]+1){ lb[g2[cur.sc]]=ub[cur.sc]+1; pq.push(mp(lb[g2[cur.sc]],g2[cur.sc])); } } lint res=0; REP(i,n) res+=max(0,ub[i]-lb[i]+1); debug(lb,lb+n); debug(ub,ub+n); dump(add); res+=add; cout<<res<<endl; return 0; }
Submission Info
Submission Time | |
---|---|
Task | F - Black Radius |
User | hogloid |
Language | C++14 (GCC 5.4.1) |
Score | 1900 |
Code Size | 3336 Byte |
Status | AC |
Exec Time | 219 ms |
Memory | 33780 KB |
Compile Error
./Main.cpp: In function ‘int main()’: ./Main.cpp:121:32: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] int a,b;scanf("%d%d",&a,&b);--a;--b; ^ ./Main.cpp:125:16: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%s",s); ^
Judge Result
Set Name | Sample | Subtask | All | ||||||
---|---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 1300 / 1300 | 600 / 600 | ||||||
Status |
|
|
|
Set Name | Test Cases |
---|---|
Sample | 0_00.txt, 0_01.txt, 0_02.txt |
Subtask | 0_01.txt, 1_00.txt, 1_01.txt, 1_02.txt, 1_03.txt, 1_04.txt, 1_05.txt, 1_06.txt, 1_07.txt, 1_08.txt, 1_09.txt, 1_10.txt, 1_11.txt, 1_12.txt, 1_13.txt, 1_14.txt, 1_15.txt, 1_16.txt, 1_17.txt, 1_18.txt, 1_19.txt, 1_20.txt, 1_21.txt, 1_22.txt, 1_23.txt, 1_24.txt, 1_25.txt, 1_26.txt, 1_27.txt, 1_28.txt, 1_29.txt |
All | 0_00.txt, 0_01.txt, 0_02.txt, 1_00.txt, 1_01.txt, 1_02.txt, 1_03.txt, 1_04.txt, 1_05.txt, 1_06.txt, 1_07.txt, 1_08.txt, 1_09.txt, 1_10.txt, 1_11.txt, 1_12.txt, 1_13.txt, 1_14.txt, 1_15.txt, 1_16.txt, 1_17.txt, 1_18.txt, 1_19.txt, 1_20.txt, 1_21.txt, 1_22.txt, 1_23.txt, 1_24.txt, 1_25.txt, 1_26.txt, 1_27.txt, 1_28.txt, 1_29.txt, 2_00.txt, 2_01.txt, 2_02.txt, 2_03.txt, 2_04.txt, 2_05.txt, 2_06.txt, 2_07.txt, 2_08.txt, 2_09.txt, 2_10.txt, 2_11.txt, 2_12.txt, 2_13.txt, 2_14.txt, 2_15.txt, 2_16.txt, 2_17.txt, 2_18.txt, 2_19.txt, 2_20.txt, 2_21.txt, 2_22.txt, 2_23.txt, 2_24.txt, 2_25.txt, 2_26.txt, 2_27.txt, 2_28.txt, 2_29.txt, 2_30.txt, 2_31.txt, 2_32.txt, 2_33.txt, 2_34.txt, 2_35.txt, 2_36.txt, 2_37.txt, 2_38.txt, 2_39.txt, 2_40.txt, 2_41.txt, 2_42.txt, 2_43.txt, 2_44.txt, 2_45.txt, 2_46.txt, 2_47.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
0_00.txt | AC | 8 ms | 5760 KB |
0_01.txt | AC | 9 ms | 5760 KB |
0_02.txt | AC | 9 ms | 5760 KB |
1_00.txt | AC | 8 ms | 5760 KB |
1_01.txt | AC | 180 ms | 33780 KB |
1_02.txt | AC | 161 ms | 29556 KB |
1_03.txt | AC | 144 ms | 21876 KB |
1_04.txt | AC | 132 ms | 22256 KB |
1_05.txt | AC | 116 ms | 22640 KB |
1_06.txt | AC | 141 ms | 22004 KB |
1_07.txt | AC | 142 ms | 22128 KB |
1_08.txt | AC | 143 ms | 23024 KB |
1_09.txt | AC | 155 ms | 27888 KB |
1_10.txt | AC | 150 ms | 26868 KB |
1_11.txt | AC | 164 ms | 33520 KB |
1_12.txt | AC | 146 ms | 24432 KB |
1_13.txt | AC | 154 ms | 27376 KB |
1_14.txt | AC | 145 ms | 24304 KB |
1_15.txt | AC | 144 ms | 23284 KB |
1_16.txt | AC | 149 ms | 25196 KB |
1_17.txt | AC | 153 ms | 26484 KB |
1_18.txt | AC | 142 ms | 21876 KB |
1_19.txt | AC | 141 ms | 21872 KB |
1_20.txt | AC | 142 ms | 21872 KB |
1_21.txt | AC | 147 ms | 22644 KB |
1_22.txt | AC | 137 ms | 22256 KB |
1_23.txt | AC | 137 ms | 22128 KB |
1_24.txt | AC | 143 ms | 22896 KB |
1_25.txt | AC | 139 ms | 24048 KB |
1_26.txt | AC | 133 ms | 22000 KB |
1_27.txt | AC | 130 ms | 22256 KB |
1_28.txt | AC | 126 ms | 22768 KB |
1_29.txt | AC | 141 ms | 24944 KB |
2_00.txt | AC | 8 ms | 5760 KB |
2_01.txt | AC | 170 ms | 33268 KB |
2_02.txt | AC | 183 ms | 31476 KB |
2_03.txt | AC | 183 ms | 30836 KB |
2_04.txt | AC | 163 ms | 27636 KB |
2_05.txt | AC | 175 ms | 27764 KB |
2_06.txt | AC | 191 ms | 28660 KB |
2_07.txt | AC | 144 ms | 21876 KB |
2_08.txt | AC | 171 ms | 21876 KB |
2_09.txt | AC | 219 ms | 21876 KB |
2_10.txt | AC | 157 ms | 22256 KB |
2_11.txt | AC | 136 ms | 22256 KB |
2_12.txt | AC | 142 ms | 22256 KB |
2_13.txt | AC | 117 ms | 22640 KB |
2_14.txt | AC | 119 ms | 22640 KB |
2_15.txt | AC | 120 ms | 22640 KB |
2_16.txt | AC | 141 ms | 22132 KB |
2_17.txt | AC | 140 ms | 22132 KB |
2_18.txt | AC | 150 ms | 22132 KB |
2_19.txt | AC | 141 ms | 22132 KB |
2_20.txt | AC | 143 ms | 22132 KB |
2_21.txt | AC | 149 ms | 22132 KB |
2_22.txt | AC | 146 ms | 22896 KB |
2_23.txt | AC | 147 ms | 23532 KB |
2_24.txt | AC | 162 ms | 23280 KB |
2_25.txt | AC | 162 ms | 28272 KB |
2_26.txt | AC | 164 ms | 27120 KB |
2_27.txt | AC | 176 ms | 28272 KB |
2_28.txt | AC | 154 ms | 26480 KB |
2_29.txt | AC | 184 ms | 31860 KB |
2_30.txt | AC | 171 ms | 30192 KB |
2_31.txt | AC | 163 ms | 26612 KB |
2_32.txt | AC | 144 ms | 22384 KB |
2_33.txt | AC | 158 ms | 24432 KB |
2_34.txt | AC | 161 ms | 26100 KB |
2_35.txt | AC | 163 ms | 28916 KB |
2_36.txt | AC | 165 ms | 21744 KB |
2_37.txt | AC | 164 ms | 21872 KB |
2_38.txt | AC | 149 ms | 23024 KB |
2_39.txt | AC | 154 ms | 22000 KB |
2_40.txt | AC | 134 ms | 22128 KB |
2_41.txt | AC | 141 ms | 22000 KB |
2_42.txt | AC | 129 ms | 22000 KB |
2_43.txt | AC | 158 ms | 27632 KB |
2_44.txt | AC | 128 ms | 22128 KB |
2_45.txt | AC | 126 ms | 22516 KB |
2_46.txt | AC | 126 ms | 22640 KB |
2_47.txt | AC | 146 ms | 25456 KB |