Submission #600772

# Submission time Handle Problem Language Result Execution time Memory
600772 2022-07-21T07:43:23 Z Arnch From Hacks to Snitches (BOI21_watchmen) C++17
0 / 100
4118 ms 54784 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 q = st.begin() -> first;
		int p = st.begin() -> second; st.erase(st.begin());
		if(p == n) {
			cout<<q;
			return 0;
		}
		for(auto j : adj[p]) {
			if(!ok(j, q) && !ok(p, q + 1)) continue;
			if(ok(j, q + 1)) {
				st.insert({q + 1, j});
			}
		}
		if(ok(p, q + 1)) {
			st.insert({q + 1, p});
		}
		if(tim > 1e7) break;
	}

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

	cout<<d[n];

    return 0;
}


# Verdict Execution time Memory Grader output
1 Correct 50 ms 52052 KB Output is correct
2 Incorrect 4118 ms 54644 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 46 ms 52052 KB Output is correct
2 Incorrect 4061 ms 54784 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 46 ms 52052 KB Output is correct
2 Incorrect 4061 ms 54784 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 46 ms 52052 KB Output is correct
2 Incorrect 4061 ms 54784 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 50 ms 52052 KB Output is correct
2 Incorrect 4118 ms 54644 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 50 ms 52052 KB Output is correct
2 Incorrect 4118 ms 54644 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 50 ms 52052 KB Output is correct
2 Incorrect 4118 ms 54644 KB Output isn't correct
3 Halted 0 ms 0 KB -