#include <bits/stdc++.h>
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define PB push_back
#define MP make_pair
#define ft first
#define sd second
#define pll pair<ll, ll>
#define pii pair<int, int>
using namespace std;
typedef long long ll;
const ll OO = 1e18;
const int oo = 2e9;
const int N = 200100;
const int M = 1010;
vector<int> g[N], vc, cyc;
set<pii> st;
int n, ans = 0, dst[N], mx = 0, mrk[N];
void CYCLE(int lst){
cyc.clear();
int it = sz(vc) - 1;
while (1){
cyc.PB(vc[it]);
if (vc[it] == lst)
break;
it--;
}
}
void dfs(int v, int p){
if (sz(cyc) > 0) return;
vc.PB(v);
mrk[v] = 1;
for (int u : g[v]){
if (u == p) continue;
if (mrk[u] == 0)
dfs(u, v); else
if (mrk[u] == 1)
CYCLE(u);
}
mrk[v] = 2;
vc.pop_back();
}
int main(){
cin >> n;
for (int i = 0; i < n; i++){
int x, y; cin >> x >> y;
x--; y--;
g[x].PB(y); g[y].PB(x);
}
dfs(0, -1);
for (int i = 0; i < n; i++){
for (int j = 0; j < n; j++)
dst[j] = oo;
dst[i] = 0;
st.insert(MP(0, i));
while (sz(st)){
int v = (*st.begin()).sd;
st.erase(st.begin());
for (int u : g[v])
if (dst[u] > dst[v] + 1){
st.erase(MP(dst[u], u));
dst[u] = dst[v] + 1;
st.insert(MP(dst[u], u));
}
}
for (int v = 0; v < n; v++) {
if (dst[v] > mx) {
mx = dst[v];
ans = 0;
}
if (dst[v] == mx)
ans++;
}
}
cout << ans / (sz(cyc) % 2 == 0 ? 1 : 2);
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
4984 KB |
Output is correct |
2 |
Correct |
6 ms |
4984 KB |
Output is correct |
3 |
Correct |
6 ms |
4984 KB |
Output is correct |
4 |
Correct |
6 ms |
4984 KB |
Output is correct |
5 |
Correct |
6 ms |
4984 KB |
Output is correct |
6 |
Incorrect |
6 ms |
4984 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
43 ms |
5112 KB |
Output is correct |
2 |
Correct |
121 ms |
5240 KB |
Output is correct |
3 |
Correct |
93 ms |
5240 KB |
Output is correct |
4 |
Incorrect |
176 ms |
5108 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1536 ms |
10092 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |