답안 #928208

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
928208 2024-02-16T04:46:46 Z Cutebol 꿈 (IOI13_dreaming) C++17
14 / 100
47 ms 13136 KB
#include "dreaming.h"
#include <bits/stdc++.h>
using namespace std ;
#define pii pair <int , int>
#define ff first 
#define ss second

const int inf = 1e9 ;
const int N = 1e5 + 5 ;

template <class T>
bool chmax( T& x , const T& y ){
  bool f = 0 ;
  if ( x < y ) x = y , f = 1 ;
  return f ;
}
template <class T>
bool chmin( T &x , const T &y ){
  bool f = 0 ;
  if ( x > y ) x = y , f = 1 ;
  return f ;
}

bool vis[N] ;
int d[N] , f[N] , sc[N] ;
int mx , m , r ;
pii ans[N] ;
vector <pii> g[N] ;
vector <int> vec ;

void dfs ( int v , int s , int& m ){
	vis[v] = 1 ; d[v] = s ;
	if ( mx <= d[v] ){
		m = v ; mx = d[v] ;
	}
	for ( auto to : g[v] ) if ( !vis[to.ff] ) dfs(to.ff,s+to.ss,m) ;
}
void fir ( int v , int d , int& m ){
	vis[v] = 0 ; f[v] = d ;
	if ( mx <= f[v] ){
		m = v ; mx = f[v] ;
	}
	for ( auto to : g[v] ) if ( vis[to.ff] ) fir(to.ff,d+to.ss,m) ;
}
void sec ( int v , int d , int& m ){
	vis[v] = 1 ; sc[v] = d ;
	if ( max( f[v] , sc[v] ) <= mx ){
		mx = max ( f[v] , sc[v] ) ; m = v ;
	}
	for ( auto to : g[v] ) if ( !vis[to.ff] ) sec(to.ff,d+to.ss,m) ;
}

int travelTime(int n, int m, int l, int a[], int b[], int c[]) {
	vec.clear() ; r = 0 ;
    for ( int i = 0 ; i < m ; i ++ ){
		g[a[i]].push_back({b[i],c[i]}) ;
		g[b[i]].push_back({a[i],c[i]}) ;
	}
	for ( int i = 0 ; i < n ; i ++ ){
		if ( !vis[i] ){
			mx = 0 ;
			dfs(i,0,m) ;
			mx = 0 ;
			fir(m,0,m) ;
			chmax ( r , f[m] ) ; 
			mx = inf ;
			sec(m,0,m) ;
			vec.push_back(max(f[m],sc[m])) ;
		}
	}
	if ( n == 1 ) return 0 ;
	if ( n == 2 ){
		if ( m == 1 ) return 0 ;
		return l ;
	} int ans = r ;
	sort ( vec.rbegin() , vec.rend() ) ;
	if ( vec.size() > 1 ) chmax ( ans , l+vec[0] + vec[1] ) ;
	if ( vec.size() > 2 ) chmax ( ans , 2*l+vec[1] + vec[2] ) ;
	return ans ;
}
/*
signed main(){
	int n , m , l , a[N] , b[N] , t[N] ;
	cin >> n >> m >> l ;
	for ( int i = 0 ; i < m ; i ++ ) cin >> a[i] >> b[i] >> t[i] ;
	cout << travelTime( n , m , l , a , b , t ) ;
}
//*/
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 13136 KB Output is correct
2 Correct 31 ms 13136 KB Output is correct
3 Correct 22 ms 10324 KB Output is correct
4 Correct 5 ms 5720 KB Output is correct
5 Correct 5 ms 5208 KB Output is correct
6 Correct 9 ms 6428 KB Output is correct
7 Correct 2 ms 4544 KB Output is correct
8 Correct 16 ms 7504 KB Output is correct
9 Correct 22 ms 8788 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 29 ms 9832 KB Output is correct
12 Correct 47 ms 11600 KB Output is correct
13 Correct 1 ms 4440 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Incorrect 1 ms 4444 KB Output isn't correct
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 13136 KB Output is correct
2 Correct 31 ms 13136 KB Output is correct
3 Correct 22 ms 10324 KB Output is correct
4 Correct 5 ms 5720 KB Output is correct
5 Correct 5 ms 5208 KB Output is correct
6 Correct 9 ms 6428 KB Output is correct
7 Correct 2 ms 4544 KB Output is correct
8 Correct 16 ms 7504 KB Output is correct
9 Correct 22 ms 8788 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 29 ms 9832 KB Output is correct
12 Correct 47 ms 11600 KB Output is correct
13 Correct 1 ms 4440 KB Output is correct
14 Correct 1 ms 4440 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 1 ms 4444 KB Output is correct
27 Correct 1 ms 4444 KB Output is correct
28 Incorrect 1 ms 4444 KB Output isn't correct
29 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 8156 KB Output is correct
2 Correct 14 ms 8284 KB Output is correct
3 Correct 14 ms 8160 KB Output is correct
4 Correct 14 ms 8156 KB Output is correct
5 Correct 14 ms 8152 KB Output is correct
6 Correct 15 ms 8672 KB Output is correct
7 Correct 14 ms 8284 KB Output is correct
8 Correct 14 ms 8028 KB Output is correct
9 Correct 13 ms 8372 KB Output is correct
10 Correct 14 ms 8540 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 4 ms 6360 KB Output is correct
13 Correct 4 ms 6360 KB Output is correct
14 Correct 4 ms 6360 KB Output is correct
15 Correct 4 ms 6356 KB Output is correct
16 Correct 4 ms 6360 KB Output is correct
17 Correct 3 ms 6104 KB Output is correct
18 Correct 4 ms 6360 KB Output is correct
19 Correct 4 ms 6360 KB Output is correct
20 Correct 1 ms 4440 KB Output is correct
21 Incorrect 1 ms 4444 KB Output isn't correct
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Incorrect 1 ms 4444 KB Output isn't correct
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 13136 KB Output is correct
2 Correct 31 ms 13136 KB Output is correct
3 Correct 22 ms 10324 KB Output is correct
4 Correct 5 ms 5720 KB Output is correct
5 Correct 5 ms 5208 KB Output is correct
6 Correct 9 ms 6428 KB Output is correct
7 Correct 2 ms 4544 KB Output is correct
8 Correct 16 ms 7504 KB Output is correct
9 Correct 22 ms 8788 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 29 ms 9832 KB Output is correct
12 Correct 47 ms 11600 KB Output is correct
13 Correct 1 ms 4440 KB Output is correct
14 Correct 1 ms 4440 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 1 ms 4444 KB Output is correct
27 Correct 1 ms 4444 KB Output is correct
28 Incorrect 1 ms 4444 KB Output isn't correct
29 Halted 0 ms 0 KB -