제출 #483002

#제출 시각아이디문제언어결과실행 시간메모리
483002MilosMilutinovicThe Xana coup (BOI21_xanadu)C++14
50 / 100
87 ms22220 KiB
#include <bits/stdc++.h> using namespace std; #define rep(i,a,n) for (int i=a;i<n;i++) #define per(i,a,n) for (int i=n-1;i>=a;i--) #define pb push_back #define mp make_pair #define all(x) (x).begin(),(x).end() #define fi first #define se second #define SZ(x) ((int)(x).size()) typedef vector<int> VI; typedef long long ll; typedef pair<int,int> PII; typedef double db; mt19937 mrand(random_device{}()); const ll mod=1000000007; int rnd(int x) { return mrand() % x;} ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;} ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;} // head #define int ll const int N=101000; int n,a[N],dp[N][2][2]; VI g[N]; void dfs(int u,int p) { VI ch; for (int v:g[u]) { if (v==p) continue; dfs(v,u); ch.pb(v); } if (ch.empty()) { if (a[u]==0) dp[u][0][0]=0,dp[u][1][1]=1; else dp[u][1][0]=1,dp[u][0][1]=0; } else { rep(x,0,2) rep(y,0,2) { int st=(a[u]+x+y)%2; if (st==0) { int totx=0,toty=0; for (int v:ch) totx+=dp[v][0][x]; for (int v:ch) toty+=dp[v][1][x]; dp[u][x][y]=totx+x; if (SZ(ch)%2==0) dp[u][x][y]=min(dp[u][x][y],toty+x); } else { for (int v:ch) { int tot=dp[v][1][x]; for (int h:ch) if (h!=v) tot+=dp[h][0][x]; dp[u][x][y]=min(dp[u][x][y],tot+x); } } } } } signed main() { scanf("%lld",&n); rep(i,0,n-1) { int u,v; scanf("%lld%lld",&u,&v); g[u].pb(v); g[v].pb(u); } int root=1; rep(i,1,n+1) if (SZ(g[i])<=SZ(g[root])) root=i; rep(i,1,n+1) scanf("%lld",a+i); rep(i,1,n+1) rep(x,0,2) rep(y,0,2) dp[i][x][y]=1e9; dfs(root,0); // rep(i,1,n+1) { // rep(x,0,2) rep(y,0,2) printf("i:%d x:%d y:%d dp:%d\n",i,x,y,dp[i][x][y]); // } int ans=min(dp[root][1][0],dp[root][0][0]); if (ans>=1e9) printf("impossible"); else printf("%lld\n",ans); }

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

xanadu.cpp: In function 'int main()':
xanadu.cpp:56:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   56 |  scanf("%lld",&n);
      |  ~~~~~^~~~~~~~~~~
xanadu.cpp:59:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   59 |   scanf("%lld%lld",&u,&v);
      |   ~~~~~^~~~~~~~~~~~~~~~~~
xanadu.cpp:65:20: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   65 |  rep(i,1,n+1) scanf("%lld",a+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...