답안 #1046103

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1046103 2024-08-06T10:07:42 Z ivopav 관광지 (IZhO14_shymbulak) C++17
30 / 100
1500 ms 8052 KB
#include <bits/stdc++.h>
using namespace std;

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});
    while (bfslis.size()>0){
        int ind=bfslis.front().ind;
        int val=bfslis.front().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<pair<int,int>> lis={};
  //  cout << "\n";
    for (int i=0;i<n;i++){
    //    cout << dist[i] << "\n";
        lis.push_back({dist[i],i});
    }
   // 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:19:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   19 |         for (int i=0;i<gra[ind].size();i++){
      |                      ~^~~~~~~~~~~~~~~~
shymbulak.cpp:44:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |         for (int j=0;j<gra[ind].size();j++){
      |                      ~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 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 17 ms 348 KB Output is correct
15 Correct 17 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 344 KB Output is correct
2 Correct 21 ms 528 KB Output is correct
3 Correct 51 ms 348 KB Output is correct
4 Correct 59 ms 344 KB Output is correct
5 Execution timed out 1568 ms 604 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1576 ms 8052 KB Time limit exceeded
2 Halted 0 ms 0 KB -