Submission #1046125

# Submission time Handle Problem Language Result Execution time Memory
1046125 2024-08-06T10:21:12 Z ivopav Shymbulak (IZhO14_shymbulak) C++17
50 / 100
1500 ms 8456 KB
#include <bits/stdc++.h>
using namespace std;

#pragma GCC optimize("Ofast","unroll-loops")
 

struct bfstyp{
    int ind;
    int val;
};

void prim(int poc,int n,vector<vector<int>>& gra,int& najv,int& najvkol){
    vector<int> dist(n,-1);
    dist[poc]=0;
    queue<bfstyp> bfslis={};
    bfslis.push(bfstyp{poc,0});
    int najv2=0;
    while (bfslis.size()>0){
        int ind=bfslis.front().ind;
        int val=bfslis.front().val;
        najv2=max(najv2,val);
     //`   cout << ind << "\n";
        bfslis.pop();
        for (int i=0;i<gra[ind].size();i++){
        //    cout << i << "\n";
            int ind2=gra[ind][i];
            if (dist[ind2]!=-1){
                continue;
            }
            dist[ind2]=val+1;
            bfslis.push(bfstyp{ind2,val+1});
        }
    }
    vector<vector<int>> lispom(najv2+3,vector<int>{});
  //  cout << "\n";
    for (int i=0;i<n;i++){
    //    cout << dist[i] << "\n";
        lispom[dist[i]].push_back(i);
        //lis.push_back({dist[i],i});
    }
    vector<pair<int,int>> lis={};
    for (int i=0;i<najv2+3;i++){
        for (int j=0;j<lispom[i].size();j++){
            lis.push_back({i,lispom[i][j]});
        }
    }
   // cout << "\n";
    //sort(lis.begin(),lis.end());
    vector<int> dp(n,0);
    dp[poc]=1;
    for (int i=0;i<n;i++){
        int ind=lis[i].second;
        if (dp[ind]==0){
            continue;
        }
        for (int j=0;j<gra[ind].size();j++){
            int ind2=gra[ind][j];
            if (dist[ind2]==dist[ind]+1){
                dp[ind2]+=dp[ind];
                if (dist[ind2]==najv){
                    najvkol+=dp[ind];
                }
                else if (najv<dist[ind2]){
                    najv=dist[ind2];
                    najvkol=dp[ind];
                }
            }
        }
    }
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    vector<vector<int>>  gra(n,vector<int>{}); 
    for (int i=0;i<n;i++){
        int unos;
        int unos2;
        cin >> unos >> unos2;
        gra[--unos].push_back(--unos2);
        gra[unos2].push_back(unos);    
    }
    int najv=0;
    int najvkol=0;
    for (int i=0;i<n;i++){
        prim(i,n,gra,najv,najvkol);
    }
   // cout << najv << "\n";
    cout << najvkol/2 << "\n";
}

Compilation message

shymbulak.cpp: In function 'void prim(int, int, std::vector<std::vector<int> >&, int&, int&)':
shymbulak.cpp:24:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |         for (int i=0;i<gra[ind].size();i++){
      |                      ~^~~~~~~~~~~~~~~~
shymbulak.cpp:43:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |         for (int j=0;j<lispom[i].size();j++){
      |                      ~^~~~~~~~~~~~~~~~~
shymbulak.cpp:56:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |         for (int j=0;j<gra[ind].size();j++){
      |                      ~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 8 ms 348 KB Output is correct
15 Correct 13 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 344 KB Output is correct
2 Correct 14 ms 540 KB Output is correct
3 Correct 47 ms 348 KB Output is correct
4 Correct 30 ms 344 KB Output is correct
5 Correct 806 ms 916 KB Output is correct
6 Correct 667 ms 1104 KB Output is correct
7 Correct 888 ms 964 KB Output is correct
8 Correct 870 ms 968 KB Output is correct
9 Correct 736 ms 1004 KB Output is correct
10 Correct 979 ms 1220 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1522 ms 8456 KB Time limit exceeded
2 Halted 0 ms 0 KB -