# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
208272 | rzbt | Zagrade (COI17_zagrade) | C++14 | 10 ms | 5880 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define F first
#define S second
#define MAXN 100005
using namespace std;
int n;
char s[MAXN];
int zagrada[MAXN];
vector<int> niz[MAXN];
int obradjen[MAXN];
int podst[MAXN];
int cale[MAXN];
int dfsV(int t,int o){
podst[t]=1;
cale[t]=o;
for(auto x:niz[t])
if(x!=o && !obradjen[x])
podst[t]+=dfsV(x,t);
return podst[t];
}
void centroidna(int c){
dfsV(c,0);
int vel=podst[c];
if(vel==1){
printf(" jedan %d\n",c);
obradjen[c]=true;
return;
}
while(22){
bool naso=false;
for(auto x:niz[c]){
if(obradjen[x] || x==cale[c])continue;
if(podst[x]>(vel>>1)){
c=x;
naso=true;
break;
}
}
if(!naso)break;
}
/// OVDE IDE OBRADA
///OVDE JE KRAJ OVRADE
printf(" vise %d\n",c);
obradjen[c]=true;
for(auto x:niz[c]){
if(!obradjen[x])centroidna(x);
}
}
int main()
{
scanf("%d", &n);
scanf("%s",s);
for(int i=1;i<=n;i++)
zagrada[i]=(s[i-1]=='('?1:-1);
for(int i=1;i<n;i++){
int t1,t2;
scanf("%d %d", &t1, &t2);
niz[t1].pb(t2);
niz[t2].pb(t1);
}
centroidna(1);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |