#include<bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define ii pair<int,int>
#define all(x) (x).begin(),(x).end()
#define INF 100000000000000000
#define modulo 1000000007
#define mod 998244353
#define int long long int
using namespace std;
struct P{
int mx,mn;
void add(int X){
if(X>mx){
mn=mx;
mx=X;
}
else if(X>mn){
mn=X;
}
}
P(int a,int b){
mx=a;
mn=b;
}
};
vector<int>adj[1000005];
vector<int>val(1000005,INF);
vector<P> data(1000005,P(0,0));
int ans=1;
void dfs(int x,int pre){
for(int i=0;i<adj[x].size();i++){
int y=adj[x][i];
if(y==pre)continue;
dfs(y,x);
if(val[x]==1&&val[y]==1)
data[x].add(data[y].mx+1);
}
if(val[x]==1)
ans=max(ans,data[x].mx+data[x].mn+1);
}
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
// freopen("q.gir","r",stdin);
// freopen("q.cik","w",stdout);
int n;
cin>>n;
for(int i=0;i<n-1;i++){
int x,y;
cin>>x>>y;
adj[x].pb(y);
adj[y].pb(x);
}
for(int i=1;i<=n;i++)cin>>val[i];
if(*min_element(all(val))>1){
cout<<*min_element(all(val))<<"/"<<1;
return 0;
}
dfs(1,0);
cout<<1<<"/"<<ans;
}
Compilation message
mag.cpp: In function 'void dfs(long long int, long long int)':
mag.cpp:32:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<adj[x].size();i++){
~^~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
50 ms |
47480 KB |
Output is correct |
2 |
Correct |
46 ms |
47352 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
67 ms |
47356 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
449 ms |
117752 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
48 ms |
47352 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
560 ms |
171328 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
480 ms |
93752 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
867 ms |
98216 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
128 ms |
52472 KB |
Output is correct |
2 |
Incorrect |
540 ms |
94356 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
443 ms |
93236 KB |
Output is correct |
2 |
Incorrect |
494 ms |
95372 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
532 ms |
94736 KB |
Output is correct |
2 |
Correct |
415 ms |
73720 KB |
Output is correct |