Submission #166961

# Submission time Handle Problem Language Result Execution time Memory
166961 2019-12-05T04:43:20 Z Trickster Shymbulak (IZhO14_shymbulak) C++14
0 / 100
1320 ms 206924 KB
//Suleyman Atayew

#include <algorithm>
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <vector>
#include <queue>
#include <cmath>
#include <map>
#include <set>

#define N 5010
#define ff first
#define ss second
#define pb push_back
#define ll long long
#define inf 1000000007
#define pii pair <int, int>

using namespace std;

int n;
int a, b;
int v[N][N];
vector <int> E[N];

int main()
{
	cin >> n;
	
	for(int i = 1; i <= n; i++) {
		cin >> a >> b;
		
		E[a].pb(b);
		E[b].pb(a);
	}
	
	for(int i = 1; i <= n; i++)
		for(int h = 1; h <= n; h++)
			v[i][h] = 1e9;
	
	for(int i = 1; i <= n; i++) {
		queue <int> Q;
		Q.push(i);
		
		v[i][i] = 0;
		
		while(!Q.empty()) {
			int x = Q.front();
			Q.pop();
			
			for(auto h: E[x])
				if(v[i][h] == 1e9) {
					v[i][h] = v[i][x] + 1;
					Q.push(h);
				}
		}
	}
	
	int mx = 0;
	for(int i = 1; i <= n; i++)
		for(int h = 1; h <= n; h++)
			mx = max(mx, v[i][h]);
	
	vector <pii> A;
	for(int i = 1; i <= n; i++)
		for(int h = i; h <= n; h++)
			if(mx == v[i][h])
				A.pb({i, h});
	
	ll ans = 0;
	for(auto i: A) {
		int a = i.ff, b = i.ss;
		
		queue <int> Q;
		Q.push(b);
		
		ll arr[N];
		int vis[N];
		memset(arr, 0, sizeof(arr));
		memset(vis, 0, sizeof(vis));
		
		while(!Q.empty()) {
			int x = Q.front();
			Q.pop();
			
			if(vis[x] == 1) continue;
			vis[x] = 1;
			
			for(auto h: E[x])
				if(v[a][h] == v[a][x]-1 && vis[h] == 0)
					arr[v[a][h]]++, Q.push(h);
		}
		
		ll sum = 1;
		for(int h = 1; h < mx; h++) sum *= arr[h];
		
		ans += sum;
	}
	cout << ans;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 2 ms 504 KB Output is correct
4 Correct 2 ms 504 KB Output is correct
5 Correct 2 ms 504 KB Output is correct
6 Incorrect 2 ms 632 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 27 ms 5372 KB Output is correct
2 Correct 1320 ms 10468 KB Output is correct
3 Incorrect 31 ms 8440 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 592 ms 206924 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -