Submission #531965

#TimeUsernameProblemLanguageResultExecution timeMemory
531965colazcyMag (COCI16_mag)C++17
24 / 120
493 ms155120 KiB
#include <cstdio> #include <cassert> #include <vector> #include <algorithm> #define let const auto #define rep(name,beg,end) for(auto lim_##name = end,name = beg;name <= lim_##name;name++) #define per(name,beg,end) for(auto lim_##name = end,name = beg;name >= lim_##name;name--) #define repn(lim) for(auto REPN_lIM = lim,REPN = 1;REPN <= REPN_lIM;REPN++) #define debug(...) fprintf(stderr,__VA_ARGS__) #define trace() debug("line : %d, Function : %s\n",__LINE__,__FUNCTION__) using ll = long long; constexpr int maxn = 1e6 + 10; int n,val[maxn],f[maxn],ans; std::vector<int> G[maxn]; void addedge(const int u,const int v){G[u].push_back(v);} void dp(const int u,const int faz = -1){ f[u] = val[u] == 1; for(let v : G[u]){ if(v == faz)continue; dp(v,u); ans = std::max(ans,f[u] + f[v]); if(val[u] == 1)f[u] = std::max(f[u],f[v] + 1); } } int main(){ // std::freopen("mag.in","r",stdin); // std::freopen("mag.out","w",stdout); std::scanf("%d",&n); repn(n - 1){ int u,v; std::scanf("%d %d",&u,&v); addedge(u,v); addedge(v,u); } rep(i,1,n)std::scanf("%d",val + i); if(std::find(val + 1,val + 1 + n,1) == val + 1 + n){ std::printf("%d/1\n",*std::min_element(val + 1,val + 1 + n)); return 0; } dp(1); std::printf("1/%d\n",ans); std::fclose(stdin); std::fclose(stdout); return 0; }

Compilation message (stderr)

mag.cpp: In function 'int main()':
mag.cpp:29:12: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |  std::scanf("%d",&n);
      |  ~~~~~~~~~~^~~~~~~~~
mag.cpp:31:22: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |   int u,v; std::scanf("%d %d",&u,&v);
      |            ~~~~~~~~~~^~~~~~~~~~~~~~~
mag.cpp:35:22: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 |  rep(i,1,n)std::scanf("%d",val + 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...
#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...