Submission #2304859


Source Code Expand

#include <bits/stdc++.h>
using namespace std;

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int i = 0;i < (n);i++)
#define FOR(i, a, b) for(int i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

const int64 mod = 1e9+7;
using PIC = pair<int32, char>;

const int32 DIRECTED = 0;
const int32 UNDIRECTED = 1;

template<int32 isUNDIRECTED=0>
class Graph{
protected:
	struct Edge{
		int32 u, v, id;
		int64 c;
		Edge(int32 u, int32 v, int64 c=0, int32 id=0):u(u), v(v), c(c), id(id){}
	};

	int32 V, E;
	vector<vector<Edge>> G;
	vector<Edge> Es;
public:
	Graph(){}
	Graph(int32 V):V(V){G.resize(V);}
	Graph(const Graph<isUNDIRECTED>& g):V(g.V), E(g.E), G(g.G), Es(g.Es){}

	void add_edge(int32 u, int32 v, int64 c=0, int32 id=0){
		G[u].emplace_back(u, v, c, id);
		if(isUNDIRECTED) G[v].emplace_back(v, u, c, id);
		Es.emplace_back(u, v, c, id);
		E++;
	}

	const vector<Edge>& operator[](int32 k){
		return G[k];
	}

	int32 dijkstra(int32 s){
		vector<int32> d(V, INF);
		d[s] = 0;
		priority_queue<PII, vector<PII>, greater<PII>> pq;
		pq.push({0, s});
		while(pq.size()){
			int32 dd, v;
			tie(dd, v) = pq.top(); pq.pop();
			if(d[v] < dd) continue;
			REP(i, G[v].size()){
				if(d[G[v][i].v] > d[v]+G[v][i].c){
					d[G[v][i].v] = d[v]+G[v][i].c;
					pq.push({d[G[v][i].v], G[v][i].v});
				}
			}
		}
		return *(max_element(all(d)));
	}
};

int main(void){
	int32 n, m;
	cin >> n >> m;
	Graph<UNDIRECTED> G(n);
	REP(i, m){
		int32 a, b;
		cin >> a >> b;
		G.add_edge(a, b, 1);
	}
	vector<int32> d1, d2;
	d1.resize(n);
	REP(i, n){
		d1[i] = G.dijkstra(i);
	}
	sort(all(d1));
	cin >> n >> m;
	G = Graph<UNDIRECTED>(n);
	REP(i, m){
		int32 a, b;
		cin >> a >> b;
		G.add_edge(a, b, 1);
	}
	d2.resize(n);
	REP(i, n){
		d2[i] = G.dijkstra(i);
	}
	sort(all(d2));
	int32 d1m = d1[d1.size()-1], d2m = d2[d2.size()-1];
	cout << max({d1m, d2m, d1[0]+d2[0]+1}) << " " << d1[d1.size()-1]+d2[d2.size()-1]+1 << endl;
}

Submission Info

Submission Time
Task C - 直径
User maze1230
Language C++14 (GCC 5.4.1)
Score 100
Code Size 2447 Byte
Status AC
Exec Time 323 ms
Memory 1784 KB

Judge Result

Set Name Small Large
Score / Max Score 50 / 50 50 / 50
Status
AC × 28
AC × 58
Set Name Test Cases
Small 10-small_random-00, 10-small_random-01, 10-small_random-02, 10-small_random-03, 10-small_random-04, 10-small_random-05, 10-small_random-06, 10-small_random-07, 10-small_random-08, 10-small_random-09, 10-small_random-10, 10-small_random-11, 10-small_random-12, 10-small_random-13, 10-small_random-14, 10-small_random-15, 10-small_random-16, 10-small_random-17, 10-small_random-18, 10-small_random-19, 21-small_path-00, 21-small_path-01, 21-small_path-02, 21-small_path-03, 21-small_path-04, 00-sample-00, 00-sample-01, 00-sample-02
Large 00-sample-00, 00-sample-01, 00-sample-02, 10-small_random-00, 10-small_random-01, 10-small_random-02, 10-small_random-03, 10-small_random-04, 10-small_random-05, 10-small_random-06, 10-small_random-07, 10-small_random-08, 10-small_random-09, 10-small_random-10, 10-small_random-11, 10-small_random-12, 10-small_random-13, 10-small_random-14, 10-small_random-15, 10-small_random-16, 10-small_random-17, 10-small_random-18, 10-small_random-19, 20-small_tree-00, 20-small_tree-01, 20-small_tree-02, 20-small_tree-03, 20-small_tree-04, 21-small_path-00, 21-small_path-01, 21-small_path-02, 21-small_path-03, 21-small_path-04, 30-large_random-00, 30-large_random-01, 30-large_random-02, 30-large_random-03, 30-large_random-04, 30-large_random-05, 30-large_random-06, 30-large_random-07, 30-large_random-08, 30-large_random-09, 40-large_comp-00, 40-large_comp-01, 40-large_comp-02, 40-large_comp-03, 40-large_comp-04, 41-large_tree-00, 41-large_tree-01, 41-large_tree-02, 41-large_tree-03, 41-large_tree-04, 42-large_path-00, 42-large_path-01, 42-large_path-02, 42-large_path-03, 42-large_path-04
Case Name Status Exec Time Memory
00-sample-00 AC 1 ms 256 KB
00-sample-01 AC 1 ms 256 KB
00-sample-02 AC 1 ms 256 KB
10-small_random-00 AC 1 ms 256 KB
10-small_random-01 AC 1 ms 256 KB
10-small_random-02 AC 1 ms 256 KB
10-small_random-03 AC 1 ms 256 KB
10-small_random-04 AC 1 ms 256 KB
10-small_random-05 AC 1 ms 256 KB
10-small_random-06 AC 1 ms 256 KB
10-small_random-07 AC 1 ms 256 KB
10-small_random-08 AC 1 ms 256 KB
10-small_random-09 AC 1 ms 256 KB
10-small_random-10 AC 1 ms 256 KB
10-small_random-11 AC 1 ms 256 KB
10-small_random-12 AC 1 ms 256 KB
10-small_random-13 AC 1 ms 256 KB
10-small_random-14 AC 1 ms 256 KB
10-small_random-15 AC 1 ms 256 KB
10-small_random-16 AC 1 ms 256 KB
10-small_random-17 AC 1 ms 256 KB
10-small_random-18 AC 1 ms 256 KB
10-small_random-19 AC 1 ms 256 KB
20-small_tree-00 AC 3 ms 256 KB
20-small_tree-01 AC 1 ms 256 KB
20-small_tree-02 AC 4 ms 256 KB
20-small_tree-03 AC 1 ms 256 KB
20-small_tree-04 AC 172 ms 384 KB
21-small_path-00 AC 1 ms 256 KB
21-small_path-01 AC 1 ms 256 KB
21-small_path-02 AC 1 ms 256 KB
21-small_path-03 AC 1 ms 256 KB
21-small_path-04 AC 1 ms 256 KB
30-large_random-00 AC 19 ms 1660 KB
30-large_random-01 AC 1 ms 256 KB
30-large_random-02 AC 5 ms 384 KB
30-large_random-03 AC 1 ms 256 KB
30-large_random-04 AC 22 ms 640 KB
30-large_random-05 AC 1 ms 256 KB
30-large_random-06 AC 9 ms 384 KB
30-large_random-07 AC 1 ms 256 KB
30-large_random-08 AC 323 ms 1784 KB
30-large_random-09 AC 322 ms 1784 KB
40-large_comp-00 AC 1 ms 256 KB
40-large_comp-01 AC 2 ms 384 KB
40-large_comp-02 AC 1 ms 256 KB
40-large_comp-03 AC 4 ms 640 KB
40-large_comp-04 AC 10 ms 896 KB
41-large_tree-00 AC 1 ms 256 KB
41-large_tree-01 AC 2 ms 256 KB
41-large_tree-02 AC 3 ms 256 KB
41-large_tree-03 AC 28 ms 384 KB
41-large_tree-04 AC 171 ms 512 KB
42-large_path-00 AC 4 ms 256 KB
42-large_path-01 AC 1 ms 256 KB
42-large_path-02 AC 1 ms 256 KB
42-large_path-03 AC 19 ms 384 KB
42-large_path-04 AC 39 ms 384 KB