답안 #1046102

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

struct bfstyp{
    long long int ind;
    long long int val;
};

void prim(long long int poc,long long int n,vector<vector<long long int>>& gra,long long int& najv,long long int& najvkol){
    vector<long long int> dist(n,-1);
    dist[poc]=0;
    queue<bfstyp> bfslis={};
    bfslis.push(bfstyp{poc,0});
    while (bfslis.size()>0){
        long long int ind=bfslis.front().ind;
        long long int val=bfslis.front().val;
     //`   cout << ind << "\n";
        bfslis.pop();
        for (long long int i=0;i<gra[ind].size();i++){
        //    cout << i << "\n";
            long long int ind2=gra[ind][i];
            if (dist[ind2]!=-1){
                continue;
            }
            dist[ind2]=val+1;
            bfslis.push(bfstyp{ind2,val+1});
        }
    }
    vector<pair<long long int,long long int>> lis={};
  //  cout << "\n";
    for (long long int i=0;i<n;i++){
    //    cout << dist[i] << "\n";
        lis.push_back({dist[i],i});
    }
   // cout << "\n";
    sort(lis.begin(),lis.end());
    vector<long long int> dp(n,0);
    dp[poc]=1;
    for (long long int i=0;i<n;i++){
        long long int ind=lis[i].second;
        if (dp[ind]==0){
            continue;
        }
        for (long long int j=0;j<gra[ind].size();j++){
            long long 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);
    long long int n;
    cin >> n;
    vector<vector<long long int>>  gra(n,vector<long long int>{}); 
    for (long long int i=0;i<n;i++){
        long long int unos;
        long long int unos2;
        cin >> unos >> unos2;
        gra[--unos].push_back(--unos2);
        gra[unos2].push_back(unos);    
    }
    long long int najv=0;
    long long int najvkol=0;
    for (long long 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(long long int, long long int, std::vector<std::vector<long long int> >&, long long int&, long long int&)':
shymbulak.cpp:19:33: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   19 |         for (long long int i=0;i<gra[ind].size();i++){
      |                                ~^~~~~~~~~~~~~~~~
shymbulak.cpp:44:33: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |         for (long long int j=0;j<gra[ind].size();j++){
      |                                ~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 460 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 356 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 2 ms 472 KB Output is correct
14 Correct 17 ms 516 KB Output is correct
15 Correct 17 ms 524 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 348 KB Output is correct
2 Correct 28 ms 540 KB Output is correct
3 Correct 58 ms 348 KB Output is correct
4 Correct 56 ms 348 KB Output is correct
5 Execution timed out 1523 ms 1052 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1531 ms 12500 KB Time limit exceeded
2 Halted 0 ms 0 KB -