Submission #163650

# Submission time Handle Problem Language Result Execution time Memory
163650 2019-11-14T13:04:22 Z quoriess Mag (COCI16_mag) C++14
24 / 120
1747 ms 160764 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;
	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);
	}
	if(dizi[node]==1){
		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;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 248 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1374 ms 94260 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1747 ms 160764 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 1560 ms 70392 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1679 ms 72644 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 182 ms 8056 KB Output is correct
2 Incorrect 1581 ms 71024 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1493 ms 66236 KB Output is correct
2 Incorrect 1627 ms 69624 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 1590 ms 71556 KB Output is correct
2 Correct 985 ms 38688 KB Output is correct