답안 #198566

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
198566 2020-01-26T15:55:41 Z Sakamotoo 꿈 (IOI13_dreaming) C++14
32 / 100
117 ms 25464 KB
#include "dreaming.h"
#include <bits/stdc++.h>
using namespace std;
 
#define mp make_pair
#define fi first
#define se second
 
const int sim=100010;
 
int p[sim];
bool udah[sim];
vector<pair<int,int> > adj[sim];
long long dp[sim];
vector<pair<long long,pair<int,int> > >sem[sim];
 
int par(int x){
	if(p[x]==x) return x;
	else return p[x]=par(p[x]);
}
 
long long cari(int x, int seb){
	for(int i=0; i<adj[x].size(); i++){
		int ind=adj[x][i].fi;
		if(ind!=seb){
			sem[x].push_back(mp(cari(ind,x)+adj[x][i].se,mp(ind,adj[x][i].se)));
		}
	}
	sort(sem[x].begin(),sem[x].end());
	reverse(sem[x].begin(),sem[x].end());
	if(sem[x].size()==0) return dp[x]=0;
	else return dp[x]=sem[x][0].fi;
}
 
long long cari2(int x,long long baw){
	if(sem[x].size()==0) return baw;
//	if(sem[x].size()>1)baw=max(baw,sem[x][1].fi);
//	long long pen=sem[x][0].fi;
	long long maxi=1e18;
	maxi=min(maxi,max(baw,dp[x]));
//	cout<<"dp "<<x<<' '<<dp[x]<<endl;
	for(int i=0; i<sem[x].size(); i++){
		long long seu=baw;
		if(i==0){
			seu=max(seu,sem[x][1].fi);
		}else {
			seu=max(seu,sem[x][0].fi);
		}
		maxi=min(maxi,cari2(sem[x][i].se.fi,seu+sem[x][i].se.se));
	}
//	cout<<x<<' '<<maxi<<endl;
	return maxi;
}
 
int travelTime(int n, int m, int l, int a[], int b[], int t[]) {
    for(int i=0; i<n; i++){
    	p[i]=i;
	}
	for(int i=0; i<m; i++){
		adj[a[i]].push_back(mp(b[i],t[i]));
		adj[b[i]].push_back(mp(a[i],t[i]));
		
		int x=par(a[i]),y=par(b[i]);
		p[x]=y;
	}
	vector<int> v;
	
	for(int i=0; i<n; i++){
		int x=par(i);
		if(!udah[x]) v.push_back(x);
		udah[x]=1;	
	}
	long long has=0;
	vector<long long> jaw;
	//cout<<v.size()<<endl;
	for(int i=0; i<v.size(); i++){
	//	cout<<v[i]<<endl;
		cari(v[i],-1);
		long long baw=0;
	//	if(sem[v[i]].size()>1){
	//		baw=sem[v[i]][1].fi;
	//	}
		
		long long wk=cari2(v[i],baw);
	//	cout<<wk<<endl<<endl;
		jaw.push_back(wk);
		if(sem[v[i]].size()>1){
			has=max(has,sem[v[i]][0].fi+sem[v[i]][1].fi);
		}else if(sem[v[i]].size()==1){
			has=max(has,dp[v[i]]);
		}
	}
	sort(jaw.begin(),jaw.end());
	reverse(jaw.begin(),jaw.end());
	//long long has=jaw[0];
//	if(jaw.size()<=1){
//		for(int i=1; i<=1e9; i++){
//		}
//	}
	if(jaw.size()>=2){
		has=max(has,jaw[1]+jaw[0]+l);
//		for(int i=1; i<=1e9; i++){
//		}
	}
	if(jaw.size()>=3){
		has=max(has,jaw[1]+jaw[2]+l+l);
	}
	return has;
}

Compilation message

