Submission #257680

# Submission time Handle Problem Language Result Execution time Memory
257680 2020-08-04T14:35:22 Z igm_igm Mag (COCI16_mag) C++14
60 / 120
635 ms 250744 KB
#include <bits/stdc++.h>
using namespace std;
typedef int64_t llo;
#define mp make_pair
#define pb push_back
#define a first 
#define b second
#define all(x) x.begin(),x.end()
void setIO(string s){
	freopen((s+".in").c_str(),"r",stdin);
	freopen((s+".out").c_str(),"w",stdout);
}

pair<llo,llo> ans;
vector<llo> adj[1000001];
vector<pair<llo,llo>> kk[1000001];
llo it[1000001];
llo dp[1000001];
llo n;
void remin(pair<llo,llo> xx){
	llo yo=__gcd(xx.a,xx.b);
	xx.a/=yo;
	xx.b/=yo;
	if(xx.a*ans.b<xx.b*ans.a){
		ans=xx;
	}
}
void dfs(llo no,llo par=-1,llo co=0){
	co+=1;
	if(it[no]>1){
		co=0;
	}
	llo ma=0;
	for(auto j:adj[no]){
		if(j==par){
			continue;
		}
		dfs(j,no,co);
		ma=max(ma,dp[j]);
		kk[no].pb({dp[j],j});
	}
	sort(all(kk[no]));
	reverse(all(kk[no]));
	llo cc=0;
	for(llo i=0;i<kk[no].size();i++){
		if(i==2){
			break;
		}
		cc+=kk[no][i].a;
	}
	remin({it[no],1+cc});
	if(it[no]==1){
		dp[no]=ma+1;
	}
}
void dfs2(llo no,llo par=-1,llo co=0){
	llo kp=co+1;
	if(kk[no].size()){
		kp+=kk[no][0].a;
	}
	remin({it[no],kp});
	if(it[no]==1){
		co=0;
	}
	else{
		co+=1;
	}
	llo ma=0;
	for(auto j:adj[no]){
		if(j==par){
			continue;
		}
		llo se=0;
		if(it[no]==1){
			se=max(se,co);
			llo su=1;
			for(int i=0;i<2;i++){
				if(i==kk[no].size()){
					break;
				}
				if(kk[no][i].b==j){
					continue;
				}
				su+=kk[no][i].a;
				break;
			}
			se=max(se,su);
		}
		dfs2(j,no,se);
	}


}




int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin>>n;
	for(llo i=0;i<n-1;i++){
		llo aa,bb;
		cin>>aa>>bb;
		aa--;
		bb--;
		adj[aa].pb(bb);
		adj[bb].pb(aa);
	}
	for(llo i=0;i<n;i++){
		cin>>it[i];
	}
	ans={it[0],1};
	dfs(0);
	//dfs2(0);
	cout<<ans.a<<"/"<<ans.b<<endl;



	return 0;
}

Compilation message

mag.cpp: In function 'void dfs(llo, llo, llo)':
mag.cpp:46:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(llo i=0;i<kk[no].size();i++){
              ~^~~~~~~~~~~~~~
mag.cpp: In function 'void dfs2(llo, llo, llo)':
mag.cpp:79:9: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if(i==kk[no].size()){
        ~^~~~~~~~~~~~~~~
mag.cpp:69:6: warning: unused variable 'ma' [-Wunused-variable]
  llo ma=0;
      ^~
mag.cpp: In function 'void setIO(std::__cxx11::string)':
mag.cpp:11:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
  freopen((s+".in").c_str(),"r",stdin);
  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
mag.cpp:12:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
  freopen((s+".out").c_str(),"w",stdout);
  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 28 ms 47352 KB Output is correct
2 Correct 26 ms 47352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 32 ms 47360 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 466 ms 160000 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 29 ms 47360 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 591 ms 245752 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 545 ms 125148 KB Output is correct
2 Correct 437 ms 104788 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 497 ms 122424 KB Output is correct
2 Correct 134 ms 55160 KB Output is correct
3 Incorrect 635 ms 250744 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 119 ms 55288 KB Output is correct
2 Correct 545 ms 126072 KB Output is correct
3 Correct 418 ms 86808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 477 ms 119124 KB Output is correct
2 Correct 498 ms 124024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 527 ms 126576 KB Output is correct
2 Correct 407 ms 86648 KB Output is correct