답안 #208272

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
208272 2020-03-10T13:07:14 Z rzbt Zagrade (COI17_zagrade) C++14
0 / 100
10 ms 5880 KB
#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

zagrade.cpp: In function 'int main()':
zagrade.cpp:63:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
zagrade.cpp:64:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%s",s);
     ~~~~~^~~~~~~~
zagrade.cpp:69:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d", &t1, &t2);
         ~~~~~^~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 7 ms 2808 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 10 ms 5880 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 7 ms 2808 KB Output isn't correct
2 Halted 0 ms 0 KB -