dreaming.cpp: In function 'long long int cari(int, int)':
dreaming.cpp:23:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0; i<adj[x].size(); i++){
               ~^~~~~~~~~~~~~~
dreaming.cpp: In function 'long long int cari2(int, long long int)':
dreaming.cpp:42:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0; i<sem[x].size(); i++){
               ~^~~~~~~~~~~~~~
dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:76:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0; i<v.size(); i++){
               ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 93 ms 24440 KB Output is correct
2 Correct 89 ms 25464 KB Output is correct
3 Correct 58 ms 18680 KB Output is correct
4 Correct 18 ms 8056 KB Output is correct
5 Correct 16 ms 6648 KB Output is correct
6 Correct 26 ms 9596 KB Output is correct
7 Correct 9 ms 5112 KB Output is correct
8 Correct 49 ms 12024 KB Output is correct
9 Correct 61 ms 15096 KB Output is correct
10 Correct 9 ms 5112 KB Output is correct
11 Correct 96 ms 18228 KB Output is correct
12 Correct 117 ms 21628 KB Output is correct
13 Correct 9 ms 5240 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 93 ms 24440 KB Output is correct
2 Correct 89 ms 25464 KB Output is correct
3 Correct 58 ms 18680 KB Output is correct
4 Correct 18 ms 8056 KB Output is correct
5 Correct 16 ms 6648 KB Output is correct
6 Correct 26 ms 9596 KB Output is correct
7 Correct 9 ms 5112 KB Output is correct
8 Correct 49 ms 12024 KB Output is correct
9 Correct 61 ms 15096 KB Output is correct
10 Correct 9 ms 5112 KB Output is correct
11 Correct 96 ms 18228 KB Output is correct
12 Correct 117 ms 21628 KB Output is correct
13 Correct 9 ms 5240 KB Output is correct
14 Incorrect 8 ms 4984 KB Output isn't correct
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 93 ms 24440 KB Output is correct
2 Correct 89 ms 25464 KB Output is correct
3 Correct 58 ms 18680 KB Output is correct
4 Correct 18 ms 8056 KB Output is correct
5 Correct 16 ms 6648 KB Output is correct
6 Correct 26 ms 9596 KB Output is correct
7 Correct 9 ms 5112 KB Output is correct
8 Correct 49 ms 12024 KB Output is correct
9 Correct 61 ms 15096 KB Output is correct
10 Correct 9 ms 5112 KB Output is correct
11 Correct 96 ms 18228 KB Output is correct
12 Correct 117 ms 21628 KB Output is correct
13 Correct 9 ms 5240 KB Output is correct
14 Incorrect 8 ms 4984 KB Output isn't correct
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 43 ms 10224 KB Output is correct
2 Correct 51 ms 10352 KB Output is correct
3 Correct 60 ms 10252 KB Output is correct
4 Correct 45 ms 10224 KB Output is correct
5 Correct 47 ms 10268 KB Output is correct
6 Correct 47 ms 11120 KB Output is correct
7 Correct 47 ms 10608 KB Output is correct
8 Correct 41 ms 10224 KB Output is correct
9 Correct 43 ms 10096 KB Output is correct
10 Correct 47 ms 10480 KB Output is correct
11 Correct 8 ms 4988 KB Output is correct
12 Correct 15 ms 7796 KB Output is correct
13 Correct 14 ms 7924 KB Output is correct
14 Correct 15 ms 7796 KB Output is correct
15 Correct 14 ms 7924 KB Output is correct
16 Correct 15 ms 7920 KB Output is correct
17 Correct 14 ms 7664 KB Output is correct
18 Correct 14 ms 7932 KB Output is correct
19 Correct 15 ms 7792 KB Output is correct
20 Correct 9 ms 4984 KB Output is correct
21 Correct 8 ms 4984 KB Output is correct
22 Correct 8 ms 5112 KB Output is correct
23 Correct 14 ms 7796 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 93 ms 24440 KB Output is correct
2 Correct 89 ms 25464 KB Output is correct
3 Correct 58 ms 18680 KB Output is correct
4 Correct 18 ms 8056 KB Output is correct
5 Correct 16 ms 6648 KB Output is correct
6 Correct 26 ms 9596 KB Output is correct
7 Correct 9 ms 5112 KB Output is correct
8 Correct 49 ms 12024 KB Output is correct
9 Correct 61 ms 15096 KB Output is correct
10 Correct 9 ms 5112 KB Output is correct
11 Correct 96 ms 18228 KB Output is correct
12 Correct 117 ms 21628 KB Output is correct
13 Correct 9 ms 5240 KB Output is correct
14 Incorrect 9 ms 5240 KB Output isn't correct
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 93 ms 24440 KB Output is correct
2 Correct 89 ms 25464 KB Output is correct
3 Correct 58 ms 18680 KB Output is correct
4 Correct 18 ms 8056 KB Output is correct
5 Correct 16 ms 6648 KB Output is correct
6 Correct 26 ms 9596 KB Output is correct
7 Correct 9 ms 5112 KB Output is correct
8 Correct 49 ms 12024 KB Output is correct
9 Correct 61 ms 15096 KB Output is correct
10 Correct 9 ms 5112 KB Output is correct
11 Correct 96 ms 18228 KB Output is correct
12 Correct 117 ms 21628 KB Output is correct
13 Correct 9 ms 5240 KB Output is correct
14 Incorrect 8 ms 4984 KB Output isn't correct
15 Halted 0 ms 0 KB -