답안 #765613

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
765613 2023-06-24T22:41:30 Z LeaRouse 관광지 (IZhO14_shymbulak) C++14
30 / 100
1500 ms 42572 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 = 1e6+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 20 ms 39380 KB Output is correct
2 Correct 24 ms 39380 KB Output is correct
3 Correct 24 ms 39380 KB Output is correct
4 Correct 23 ms 39380 KB Output is correct
5 Correct 29 ms 39380 KB Output is correct
6 Correct 34 ms 39452 KB Output is correct
7 Correct 27 ms 39380 KB Output is correct
8 Correct 32 ms 39468 KB Output is correct
9 Correct 40 ms 39576 KB Output is correct
10 Correct 33 ms 39380 KB Output is correct
11 Correct 36 ms 39380 KB Output is correct
12 Correct 30 ms 39380 KB Output is correct
13 Correct 131 ms 39380 KB Output is correct
14 Correct 374 ms 39476 KB Output is correct
15 Correct 362 ms 39472 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 532 ms 39488 KB Output is correct
2 Correct 640 ms 39508 KB Output is correct
3 Correct 730 ms 39492 KB Output is correct
4 Correct 790 ms 39508 KB Output is correct
5 Execution timed out 1539 ms 39612 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1562 ms 42572 KB Time limit exceeded
2 Halted 0 ms 0 KB -