제출 #414757

#제출 시각아이디문제언어결과실행 시간메모리
414757juggernautThe Xana coup (BOI21_xanadu)C++17
10 / 100
107 ms16808 KiB
#include<bits/stdc++.h> #define fr first #define sc second using namespace std; void usaco(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);} typedef long long ll; #define USING_ORDERED_SET 0 #if USING_ORDERED_SET #include<bits/extc++.h> using namespace __gnu_pbds; template<class T>using ordered_set=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>; #endif template<class T>void umax(T &a,T b){if(a<b)a=b;} template<class T>void umin(T &a,T b){if(b<a)a=b;} #ifdef IOI2021SG #define printl(args...)printf(args) #else #define printl(args...)((void)0) #endif int a[100005],n; vector<int>g[100005]; int dp[100005][2][2]; void dfs(int v,int p){ dp[v][0][0]=2e5; dp[v][0][1]=2e5; dp[v][1][0]=2e5; dp[v][1][1]=2e5; for(int to:g[v])if(to!=p)dfs(to,v); int sz=g[v].size(); if(v^p)sz--; int x; for(int to:g[v])if(to!=p)x=to; int y; for(int to:g[v])if(to!=p&&to!=x)y=to; if(sz==0){ if(a[v]==0){ dp[v][0][0]=0; dp[v][0][1]; dp[v][1][0]; dp[v][1][1]=1; }else{ dp[v][0][0]; dp[v][0][1]=0; dp[v][1][0]=1; dp[v][1][1]; } }else if(sz==1){ if(a[v]==0){ dp[v][0][0]=dp[x][0][0]; dp[v][0][1]=dp[x][1][0]; dp[v][1][0]=dp[x][1][1]+1; dp[v][1][1]=dp[x][0][1]+1; }else{ dp[v][0][0]=dp[x][1][0]; dp[v][0][1]=dp[x][0][0]; dp[v][1][0]=dp[x][0][1]+1; dp[v][1][1]=dp[x][1][1]+1; } } } int main(){ scanf("%d",&n); for(int i=1,x,y;i<n;i++){ scanf("%d%d",&x,&y); g[x].push_back(y); g[y].push_back(x); } int root; for(int i=1;i<=n;i++)if(g[i].size()==1)root=i; for(int i=1;i<=n;i++)scanf("%d",&a[i]); dfs(root,root); int x=min(dp[root][1][0],dp[root][0][0]); if(x>=int(2e5))puts("impossible"); else printf("%d",x); }

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

xanadu.cpp: In function 'void dfs(int, int)':
xanadu.cpp:38:23: warning: statement has no effect [-Wunused-value]
   38 |             dp[v][0][1];
      |             ~~~~~~~~~~^
xanadu.cpp:39:23: warning: statement has no effect [-Wunused-value]
   39 |             dp[v][1][0];
      |             ~~~~~~~~~~^
xanadu.cpp:42:23: warning: statement has no effect [-Wunused-value]
   42 |             dp[v][0][0];
      |             ~~~~~~~~~~^
xanadu.cpp:45:23: warning: statement has no effect [-Wunused-value]
   45 |             dp[v][1][1];
      |             ~~~~~~~~~~^
xanadu.cpp:33:9: warning: variable 'y' set but not used [-Wunused-but-set-variable]
   33 |     int y;
      |         ^
xanadu.cpp: In function 'void usaco(std::string)':
xanadu.cpp:5:29: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | void usaco(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);}
      |                      ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
xanadu.cpp:5:66: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    5 | void usaco(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);}
      |                                                           ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
xanadu.cpp: In function 'int main()':
xanadu.cpp:62:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   62 |     scanf("%d",&n);
      |     ~~~~~^~~~~~~~~
xanadu.cpp:64:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   64 |         scanf("%d%d",&x,&y);
      |         ~~~~~^~~~~~~~~~~~~~
xanadu.cpp:70:31: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   70 |     for(int i=1;i<=n;i++)scanf("%d",&a[i]);
      |                          ~~~~~^~~~~~~~~~~~
xanadu.cpp: In function 'void dfs(int, int)':
xanadu.cpp:52:35: warning: 'x' may be used uninitialized in this function [-Wmaybe-uninitialized]
   52 |             dp[v][1][1]=dp[x][0][1]+1;
      |                         ~~~~~~~~~~^
#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...