Submission #138179


Source Code Expand

#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<string>
#include<string.h>
#include<cstdlib>
#include<ctime>
#include<cmath>
#include<complex>
#include<map>
#include<set>
#include<bitset>
#include<iostream>
#include<sstream>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < n; i++)
#define rrep(i,n) for(int i = 1; i <= n; i++)
#define drep(i,n) for(int i = n-1; i >= 0; i--)
#define gep(i,g,j) for(int i = g.head[j]; i != -1; i = g.e[i].next)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) x = max(x,y);
#define mins(x,y) x = min(x,y);
#define pb push_back
#define sz(x) (int)(x).size()
#define popcount __builtin_popcount
#define snuke srand((unsigned)clock()+(unsigned)time(NULL))
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;

const int MX = 1005, INF = 1000000000;
const ll LINF = 1000000000000000000ll;
const double eps = 1e-10;
const int dx[] = {-1,0,1,0}, dy[] = {0,-1,0,1}; //<^>v

// Dijkstra
// Graph
typedef int TT;
struct edge{
	int next, to, lim;
	TT co;
	edge(){}
	edge(int next, int to, TT co=0, int lim=1):next(next),to(to),co(co),lim(lim){}
};
struct graph{
	vector<TT> head; vector<edge> e; int es, vs;
	graph(){}
	graph(int vsz, int esz){ head.resize(vsz); e.resize(esz+1); init(vsz);}
	void init(int vsz){ es = 0; vs = vsz; rep(i,vsz) head[i] = -1;}
	void add(int from, int to, TT co=0, int lim=1){ e[es] = edge(head[from],to,co,lim); head[from] = es++;}
	void add2(int from, int to, TT co=0, int lim=1){ add(from,to,co,lim); add(to,from,co,lim);}
	void addf(int from, int to, TT co=0, int lim=1){ add(from,to,co,lim); add(to,from,-co,0);}
};
//
typedef pair<TT,int> TP;
vector<TT> d1, d2; vector<int> pre;
void dijk(graph& ng, int sv, vector<TT>& ndist){
	ndist.resize(ng.vs); fill(rng(ndist),INF); pre.resize(ng.vs); fill(rng(pre),-1);
	priority_queue<TP, vector<TP>, greater<TP> > q;
	TP p; int v; ng.e[ng.es].to = sv; q.push(TP(0,ng.es));
	while(!q.empty()){
		p = q.top(); q.pop(); v = ng.e[p.se].to;
		if(pre[v] != -1) continue;
		ndist[v] = p.fi; pre[v] = p.se^1;
		for(int i = ng.head[v]; i != -1; i = ng.e[i].next)
			if(ng.e[i].lim > 0 && p.fi+ng.e[i].co < ndist[ng.e[i].to]){
				ndist[ng.e[i].to] = p.fi+ng.e[i].co; q.push(TP(p.fi+ng.e[i].co,i));}
	}
}
//

int main(){
	int n1, n2, m1, m2;
	scanf("%d%d",&n1,&m1);
	
	graph g1(MX,MX*20), g2(MX,MX*20);
	int a, b;
	rep(i,m1){
		scanf("%d%d",&a,&b);
		g1.add2(a,b,1);
	}
	
	scanf("%d%d",&n2,&m2);
	rep(i,m2){
		scanf("%d%d",&a,&b);
		g2.add2(a,b,1);
	}
	
	int x1 = INF, x2 = INF, y1 = 0, y2 = 0, d = 0;
	rep(i,n1){
		dijk(g1,i,d1);
		int r = 0;
		rep(j,n1) r = max(r,d1[j]);
		x1 = min(x1,r);
		y1 = max(y1,r);
		d = max(d,r);
	}
	rep(i,n2){
		dijk(g2,i,d2);
		int r = 0;
		rep(j,n2) r = max(r,d2[j]);
		x2 = min(x2,r);
		y2 = max(y2,r);
		d = max(d,r);
	}
	
	printf("%d %d\n",max(d,x1+x2+1),y1+y2+1);
	
	return 0;
}




Submission Info

Submission Time
Task C - 直径
User snuke
Language C++ (G++ 4.6.4)
Score 100
Code Size 3123 Byte
Status AC
Exec Time 748 ms
Memory 1572 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:79:23: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
./Main.cpp:84:22: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
./Main.cpp:88:23: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
./Main.cpp:90:22: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]

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 22 ms 1572 KB
00-sample-01 AC 23 ms 1436 KB
00-sample-02 AC 23 ms 1444 KB
10-small_random-00 AC 22 ms 1444 KB
10-small_random-01 AC 23 ms 1568 KB
10-small_random-02 AC 22 ms 1564 KB
10-small_random-03 AC 21 ms 1392 KB
10-small_random-04 AC 22 ms 1572 KB
10-small_random-05 AC 23 ms 1568 KB
10-small_random-06 AC 22 ms 1440 KB
10-small_random-07 AC 22 ms 1572 KB
10-small_random-08 AC 22 ms 1564 KB
10-small_random-09 AC 22 ms 1384 KB
10-small_random-10 AC 23 ms 1444 KB
10-small_random-11 AC 22 ms 1440 KB
10-small_random-12 AC 22 ms 1568 KB
10-small_random-13 AC 22 ms 1440 KB
10-small_random-14 AC 22 ms 1440 KB
10-small_random-15 AC 21 ms 1564 KB
10-small_random-16 AC 22 ms 1388 KB
10-small_random-17 AC 22 ms 1572 KB
10-small_random-18 AC 22 ms 1572 KB
10-small_random-19 AC 22 ms 1572 KB
20-small_tree-00 AC 25 ms 1564 KB
20-small_tree-01 AC 22 ms 1440 KB
20-small_tree-02 AC 27 ms 1444 KB
20-small_tree-03 AC 23 ms 1444 KB
20-small_tree-04 AC 253 ms 1448 KB
21-small_path-00 AC 23 ms 1568 KB
21-small_path-01 AC 22 ms 1444 KB
21-small_path-02 AC 22 ms 1572 KB
21-small_path-03 AC 22 ms 1444 KB
21-small_path-04 AC 21 ms 1564 KB
30-large_random-00 AC 78 ms 1380 KB
30-large_random-01 AC 21 ms 1564 KB
30-large_random-02 AC 27 ms 1572 KB
30-large_random-03 AC 23 ms 1568 KB
30-large_random-04 AC 54 ms 1440 KB
30-large_random-05 AC 23 ms 1448 KB
30-large_random-06 AC 34 ms 1448 KB
30-large_random-07 AC 23 ms 1568 KB
30-large_random-08 AC 748 ms 1448 KB
30-large_random-09 AC 722 ms 1436 KB
40-large_comp-00 AC 22 ms 1564 KB
40-large_comp-01 AC 23 ms 1568 KB
40-large_comp-02 AC 23 ms 1564 KB
40-large_comp-03 AC 26 ms 1440 KB
40-large_comp-04 AC 38 ms 1560 KB
41-large_tree-00 AC 23 ms 1428 KB
41-large_tree-01 AC 23 ms 1560 KB
41-large_tree-02 AC 26 ms 1564 KB
41-large_tree-03 AC 60 ms 1440 KB
41-large_tree-04 AC 254 ms 1564 KB
42-large_path-00 AC 28 ms 1560 KB
42-large_path-01 AC 23 ms 1444 KB
42-large_path-02 AC 23 ms 1452 KB
42-large_path-03 AC 54 ms 1448 KB
42-large_path-04 AC 95 ms 1444 KB