# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
370084 |
2021-02-23T08:04:34 Z |
maozkurt |
Mag (COCI16_mag) |
C++17 |
|
4000 ms |
93420 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 = 2e9;
vector<int> adj[maxn];
int magic[maxn];
int p[maxn];
int depth[maxn];
int dfs1(int v, int s){
int ret = v;
for(int i : adj[v]){
if(magic[i] == 1 && p[i] != s){
p[i] = s;
depth[i] = depth[v] + 1;
int a = dfs1(i,s);
if(depth[a] >= depth[ret]){
ret = a;
}
}
}
return ret;
}
int dfs3(int s){
int maxx = -1, iki = -1;
int cnt = 0;
for(int i : adj[s]){
if(magic[i] == 1)
cnt++;
}
if(cnt < 2)
return -1;
for(int i : adj[s]){
if(magic[i] == 1){
p[i] = s;
depth[i] = 1;
int cur = depth[dfs1(i,s)];
if(cur>maxx){
iki = maxx;
maxx = cur;
}
else if(cur>iki){
iki = cur;
}
}
}
return (iki==-1 ? -1 : maxx + iki + 1);
}
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;
for(int i=1;i<=n;i++){
cin>>magic[i];
minn = min(minn,magic[i]);
}
if(minn > 1){
cout << minn << '/' << 1 << endl;
exit(0);
}
int maxbir = 0;
for(int i=1;i<=n;i++){
if(magic[i]==1 && p[i] == 0){
p[i] = i;
int cur = dfs1(i,i);
if(cur==i){
maxbir = max(maxbir,1);
}
else{
p[cur] = cur;
depth[cur] = 1;
maxbir = depth[dfs1(cur,cur)];
}
}
}
int maxiki = 0;
for(int i=1;i<=n;i++){
if(magic[i] == 2){
int cur = dfs3(i);
maxiki = max(maxiki, cur);
}
}
if(2*maxbir >= maxiki){
cout << 1 << '/' << maxbir << endl;
}
else{
int sol = 2;
if(maxiki % 2 == 0){
sol=1;
maxiki/=2;
}
cout << sol << '/' << maxiki << endl;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
24044 KB |
Output is correct |
2 |
Incorrect |
17 ms |
23916 KB |
Output isn't 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 |
436 ms |
93420 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
23936 KB |
Output is correct |
2 |
Incorrect |
408 ms |
70252 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
467 ms |
67564 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
422 ms |
70380 KB |
Output is correct |
2 |
Incorrect |
337 ms |
59372 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
378 ms |
68060 KB |
Output is correct |
2 |
Incorrect |
295 ms |
30060 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4067 ms |
29548 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
385 ms |
68124 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1259 ms |
70976 KB |
Output is correct |
2 |
Correct |
489 ms |
50740 KB |
Output is correct |