# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
369771 |
2021-02-22T11:47:00 Z |
maozkurt |
Mag (COCI16_mag) |
C++17 |
|
4000 ms |
94060 KB |
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <string>
#include <stack>
#include <numeric>
#include <cassert>
#define endl '\n'
#define sp ' '
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int maxn = 1e6+5;
const int inf = 1e9;
vector<int> adj[maxn];
int magic[maxn];
int visited[maxn];
int dfs1(int v, int s){
int ret = 1;
for(int i : adj[v]){
if(magic[i] == 1 && visited[i]!=s){
visited[i] = s;
ret = max(ret,dfs1(i,s)+1);
}
}
return ret;
}
int main(){
ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);cerr.tie(nullptr);
int n;cin>>n;
for(int i=0;i<n-1;i++){
int a,b;cin>>a>>b;
adj[a].pb(b);
adj[b].pb(a);
}
int minn = inf;
vector<int> iki;
for(int i=1;i<=n;i++){
cin>>magic[i];
minn = min(minn, magic[i]);
if(magic[i] == 2)
iki.pb(i);
}
if(minn != 1){
cout << minn << '/' << 1 << endl;
exit(0);
}
int ikimaxx = 0;
for(int i : iki){
int birmaxx = -1;
int biriki = -1;
for(int v : adj[i]){
if(magic[v] == 1){
visited[v] = i;
int cur = dfs1(v,i);
if(cur>birmaxx){
biriki = birmaxx;
birmaxx = cur;
}
else if(cur>biriki){
biriki = cur;
}
}
}
//cerr << i << sp << biriki << sp << birmaxx << endl;
if(birmaxx != -1 && biriki != -1){
ikimaxx = max(ikimaxx, birmaxx + biriki);
}
}
int maxx = 0;
for(int i=1;i<=n;i++){
if(visited[i]!=-1 && magic[i] == 1){
visited[i] = -1;
maxx = max(maxx, dfs1(i,-1));
}
}
if(2*maxx >= ikimaxx+1){
cout << 1 << '/' << maxx << endl;
}
else{
cout << ((ikimaxx+1)%2==0 ? 1 : 2) << '/' << ((ikimaxx+1)%2==0?(ikimaxx+1)/2:ikimaxx+1) << endl;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
23916 KB |
Output is correct |
2 |
Correct |
17 ms |
23916 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
23916 KB |
Output is correct |
2 |
Correct |
17 ms |
23916 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
385 ms |
94060 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
23788 KB |
Output is correct |
2 |
Correct |
409 ms |
80092 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
445 ms |
80152 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
398 ms |
78188 KB |
Output is correct |
2 |
Correct |
309 ms |
63596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
390 ms |
82632 KB |
Output is correct |
2 |
Incorrect |
384 ms |
29548 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4048 ms |
29292 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
375 ms |
76708 KB |
Output is correct |
2 |
Correct |
404 ms |
79676 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1073 ms |
78760 KB |
Output is correct |
2 |
Incorrect |
390 ms |
51632 KB |
Output isn't correct |