Submission #77241

# Submission time Handle Problem Language Result Execution time Memory
77241 2018-09-24T08:34:01 Z farukkastamonuda Dynamite (POI11_dyn) C++14
0 / 100
426 ms 35916 KB
#include <bits/stdc++.h>
#define li 300005
#define fi first
#define se second
#define mp make_pair
using namespace std;
int n,m,ok[li],x,y,t,vis[li];
vector<int> v[li];
pair<int,int> say[li],temp;
queue< pair<int,int> > q;
void bfs(){
    while(!q.empty()){
        temp=q.front();
        q.pop();
        int seh=temp.se;
        int cost=temp.fi;
        if(vis[seh]==1) continue;
        vis[seh]=1;
        t-=ok[seh];
        //cout<<seh<<' '<<cost<<endl;
        if(t==0){
            printf("%d\n",cost);
            exit(0);
        }
        for(int i=0;i<(int)v[seh].size();i++){
           // printf("*");
            int go=v[seh][i];
            //cout<<"GO:"<<go<<endl;
            if(vis[go]==1) continue;
            q.push(mp(cost+1,go));
        }
    }
}
int main(){
    scanf("%d %d",&n,&m);
    for(int i=1;i<=n;i++) {scanf("%d",&ok[i]);t+=ok[i];}
    for(int i=1;i<n;i++){
        scanf("%d %d",&x,&y);
        v[x].push_back(y);
        v[y].push_back(x);
        say[x].fi++;
        say[y].fi++;
        say[x].se=x;
        say[y].se=y;
    }
    sort(say+1,say+n+1);
    reverse(say+1,say+n+1);
    for(int i=1;i<=m;i++){
        cout<<say[i].se<<endl;
        q.push(mp(0,say[i].se));
    }
    bfs();
    return 0;
}

Compilation message

dyn.cpp: In function 'int main()':
dyn.cpp:35:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d",&n,&m);
     ~~~~~^~~~~~~~~~~~~~~
dyn.cpp:36:33: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(int i=1;i<=n;i++) {scanf("%d",&ok[i]);t+=ok[i];}
                            ~~~~~^~~~~~~~~~~~~
dyn.cpp:38:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d",&x,&y);
         ~~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 9 ms 7416 KB Output is correct
2 Incorrect 9 ms 7416 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 7456 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 7680 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 7796 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 19 ms 8440 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 49 ms 11420 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 93 ms 15012 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 235 ms 22448 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 376 ms 31556 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 426 ms 35916 KB Output isn't correct
2 Halted 0 ms 0 KB -