Submission #420745

# Submission time Handle Problem Language Result Execution time Memory
420745 2021-06-08T13:41:22 Z lakshith_ From Hacks to Snitches (BOI21_watchmen) C++14
0 / 100
779 ms 85956 KB
#include <bits/stdc++.h>

using namespace std;

//#define int long long 
#define what_is(a) cout << #a << " is " <<a << "\n"
#define checker(a) cout << "chekcer reached " << a << "\n"

inline void io(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
}

vector<vector<int>> adj(100000,vector<int>());

struct node{
	int n,t,a;
};

void print(node n){
	cout << n.n << " " << n.t << " " << n.a << "\n";
}

int mem[1000000][200];
int w[100000][200];

void solve(){
	int n,m;
	cin >> n >> m;
	for(int i=0;i<m;i++){
		int u,v;
		cin >>u >> v;
		u--,v--;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	
	int k;
	cin >> k;
	int L = 126;
	while(k--){
		int l; cin >> l;
		vector<int> vec(l);
		for(int& x: vec){
			cin >> x;
			x--;
		}
		for(int t=0;t<L;t++)
			w[vec[t%l]][t] = 1;
	}
	 
	int ans = -1;
	queue<node> q;
	q.push({0,0,0});
	while(!q.empty()){
		node u = q.front();
		//print(u);
		q.pop();
		if(u.n==n-1){
			ans = u.a;
			break;
		}
		for(int v:adj[u.n]){
			if(w[v][(u.t+1)%L])continue;
			if(w[u.n][(u.t+1)%L]&&w[v][(u.t)%L])continue;
			if(mem[v][(u.t+1)%L])continue;
			mem[v][(u.t+1)%L] = 1;
			q.push({v,(u.t+1)%L,u.a+1});
		}
		if(w[u.n][(u.t+1)%L]==0 && mem[u.n][(u.t+1)%L]==0){
			q.push({u.n,(u.t+1)%L,u.a+1});
			mem[u.n][(u.t+1)%L] = 1;
		}
	}
	cout << (ans==-1?"impossible":to_string(ans)) << " \n";
}

signed main(){
	solve();
}
# Verdict Execution time Memory Grader output
1 Correct 54 ms 4676 KB Output is correct
2 Incorrect 779 ms 85912 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 46 ms 4668 KB Output is correct
2 Incorrect 748 ms 85956 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 46 ms 4668 KB Output is correct
2 Incorrect 748 ms 85956 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 46 ms 4668 KB Output is correct
2 Incorrect 748 ms 85956 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 54 ms 4676 KB Output is correct
2 Incorrect 779 ms 85912 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 54 ms 4676 KB Output is correct
2 Incorrect 779 ms 85912 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 54 ms 4676 KB Output is correct
2 Incorrect 779 ms 85912 KB Output isn't correct
3 Halted 0 ms 0 KB -