제출 #718994

#제출 시각아이디문제언어결과실행 시간메모리
718994vinnipuh01Event Hopping (BOI22_events)C++17
10 / 100
1578 ms40508 KiB
#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 ];
set <pair<int, int> > st;

void bfs( int u ) {
	for ( int i = 1; i <= n; i ++ )
		d[ i ] = oo;
	d[ u ] = 0;
	st.insert( { d[ u ], u } );
	while ( st.size() ) {
		u = st.begin()->second;
		st.erase( st.begin() );
		for ( auto to : v[ u ] ) {
			if ( d[ to ] > d[ u ] + 1 ) {
				st.erase( { d[ to ], to } );
				d[ to ] = d[ u ] + 1;
				st.insert( { d[ to ], 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 ] && i != 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;
			
		}  
	}
}

컴파일 시 표준 에러 (stderr) 메시지

events.cpp:66:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   66 | main () {
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...