답안 #163646

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
163646 2019-11-14T13:00:20 Z quoriess Mag (COCI16_mag) C++14
24 / 120
1841 ms 160632 KB
#include <bits/stdc++.h>
#include <unistd.h>
using namespace std;
typedef long long int lli;
typedef pair<lli, lli> pii;
#define dbg(x) cout << #x << " has a value of: " << x << "\n";
#define usize(x) (int)(x.size())
#define plist(x)                       \
    for (int i = 0; i < usize(x); i++) \
        cout << "eleman " << i << " = " << x[i] << "\n";
#define foreach(x) for (auto item : x)
#define fill(s, x)              \
    for (int i = 0; i < x; i++) \
        cin >> s[i];
#define in(veriler, a) (veriler.find(a) != veriler.end())
#define btw(x, y, z) x >= y&& x <= z;
std::ostream& operator<<(std::ostream& os, pair<int,int> p) {
    os << p.first << ", " << p.second;
    return os;
}
#ifdef ONLINE_JUDGE
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);
#else
#define fio //a
#endif
vector<lli> dizi;
vector<vector<lli> > adj;
vector<lli> dzp;
lli mx=-1;
void dfs(int node,int parent){
	lli mx1=0,mx2=0;
	if(adj[node].size()==1&&adj[node][0]==parent){
		if(dizi[node]==1)dzp[node]=1;
		else dzp[node]=0;
		return;
	}
	foreach(adj[node]){
		if(item==parent)continue;
		dfs(item,node);
		if(dizi[node]!=1)continue;
		if(dizi[item]!=1)continue;
		if(dzp[item]>mx1){
			mx2=mx1;
			mx1=dzp[item];
		}
		else if(dzp[item]>mx2){
			mx2=dzp[item];
		}
	//	dbg(mx1);
	//	dbg(mx2);
	}
	dzp[node]=mx1+1;
	mx=max(mx1+1+mx2,mx);
}
int main() {
	int n;
	cin>>n;
	adj=vector<vector<lli> >(n+1);
	dizi=dzp=vector<lli>(n+1);
	for(int i=0;i<n-1;i++){
		int a,b;
		cin>>a>>b;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
	bool b1=0;
	lli mn=1e9;
	for(int i=0;i<n;i++){
		cin>>dizi[i+1];
		if(dizi[i+1]==1)b1=1;
		mn=min(mn,dizi[i+1]);
	}
	if(!b1){cout<<mn<<"/"<<1<<"\n";return 0;}
	dfs(1,0);
	cout<<1<<"/"<<mx<<"\n";
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1393 ms 94420 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1760 ms 160632 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1567 ms 70396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1638 ms 72748 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 177 ms 7980 KB Output is correct
2 Incorrect 1572 ms 86364 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1487 ms 66256 KB Output is correct
2 Incorrect 1631 ms 86656 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1841 ms 71564 KB Output is correct
2 Correct 955 ms 46188 KB Output is correct