답안 #14240

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
14240 2015-05-07T12:51:57 Z jihoon 꿈 (IOI13_dreaming) C++
컴파일 오류
0 ms 0 KB
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;

int bae[100001][2];
vector<int> lnk[100001];
vector<int> gili[100001];
vector<int> gap[100001];
int lnp[100001];
bool check[100001]={0};
vector<int> cc;
int tm=0;
int mn=2100000000;

int dfs1(int nw){
	int i;
	check[nw]=true;
	for(i=0;i<lnp[nw];i++){
		if(check[lnk[nw][i]]) continue;
		gap[nw][i]=dfs1(lnk[nw][i])+gili[nw][i];
		if(bae[nw][0]<gap[nw][i]){
			bae[nw][1]=bae[nw][0];
			bae[nw][0]=gap[nw][i];
		}else if(bae[nw][1]<gap[nw][i]){
			bae[nw][1]=gap[nw][i];
		}
	}
	return bae[nw][0];
}

void dfs2(int nw,int prevhead){
	int i;
	check[nw]=true;
	mn=min(mn,max(prevhead,bae[nw][0]));
	for(i=0;i<lnp[nw];i++){
		if(check[lnk[nw][i]]) continue;
		if(bae[nw][0]==gap[nw][i]){
			dfs2(lnk[nw][i],max(bae[nw][1],prevhead)+gili[nw][i]);
		}else{
			dfs2(lnk[nw][i],max(bae[nw][0],prevhead)+gili[nw][i]);
		}
	}
}

int main(){
	int i,n,m,l,ia,ib,ic;
	scanf("%d %d %d",&n,&m,&l);
	for(i=0;i<m;i++){
		scanf("%d %d %d",&ia,&ib,&ic);
		lnk[ia].push_back(ib);
		gili[ia].push_back(ic);
		lnk[ib].push_back(ia);
		gili[ib].push_back(ic);
		gap[ia].push_back(0);
		gap[ib].push_back(0);
		lnp[ia]++;lnp[ib]++;
	}
    for(i=0;i<n;i++){
        if(check[i]) continue;
        dfs1(i);
    }
    for(i=0;i<n;i++){
        check[i]=false;
    }
    for(i=0;i<n;i++){
        if(check[i]) continue;
        mn=2100000000;
        dfs2(i,0);
        cc.push_back(-mn);
        //printf("%d\n",mn);
        tm++;
    }
	if(tm==1){
		printf("%d",-cc[0]);
	}else if(tm==2){
		printf("%d",-cc[0]-cc[1]+l);
	}else{
		sort(cc.begin(),cc.end());
		cc[0]=-cc[0];cc[1]=-cc[1];cc[2]=-cc[2];
		printf("%d",max(cc[0]+cc[1]+l,max(cc[0]+cc[2]+l,cc[1]+cc[2]+l*2)));
	}
}

Compilation message

dreaming.cpp: In function 'int main()':
dreaming.cpp:48:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d %d",&n,&m,&l);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~
dreaming.cpp:50:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d %d",&ia,&ib,&ic);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
/tmp/cceZLVS4.o: In function `main':
dreaming.cpp:(.text.startup+0x0): multiple definition of `main'
/tmp/cc7lI1yG.o:grader.c:(.text.startup+0x0): first defined here
/tmp/cc7lI1yG.o: In function `main':
grader.c:(.text.startup+0xa2): undefined reference to `travelTime'
collect2: error: ld returned 1 exit status