답안 #765615

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
765615 2023-06-24T22:43:17 Z LeaRouse 관광지 (IZhO14_shymbulak) C++14
50 / 100
342 ms 11172 KB
#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(0); cin.tie(0);
#define ll long long
#define ff first
#define ss second
using namespace std;
const int MAX = 5e3+5;
ll D[MAX],C[MAX],ans[MAX];
pair<int,int>dp[(1<<21)+5];
vector<int>v[MAX];
ll maxi=0;
void bfs(int x){
    memset(D,-1,sizeof(D));
    memset(C,0,sizeof(C));
    queue<int>q;
    D[x]=0; C[x] = 1; q.push(x); 
    while(!q.empty()){
        int u=q.front(); 
        q.pop();
        for(auto it:v[u]){
            if(D[it]==-1){
                D[it]=D[u]+1;   C[it]=C[u];
                ans[D[it]]+=C[u];   q.push(it);
            }
            else if(D[it]==D[u]+1){
                C[it]+=C[u];    ans[D[it]]+=C[u];
            }
            maxi=max(maxi,D[it]);
        }
    }
}

void go(){
    int n;  cin>>n;
    for(int i=0;i<n;i++){
        int a,b;    cin>>a>>b;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    for(int i=0;i<n;i++){
        bfs(i+1);
    }
    cout<<ans[maxi]/2<<endl;
}

int main(){
    fastio;
    go();
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 0 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 416 KB Output is correct
10 Correct 0 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 3 ms 468 KB Output is correct
15 Correct 3 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 556 KB Output is correct
2 Correct 7 ms 560 KB Output is correct
3 Correct 11 ms 568 KB Output is correct
4 Correct 12 ms 468 KB Output is correct
5 Correct 258 ms 668 KB Output is correct
6 Correct 180 ms 724 KB Output is correct
7 Correct 285 ms 688 KB Output is correct
8 Correct 276 ms 596 KB Output is correct
9 Correct 269 ms 680 KB Output is correct
10 Correct 342 ms 680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 26 ms 11172 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -