답안 #531965

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
531965 2022-03-02T01:54:08 Z colazcy Mag (COCI16_mag) C++17
24 / 120
493 ms 155120 KB
#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

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);
      |            ~~~~~~~~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 23756 KB Output is correct
2 Correct 14 ms 23776 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 17 ms 23776 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 344 ms 100132 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 14 ms 23756 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 493 ms 155120 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 415 ms 77876 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 447 ms 81004 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 69 ms 29136 KB Output is correct
2 Incorrect 412 ms 78528 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 379 ms 76356 KB Output is correct
2 Incorrect 401 ms 79124 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 479 ms 78772 KB Output is correct
2 Correct 379 ms 51392 KB Output is correct