답안 #68486

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
68486 2018-08-17T08:12:03 Z tempytemptemp 관광지 (IZhO14_shymbulak) C++14
30 / 100
1500 ms 12440 KB
/*
  We found Despacito 5 during contest (not clickbait)
*/
#include	<iostream>
#include	<cstdio>
#include	<vector>
#include 	<set>
#include	<map>
#include	<queue>
#include	<stack>
#include	<algorithm>
#include	<cstring>
#include	<cfloat>
#include	<cmath>
#include	<cassert>
#include	<locale>
#include	<string>
#include	<bitset>
#include	<functional>
#include	<climits>
#include	<iomanip>
using namespace std;

#define read(x)     freopen(x,"r",stdin)
#define write(x)    freopen(x,"w",stdout)
#define cl(a,b)	    memset(a,b,sizeof(a))
#define all(x)      x.begin(),x.end()
#define rall(x)     x.rbegin(),x.rend()
#define ll          long long
#define ld          long double
#define vec         vector
#define vi          vec<int>
#define heap        priority_queue
#define res         reserve
#define pb          push_back
#define f(x,y,z)    for(int x=(y); x<(z); x++)
#define fd(x,y,z)   for(int x=(y); x>=(z); x--)
#define fit(x,y)    for(auto x: y)
#define srt(x)      sort(all(x))
#define rsrt(x)     sort(rall(x))
#define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin())
#define pii         pair<int,int>
#define ppi         pair<pii,int>
#define pip         pair<int,pii>
#define mp          make_pair
#define f1          first
#define s2          second
#define cdbg(x)     cerr<<#x<<" = "<<x<<",\t";
#define cdbl        cerr<<"\n----------\n";
#define pow2(x)     ((x)*(x))
#define edist(x1, y1, x2, y2) (sqrt((pow2(x1-x2)+pow2(y1-y2))))
#define mdist(x1, y1, x2, y2) (abs((x1)-(x2))+abs((y1)-(y2)))
#define y1          FullSensei
#define mid         ((ss+se)>>1)
#define left        (si<<1)
#define right       ((si<<1)+1)
#define pi          3.141592653589793
#define popcount    __builtin_popcount
#define spc			' '
#define endl		'\n'
#define in			insert
#define up_b		upper_bound
#define low_b 		lower_bound
#define Decimal		fixed<<setprecision(20)
#define si			short int

bool checkbit(int x,int y){return (x&(1<<y));}
int setbit(int x,int y){return (x^(1<<y));}
const int dirs[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
const int mod=1e9+7;
const int p1=805306457;
const int p2=1610612741;
const int N=5e3;
const si INF=N;
si d[N+3][N+3];
si c[N+3][N+3];
int n;

int main(){
	scanf("%d",&n);
	assert(n<=N);
	f(i,1,n+1)	f(j,1,n+1){
		c[i][j]=1;
		d[i][j]=INF;
	}
	f(i,1,n+1)	d[i][i]=c[i][i]=0;
	f(i,0,n){
		int u, v;
		scanf("%d %d",&u,&v);
		d[u][v]=1;
		d[v][u]=1;
	}
	f(k,1,n+1){
		f(i,1,n+1){
			f(j,1,n+1){
				if(k==i || k==j || i==j)
					continue;
				if(d[i][j] > d[i][k] + d[k][j]){
					d[i][j]=d[i][k]+d[k][j];
					c[i][j]=c[i][k]*c[k][j];
				}
				else if(d[i][j] == d[i][k] + d[k][j]){
					c[i][j]++;
				}
			}
		}
	}
	int maxv=0, cnt=0;
	f(i,1,n+1){
		f(j,i+1,n+1){
			if(d[i][j] > maxv){
				maxv=d[i][j];
				cnt=c[i][j];
			}
			else if(d[i][j] == maxv){
				cnt+=c[i][j];
			}
		}
	}
	cout<<cnt<<endl;
	return 0;
}

Compilation message

shymbulak.cpp: In function 'int main()':
shymbulak.cpp:80:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&n);
  ~~~~~^~~~~~~~~
shymbulak.cpp:89:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d",&u,&v);
   ~~~~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 436 KB Output is correct
4 Correct 2 ms 436 KB Output is correct
5 Correct 2 ms 616 KB Output is correct
6 Correct 2 ms 616 KB Output is correct
7 Correct 2 ms 616 KB Output is correct
8 Correct 3 ms 616 KB Output is correct
9 Correct 2 ms 616 KB Output is correct
10 Correct 2 ms 648 KB Output is correct
11 Correct 2 ms 664 KB Output is correct
12 Correct 2 ms 664 KB Output is correct
13 Correct 13 ms 1820 KB Output is correct
14 Correct 265 ms 5520 KB Output is correct
15 Correct 275 ms 5528 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 753 ms 8056 KB Output is correct
2 Correct 1115 ms 9452 KB Output is correct
3 Execution timed out 1553 ms 12440 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 4 ms 12440 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -