Submission #346035

# Submission time Handle Problem Language Result Execution time Memory
346035 2021-01-09T04:07:25 Z Pichon5 Birmingham (COCI20_birmingham) C++17
70 / 70
211 ms 11240 KB
#include<bits/stdc++.h>
#define lcm(a,b) (a/__gcd(a,b))*b
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define pb push_back
#define F first
#define S second
#define mp make_pair
//salida rapida "\n"
//DECIMALES fixed<<sp(n)<<x<<endl;
//gcd(a,b)= ax + by
//lCB x&-x
//set.erase(it) - ersases the element present at the required index//auto it = s.find(element)
//set.find(element) - iterator pointing to the given element if it is present else return pointer pointing to set.end()
//set.lower_bound(element) - iterator pointing to element greater than or equal to the given element
//set.upper_bound(element) - iterator pointing to element greater than the given element
// | ^
//stoll string to long long
using namespace std;
int n,m,q,k,x,a,b;
vector<vi>G;
int main()
{
    cin>>n>>m>>q>>k;
    queue<int>Q;
    vi dis(n+1,-1);
    while(q--){
        cin>>x;
        Q.push(x);
        dis[x]=0;
    }
    G.assign(n+1,vi());
    for(int i=0;i<m;i++){
        cin>>a>>b;
        G[a].pb(b);
        G[b].pb(a);
    }
    while(!Q.empty()){
        int u = Q.front();
        Q.pop();
        for(auto it : G[u]){
            if(dis[it]!=-1){
                continue;
            }
            dis[it]=dis[u]+1;
            Q.push(it);
        }
    }
    vll aux;
    ll K=k;
    aux.pb(k);
    for(int i=2;i<=n;i++){
        K+=k*i;
        aux.pb(K);
    }
    /*for(int i=1;i<=n;i++){
        cout<<dis[i]<<" . ";
    }*/
    for(int i=1;i<=n;i++){
        if(dis[i]==0){
            cout<<0<<" ";
            continue;
        }
        int b=0,e=n-1,res;
        while(b<=e){
            int mid=(b+e)/2;
            if(aux[mid]>=dis[i]){
                res=mid+1;
                e=mid-1;
            }else{
                b=mid+1;
            }
        }
        cout<<res<<" ";
    }

    
    return 0;
}

Compilation message

birmingham.cpp: In function 'int main()':
birmingham.cpp:76:20: warning: 'res' may be used uninitialized in this function [-Wmaybe-uninitialized]
   76 |         cout<<res<<" ";
      |                    ^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 183 ms 10468 KB Output is correct
2 Correct 196 ms 10852 KB Output is correct
3 Correct 208 ms 11108 KB Output is correct
4 Correct 157 ms 9828 KB Output is correct
5 Correct 164 ms 10084 KB Output is correct
6 Correct 204 ms 11108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 198 ms 10980 KB Output is correct
2 Correct 190 ms 10596 KB Output is correct
3 Correct 200 ms 10888 KB Output is correct
4 Correct 204 ms 10980 KB Output is correct
5 Correct 191 ms 10596 KB Output is correct
6 Correct 179 ms 10340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 183 ms 10468 KB Output is correct
2 Correct 201 ms 10852 KB Output is correct
3 Correct 205 ms 11236 KB Output is correct
4 Correct 196 ms 10980 KB Output is correct
5 Correct 173 ms 10280 KB Output is correct
6 Correct 186 ms 10596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 163 ms 10152 KB Output is correct
2 Correct 193 ms 10596 KB Output is correct
3 Correct 199 ms 11048 KB Output is correct
4 Correct 178 ms 10340 KB Output is correct
5 Correct 176 ms 9992 KB Output is correct
6 Correct 177 ms 10468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 167 ms 10212 KB Output is correct
2 Correct 183 ms 10596 KB Output is correct
3 Correct 183 ms 10536 KB Output is correct
4 Correct 172 ms 10408 KB Output is correct
5 Correct 181 ms 10312 KB Output is correct
6 Correct 176 ms 10344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 173 ms 10084 KB Output is correct
2 Correct 181 ms 10340 KB Output is correct
3 Correct 172 ms 10212 KB Output is correct
4 Correct 187 ms 10596 KB Output is correct
5 Correct 173 ms 10212 KB Output is correct
6 Correct 180 ms 10468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 178 ms 10280 KB Output is correct
2 Correct 166 ms 9828 KB Output is correct
3 Correct 207 ms 11144 KB Output is correct
4 Correct 173 ms 10084 KB Output is correct
5 Correct 184 ms 10376 KB Output is correct
6 Correct 211 ms 11240 KB Output is correct