답안 #718985

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
718985 2023-04-05T08:12:44 Z vinnipuh01 Event Hopping (BOI22_events) C++17
0 / 100
21 ms 5512 KB
#include <iostream>
#include <bits/stdc++.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <deque>
#include <set>
#include <stack>
#include <string>
#include <map>
#include <queue>
#define sqrt sqrtl
 
using namespace std;
 
const long long oo = 1e9;
 
int sum, ans = 0, mx = 0, mn = 1000000000, num, pos;
 
 
/*
    ViHHiPuh
 
   (( `'-""``""-'` ))
     )-__-_.._-__-(
   / --- (o _ o) --- \
   \ .-* ( .0. ) *-. /
   _'-. ,_ '=' _, .-'_
  / `;#'#'# - #'#'#;` \
 \_)) -----'#'----- ((_/
      # --------- #
  '# ------- ------ #'
  /..-'# ------- #'-.\
  _\...-\'# -- #'/-.../_
  ((____)- '#' -(____))
 
 
    cout << fixed << setprecision(6) << x;
 
 
    freopen ( "sum.in", "r", stdin )
*/

int n, m, x, y, a[ 100001 ], b[ 100001 ], d[ 100001 ], d1[ 5001 ][ 5001 ];
vector <int> v[ 100001 ];
queue <int> q;

void bfs( int u ) {
	for ( int i = 1; i <= n; i ++ )
		d[ i ] = oo;
	d[ u ] = 0;
	q.push( u );
	while ( q.size() ) {
		int x = q.front();
		q.pop();
		for ( auto to : v[ u ] ) {
			if ( d[ to ] > d[ x ] + 1 ) {
				d[ to ] = d[ x ] + 1;
				q.push( to ); 
			}
		}
	}
}

main () {
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cin >> n >> m;
	for ( int i = 1; i <= n; i ++ ) {
		cin >> a[ i ] >> b[ i ];
	}
	if ( n <= 5000 ) {
		for ( int i = 1; i <= n; i ++ ) {
			for ( int j = 1; j <= n; j ++ ) {
				if ( a[ j ] <= b[ i ] && b[ i ] <= b[ j ] ) {
					v[ i ].push_back( j );
				}
			}
		}
		for ( int i = 1; i <= n; i ++ ) {
			bfs( i );
			for ( int j = 1; j <= n; j ++ )
				d1[ i ][ j ] = d[ j ];
		}
		while ( m -- ) {
			cin >> x >> y;
			if ( d1[ x ][ y ] == oo )
				cout << "impossible\n";
			else
				cout << d1[ x ][ y ] << "\n";
		}
		return 0;
	}
	else if ( m <= 100 ) {
		for ( int i = 1; i <= n; i ++ ) {
			
		}
		while ( m -- ) {
			cin >> x >> y;
			
		}  
	}
}

Compilation message

events.cpp:65:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   65 | main () {
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 2644 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 2644 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 2644 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 2644 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 21 ms 5512 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 2644 KB Output isn't correct
2 Halted 0 ms 0 KB -