Submission #486687

# Submission time Handle Problem Language Result Execution time Memory
486687 2021-11-12T10:43:21 Z my04 Shymbulak (IZhO14_shymbulak) C++17
30 / 100
1500 ms 262144 KB
#include <bits/stdc++.h>

#define pb push_back
#define mp make_pair
#define sz(x) (int)(x).size()
#define S second
#define F first
#define all(x) (x).begin(), (x).end()

using namespace std;
using ll = long long;

void setIO(string name = "") {
	ios_base::sync_with_stdio(NULL);
	cin.tie(NULL);
	cout.tie(NULL);

	if (sz(name)) {
		freopen((name + ".in").c_str(), "r", stdin);
		freopen((name + ".out").c_str(), "w", stdout);
	}
}

const int inf = 1e9;
const ll INF = 1e18;            
const int mod = 1e9 + 7;
const int MAXN = 1e6 + 5;

#define int ll

int n;
vector<int> g[5005];
int dist[5005][5005];
int cnt[5005][5005];

void solve() {
	cin >> n;

	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			dist[i][j] = inf;
		}
	}

	for (int i = 1; i <= n; i++) {
		dist[i][i] = 0;
	}


	for (int i = 1; i <= n; i++) {
		int a, b;
		cin >> a >> b;
		g[a].pb(b);
		g[b].pb(a);
	
		dist[a][b] = dist[b][a] = 1;
		cnt[a][b]++;
		cnt[b][a]++;
	}


	for (int k = 1; k <= n; k++) {
		for (int i = 1; i <= n; i++) {
		 	for (int j = 1; j <= n; j++) {

				int val = dist[i][k] + dist[j][k];
	 	    	if (val == dist[i][j]) cnt[i][j] += (cnt[i][k] * cnt[k][j]);
	 	    	else if (val < dist[i][j]) {
	 	    		dist[i][j] = val;
	 	    		cnt[i][j] = cnt[i][k] * cnt[k][j];
	 	    	}
	 	    }
	 	}
	}

	int mx = -inf;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			mx = max(mx, dist[i][j]);
		}
	}

	int res = 0;
	for (int i = 1; i <= n; i++) {
		for (int j = i + 1; j <= n; j++) {
			if (dist[i][j] == mx) res += cnt[i][j];
		}
	}

	cout << res;
}                   	

main() {
	setIO();
	
	int tt = 1;
	// cin >> tt;
	while (tt--) {
		solve();
	}
	
	return 0;
}

Compilation message

shymbulak.cpp:93:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   93 | main() {
      | ^~~~
shymbulak.cpp: In function 'void setIO(std::string)':
shymbulak.cpp:19:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |   freopen((name + ".in").c_str(), "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
shymbulak.cpp:20:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |   freopen((name + ".out").c_str(), "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 512 KB Output is correct
2 Correct 0 ms 460 KB Output is correct
3 Correct 0 ms 460 KB Output is correct
4 Correct 0 ms 460 KB Output is correct
5 Correct 1 ms 588 KB Output is correct
6 Correct 0 ms 588 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 1 ms 588 KB Output is correct
9 Correct 1 ms 588 KB Output is correct
10 Correct 0 ms 588 KB Output is correct
11 Correct 0 ms 588 KB Output is correct
12 Correct 1 ms 460 KB Output is correct
13 Correct 6 ms 2124 KB Output is correct
14 Correct 156 ms 8344 KB Output is correct
15 Correct 194 ms 8400 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 466 ms 13776 KB Output is correct
2 Correct 698 ms 16988 KB Output is correct
3 Execution timed out 1588 ms 23992 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 439 ms 262144 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -