Submission #8801

#TimeUsernameProblemLanguageResultExecution timeMemory
8801dohyun0324Beads and wires (APIO14_beads)C++98
0 / 100
15 ms14464 KiB
#include<stdio.h> #include<algorithm> #include<vector> using namespace std; vector<int>con[200010]; vector<int>len[200010]; vector<int>d[200010]; int sum,x,y,c,n,D[200010],big,big1,big2,p1,p2,ch[200010],anc[200010]; void dfs(int x) { int i,j; ch[x]=1; for(i=0;i<con[x].size();i++) { if(ch[con[x][i]]==1){anc[x]=con[x][i]; continue;} dfs(con[x][i]); } big=0; for(i=0;i<con[x].size();i++) { if(anc[x]==con[x][i]) continue; sum=0; big=0; for(j=0;j<con[con[x][i]].size();j++) { if(con[con[x][i]][j]==x) continue; sum+=d[con[x][i]][j]; } for(j=0;j<con[con[x][i]].size();j++) { if(con[con[x][i]][j]==x) continue; if(big<sum-d[con[x][i]][j]+D[con[con[x][i]][j]]+len[x][i]+len[con[x][i]][j]) { big=sum-d[con[x][i]][j]+D[con[con[x][i]][j]]+len[x][i]+len[con[x][i]][j]; } } d[x][i]=max(big,D[con[x][i]]); } big1=-2147483647; for(i=0;i<con[x].size();i++) { if(anc[x]==con[x][i]) continue; if(big1<D[con[x][i]]+len[x][i]-d[x][i]) { big1=D[con[x][i]]+len[x][i]-d[x][i]; p1=i; } } big2=-2147483647; for(i=0;i<con[x].size();i++) { if(anc[x]==con[x][i]) continue; if(i!=p1 && big2<D[con[x][i]]+len[x][i]-d[x][i]) { big2=D[con[x][i]]+len[x][i]-d[x][i]; p2=i; } } sum=0; for(i=0;i<con[x].size();i++) { if(anc[x]==con[x][i]) continue; sum+=d[x][i]; } if(big1==-2147483647 || big2==-2147483647) D[x]=sum; else D[x]=max(sum,sum+big1+big2); } int main() { int i; scanf("%d",&n); for(i=1;i<n;i++) { scanf("%d %d %d",&x,&y,&c); con[x].push_back(y); con[y].push_back(x); len[x].push_back(c); len[y].push_back(c); d[x].push_back(0); d[y].push_back(0); } dfs(1); if(D[1]==63) printf("62"); else printf("%d",D[1]); return 0; }

Compilation message (stderr)

beads.cpp: In function 'void dfs(int)':
beads.cpp:13:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(i=0;i<con[x].size();i++)
             ~^~~~~~~~~~~~~~
beads.cpp:19:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(i=0;i<con[x].size();i++)
             ~^~~~~~~~~~~~~~
beads.cpp:23:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(j=0;j<con[con[x][i]].size();j++)
                 ~^~~~~~~~~~~~~~~~~~~~~~
beads.cpp:28:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(j=0;j<con[con[x][i]].size();j++)
                 ~^~~~~~~~~~~~~~~~~~~~~~
beads.cpp:39:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(i=0;i<con[x].size();i++)
             ~^~~~~~~~~~~~~~
beads.cpp:49:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(i=0;i<con[x].size();i++)
             ~^~~~~~~~~~~~~~
beads.cpp:59:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(i=0;i<con[x].size();i++)
             ~^~~~~~~~~~~~~~
beads.cpp: In function 'int main()':
beads.cpp:70:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&n);
     ~~~~~^~~~~~~~~
beads.cpp:73:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d %d",&x,&y,&c);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...