답안 #163645

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
163645 2019-11-14T12:59:13 Z quoriess Mag (COCI16_mag) C++14
0 / 120
1915 ms 204984 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;
	}
	dbg(node);
	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";}
	dfs(1,0);
	cout<<1<<"/"<<mx<<"\n";
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 504 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1588 ms 130740 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 380 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1915 ms 204984 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1805 ms 113544 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1799 ms 108652 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 189 ms 10696 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1649 ms 104300 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1892 ms 114864 KB Output isn't correct
2 Halted 0 ms 0 KB -