답안 #939047

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
939047 2024-03-06T04:21:14 Z ezzzay Network (BOI15_net) C++14
0 / 100
1 ms 2392 KB
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ff first
#define ss second
#define pb push_back
const int N=3e3+5;
bool vis[N];
vector<int>v[N];
vector<pair<int,int>>rts;
vector<int>vec;
void dfs(int a, pair<int,int>p ){
    int x=p.ff;
    int y=p.ss;
    vec.pb(a);
    vis[a]=1;
    for(auto b:v[a]){
        if((a==x and b==y) or (a==y and b==x)){
            continue;
        }
        if(vis[b]==0)dfs(b,p);
    }
}
int dist[N][N];
signed main(){
    int n;
    cin>>n;
    for(int i=1;i<n;i++){
        int a,b;
        cin>>a>>b;
        dist[a][b]=-100000;
        dist[b][a]=-100000;
        v[a].pb(b);
        v[b].pb(a);
        rts.pb({a,b});
    }
    int z=0;
    for(auto p:rts){
        int x=p.ff,y=p.ss;
        memset(vis,0,sizeof vis);
        vec.clear();
        dfs(x,p);
        vector<int>vc=vec;
        vec.clear();
        dfs(y,p);
        for(auto w:vec){
            for(auto e:vc){
                dist[w][e]++;
                dist[e][w]++;
                z=max(z,dist[w][e]);
            }
        }
    }
    int k=0;
    for(int i=1;i<=n;i++){
        for(int j=i+1;j<=n;j++){
            if(dist[i][j]==z){
                k++;
            }
        }
    }
    cout<<k<<endl;
     for(int i=1;i<=n;i++){
        for(int j=i+1;j<=n;j++){
            if(dist[i][j]==z){
                k++;
                cout<<i<<" "<<j<<endl;
            }
        }
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 1 ms 2392 KB Invalid number of links.
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 1 ms 2392 KB Invalid number of links.
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 1 ms 2392 KB Invalid number of links.
3 Halted 0 ms 0 KB -