답안 #703953

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
703953 2023-03-01T05:54:57 Z vjudge1 Event Hopping (BOI22_events) C++17
0 / 100
39 ms 3112 KB
/*#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC target ("avx2")
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
  
#define fix fixed<<setprecision
#define forn(i, n) for(int i = 1; i <= (n); ++i)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define sz(s) (int) (s).size()
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define ss second
#define ff first

using namespace std;
using namespace __gnu_pbds;
using pii = pair<int,int>;
using pll = pair<long long, long long>;
using ll = long long;
using ull = unsigned long long;

 
template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const int N = 1e5+100, inf = 1e9+7;
int n, q, s[N], e[N], d[N];

void bfs(int lt){
	for(int i = 1; i <= n; ++i)
		d[i] = inf;
	d[lt] = 0;
	queue<int> q;
	q.push(lt);
	while(!q.empty()){
		int i = q.front();
		q.pop();
		for(int j = 1; j <= n; ++j)
			if(j != i && s[j] <= e[i] && e[i] <= e[j] && d[j] == inf){
				d[j] = d[i] + 1;
				q.push(j);
			}
	}
}


int main(){
	//freopen("cownomics.in", "r", stdin);
	//freopen("cownomics.out", "w", stdout);
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin >> n >> q;
	for(int i = 1; i <= n; ++i)
		cin >> s[i] >> e[i];
	while(q--){
		int a, b;
		cin >> a >> b;
		if(s[b] <= e[a] && e[a] <= e[b]){
			cout << "1\n";
			continue;
		}else{
			cout << "impossible\n";
			continue;
		}
		bfs(a);
		if(d[b] == inf)
			cout << "impossible\n";
		else
			cout << d[b] << '\n';
	}
}	
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 39 ms 3112 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -