제출 #604718

#제출 시각아이디문제언어결과실행 시간메모리
604718krit3379The Xana coup (BOI21_xanadu)C++17
100 / 100
99 ms23436 KiB
#include<bits/stdc++.h> using namespace std; #pragma GCC optimize("O3,unroll-loops") #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") #define N 100005 long long st[N],dp[2][2][N],ans; // good/bad not pass/pass vector<int> gr[N]; void upd(long long &x,long long &v0,long long &v1,long long &s,long long &m){ x+=min(v0,v1); s^=v0<=v1?0:1; m=min(m,abs(v0-v1)); } void dfs(int s,int f){ long long b=0,g=0,sb=0,sg=0,mb=1e9,mg=1e9; for(auto x:gr[s]){ if(x==f)continue; dfs(x,s); upd(b,dp[1][0][x],dp[1][1][x],sb,mb); upd(g,dp[0][0][x],dp[0][1][x],sg,mg); } dp[sg^st[s]][0][s]=min(g,dp[sg^st[s]][0][s]); dp[sg^st[s]^1][0][s]=min(g+mg,dp[sg^st[s]^1][0][s]); dp[sb^st[s]^1][1][s]=min(b+1,dp[sb^st[s]^1][1][s]); dp[sb^st[s]][1][s]=min(b+mb+1,dp[sb^st[s]][1][s]); } int main(){ int n,i,j,k,a,b; scanf("%d",&n); for(i=1;i<n;i++){ scanf("%d %d",&a,&b); gr[a].push_back(b); gr[b].push_back(a); } for(i=0;i<2;i++)for(j=0;j<2;j++)for(k=1;k<=n;k++)dp[i][j][k]=1e9; for(i=1;i<=n;i++)scanf("%lld",&st[i]); dfs(1,0); if(min(dp[0][0][1],dp[0][1][1])<1e9)printf("%lld",min(dp[0][0][1],dp[0][1][1])); else printf("impossible"); return 0; }

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

xanadu.cpp: In function 'int main()':
xanadu.cpp:33:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |     scanf("%d",&n);
      |     ~~~~~^~~~~~~~~
xanadu.cpp:35:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 |         scanf("%d %d",&a,&b);
      |         ~~~~~^~~~~~~~~~~~~~~
xanadu.cpp:40:27: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |     for(i=1;i<=n;i++)scanf("%lld",&st[i]);
      |                      ~~~~~^~~~~~~~~~~~~~~
#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...