답안 #600757

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
600757 2022-07-21T07:37:49 Z Arnch From Hacks to Snitches (BOI21_watchmen) C++17
0 / 100
1672 ms 54624 KB
// oooo
/*
 har chi delet mikhad bebar ~
 gitar o ba khodet nabar! ~
 ;Amoo_Hasan;
*/

#include<bits/stdc++.h>
//#pragma GCC optimize("O3,no-stack-protector,unroll-loops")
//#pragma GCC target("avx2,fma")

using namespace std;

typedef long long ll;
typedef long double ld;

#define Sz(x) int((x).size())
#define All(x) (x).begin(), (x).end()
#define wtf(x) cout<<#x <<" : " <<x <<endl

constexpr ll inf = 1e18, N = 1e6 + 10, mod = 1e9 + 7, pr = 1000696969;

int a[N], d[N];
vector<pair<int, int> > can[N];
vector<int> adj[N];

bool ok(int u, int t) {
	for(auto i : can[u]) {
		if(i.first > t) continue;
		if((t - i.first) % i.second == 0) return false;
	}
	return true;
}

int main() {
    ios :: sync_with_stdio(0), cin.tie(0);
	
	int n, m; cin >>n >>m;
	for(int i = 0; i < m; i++) {
		int u, v; cin >>u >>v;
		adj[u].push_back(v), adj[v].push_back(u);
	}
	int k; cin >>k;
	for(int i = 0; i < k; i++) {
		int l; cin >>l;
		for(int j = 0; j < l; j++) {
			cin >>a[j];
			can[a[j]].push_back({j, l});
		}
	}
	assert(k == 1);

	memset(d, 63, sizeof(d));
	d[1] = 0;
	set<pair<int, int> > st;
	st.insert({d[1], 1});

	int tim = 0;
	
	while(!st.empty()) {
		tim++;
		int p = st.begin() -> second; st.erase(st.begin());
		if(p == n) {
			cout<<d[p];
			return 0;
		}
		for(auto j : adj[p]) {
			if(d[j] <= d[p] + 1) continue;
			if(!ok(j, d[p]) && !ok(p, d[p] + 1)) continue;
			if(ok(j, d[p] + 1)) {
				st.erase({d[j], j});
				d[j] = d[p] + 1;
				st.insert({d[j], j});
			}
		}
		if(ok(p, d[p] + 1)) {
			d[p]++;
			st.insert({d[p], p});
		}
		if(tim > 1e7) break;
	}

	if(d[n] > 1e9) {
		cout<<"impossible";
		return 0;
	}

	cout<<d[n];

    return 0;
}


# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 52116 KB Output is correct
2 Incorrect 1586 ms 54624 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 42 ms 52012 KB Output is correct
2 Incorrect 1672 ms 54536 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 42 ms 52012 KB Output is correct
2 Incorrect 1672 ms 54536 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 42 ms 52012 KB Output is correct
2 Incorrect 1672 ms 54536 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 52116 KB Output is correct
2 Incorrect 1586 ms 54624 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 52116 KB Output is correct
2 Incorrect 1586 ms 54624 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 52116 KB Output is correct
2 Incorrect 1586 ms 54624 KB Output isn't correct
3 Halted 0 ms 0 KB -