답안 #29692

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
29692 2017-07-20T10:45:39 Z inqr 꿈 (IOI13_dreaming) C++14
0 / 100
1000 ms 10520 KB
#include "dreaming.h"
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define rt insert
#define st first
#define nd second
#define ll long long
#define DB printf("debug\n");
using namespace std;
int n,m,l;
vector < pair < int , int > > ed[100005];

int rn1=-1,rn2=-1;
bool dfsv[100005];
int enuzakyol,enuzaknod;
inline void dfsmax(int vn,int wn){
	if(dfsv[vn])return;
	dfsv[vn]=1;
	//printf("dfsmax %d %d %d %d\n",vn,wn,rn1,rn2);
	if(wn>enuzakyol){
		enuzakyol=wn;
		enuzaknod=vn;
	}
	for(int i=0;i<(int)ed[vn].size();i++){
		if(dfsv[ed[vn][i].st]==0)
			dfsmax(ed[vn][i].st,wn+ed[vn][i].nd);
	}
	if(rn1==vn and dfsv[rn2]==0)dfsmax(rn2,wn+l);
	else if(rn2==vn and dfsv[rn1]==0)dfsmax(rn1,wn+l);
}
inline int enuzak(){
	enuzakyol=-1,enuzaknod=-1;
	memset(dfsv,0,sizeof(dfsv));

	if(ed[0].size())dfsmax(0,0);
	else dfsmax(1,0);
	//printf("enuzakyol=%d enuzaknod=%d\n",enuzakyol,enuzaknod);
	
	enuzakyol=-1;
	memset(dfsv,0,sizeof(dfsv));
	dfsmax(enuzaknod,0);
	
	return enuzakyol;
} 
inline int solve(int teknod){
	int enuzakyolyeni=INT_MAX;
	//printf("teknod=%d\n",teknod);
	for(int i=0;i<n;i++){
		if(i!=teknod){
			//printf("enuzak %d %d\n",i,teknod);
			rn1=i;rn2=teknod;
			enuzakyolyeni=min(enuzakyolyeni,enuzak());
		}
	}
	return enuzakyolyeni;
}
int dfs2max;
vector < int > dfs2wn;
vector < int > dfs2nd;
void dfs2(int vn,int wn){
	if(dfsv[vn]==1)return;
	dfsv[vn]=1;
	dfs2wn.pb(wn);
	dfs2nd.pb(vn);
	dfs2max=max(dfs2max,wn);
	for(int i=0;i<n;i++){
		dfs2(ed[vn][i].st,wn+ed[vn][i].nd);
	}
}
int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
 	n=N,m=M,l=L;
	for(int i=0;i<M;i++){
		ed[A[i]].pb(mp(B[i],T[i]));
		ed[B[i]].pb(mp(A[i],T[i]));
	}
	if(M=N-2 and N<=100){
		int teknod=-1;
		for(int i=0;i<N;i++){
			if(ed[i].size()==0){
				//printf("i=%d i.size=%d\n",i,(int)ed[i].size());
				teknod=i;
			}
		}
	    return solve(teknod);
	}
	else{
		for(int i=0;i<N;i++){
			if(ed[i].size()==1 and dfsv[i]==0){
				memset(dfsv,0,sizeof(dfsv));
				dfs2max=-1;
				dfs2nd.clear();
				dfs2wn.clear();
				dfs2(i,0);
				if(rn1==-1){
					rn1=dfs2nd[lower_bound(dfs2wn.begin(),dfs2wn.end(),(dfs2max/2))-dfs2wn.begin()];
				}
				else rn2=dfs2nd[lower_bound(dfs2wn.begin(),dfs2wn.end(),(dfs2max/2))-dfs2wn.begin()];
			}
		}
		return enuzak();
	}
}

Compilation message

dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:77:6: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
  if(M=N-2 and N<=100){
     ~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1060 ms 10520 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1060 ms 10520 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1060 ms 10520 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 24 ms 9976 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1060 ms 10520 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1060 ms 10520 KB Time limit exceeded
2 Halted 0 ms 0 KB -