제출 #376226

#제출 시각아이디문제언어결과실행 시간메모리
376226daniel920712Designated Cities (JOI19_designated_cities)C++14
6 / 100
499 ms66028 KiB
#include <iostream> #include <stdio.h> #include <stdlib.h> #include <vector> #include <map> #include <set> using namespace std; vector < pair < long long , long long > > Next[200005]; map < long long , long long > all[200005]; set < long long > vis[200005]; long long ans[200005]; long long xx[200005]; long long DP[5][200005]; void F(long long here,long long fa) { for(auto i:Next[here]) { if(i.first!=fa) { ans[1]+=i.second; F(i.first,here); } } } void F2(long long here,long long fa) { for(auto i:Next[here]) { if(i.first!=fa) { F2(i.first,here); } } } void F3(long long here,long long fa) { for(auto i:Next[here]) { if(i.first!=fa) { vis[here].insert(i.first); F3(i.first,here); } } } void F4(long long here,long long fa) { long long x=1e18,y=0,z,tt; for(auto i:Next[here]) if(i.first!=fa) F4(i.first,here); DP[0][here]=1e18; DP[1][here]=1e18; DP[2][here]=1e18; for(auto i:Next[here]) { if(i.first!=fa) { DP[0][here]+=DP[0][i.first]; DP[0][here]+=all[here][i.first]; } } DP[1][here]=DP[0][here]; y=0; for(auto i:Next[here]) { if(i.first!=fa) { x=min(x,0-DP[0][i.first]-all[here][i.first]+DP[1][i.first]); y+=DP[0][i.first]+all[here][i.first]; } } DP[2][here]=DP[0][here]+x; DP[1][here]=min(DP[1][here],y+x); x=1e18; y=0; for(auto i:Next[here]) { if(i.first!=fa) { x=min(x,0-DP[0][i.first]-all[here][i.first]+DP[2][i.first]+all[here][i.first]); y+=DP[0][i.first]+all[here][i.first]; } } DP[2][here]=min(DP[2][here],y+x); x=1e18; y=0; z=1e18; for(auto i:Next[here]) { if(i.first!=fa) { tt=0-DP[0][i.first]-all[here][i.first]+DP[2][i.first]+all[here][i.first]; if(tt<x) { z=x; x=tt; } else if(tt<z) { z=tt; } y+=DP[0][i.first]+all[here][i.first]; } } DP[2][here]=min(DP[2][here],y+x+z); //for(auto i:Next[here]) if(i.first!=fa) x=min(x,0-DP[0][i.first]-all[here][i.first]+DP[1][i.first]); } int main() { long long N,M,i,j,k,a,b,c,d,how=1e18; scanf("%lld",&N); for(i=1;i<N;i++) { scanf("%lld %lld %lld %lld",&a,&b,&c,&d); Next[a].push_back(make_pair(b,c)); Next[b].push_back(make_pair(a,d)); all[a][b]=c; all[b][a]=d; } for(i=1;i<=N;i++) xx[i]=1e18; if(N<=16) { for(i=0;i<(1<<N);i++) { a=0; b=0; for(j=1;j<=N;j++) vis[j].clear(); for(j=0;j<N;j++) { if(i&(1<<j)) { F3(j+1,-1); a++; } } for(j=1;j<=N;j++) for(auto k:Next[j]) if(vis[j].find(k.first)==vis[j].end()) b+=all[k.first][j]; xx[a]=min(xx[a],b); } scanf("%lld",&M); while(M--) { scanf("%lld",&a); printf("%lld\n",xx[a]); } } else { scanf("%d %d",&a,&b); if(b==1) { F(1,-1); F2(1,-1); for(i=1;i<=N;i++) { how=min(how,ans[i]); } printf("%lld\n",how); } else { F4(1,-1); printf("%lld\n",DP[2][1]); } } return 0; }

컴파일 시 표준 에러 (stderr) 메시지

designated_cities.cpp: In function 'int main()':
designated_cities.cpp:157:17: warning: format '%d' expects argument of type 'int*', but argument 2 has type 'long long int*' [-Wformat=]
  157 |         scanf("%d %d",&a,&b);
      |                ~^     ~~
      |                 |     |
      |                 int*  long long int*
      |                %lld
designated_cities.cpp:157:20: warning: format '%d' expects argument of type 'int*', but argument 3 has type 'long long int*' [-Wformat=]
  157 |         scanf("%d %d",&a,&b);
      |                   ~^     ~~
      |                    |     |
      |                    int*  long long int*
      |                   %lld
designated_cities.cpp:117:23: warning: unused variable 'k' [-Wunused-variable]
  117 |     long long N,M,i,j,k,a,b,c,d,how=1e18;
      |                       ^
designated_cities.cpp:118:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  118 |     scanf("%lld",&N);
      |     ~~~~~^~~~~~~~~~~
designated_cities.cpp:123:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  123 |         scanf("%lld %lld %lld %lld",&a,&b,&c,&d);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
designated_cities.cpp:148:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  148 |         scanf("%lld",&M);
      |         ~~~~~^~~~~~~~~~~
designated_cities.cpp:151:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  151 |             scanf("%lld",&a);
      |             ~~~~~^~~~~~~~~~~
designated_cities.cpp:157:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  157 |         scanf("%d %d",&a,&b);
      |         ~~~~~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...