Submission #167392

#TimeUsernameProblemLanguageResultExecution timeMemory
167392theStaticMindMag (COCI16_mag)C++14
24 / 120
867 ms171328 KiB
#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 (stderr)

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++){
                   ~^~~~~~~~~~~~~~
#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...