Submission #947845

# Submission time Handle Problem Language Result Execution time Memory
947845 2024-03-17T06:24:12 Z willychan From Hacks to Snitches (BOI21_watchmen) C++17
0 / 100
313 ms 8760 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include<bits/extc++.h>
//__gnu_pbds
int l;
int n,m;
int mp(int c,int x){
	x%=l;
	return (n*x+c);
}


int main(){
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	cin>>n>>m;
	vector<vector<int>> side(n);
	for(int i=0;i<m;i++){
		int a,b;cin>>a>>b;
		a--;
		b--;
		side[a].push_back(b);
		side[b].push_back(a);
	}
	int k;cin>>k;
	if(k>1) return 0;
	cin>>l;
	vector<int> node(l);
	for(int i=0;i<l;i++) cin>>node[i];
	vector<bool> vis(n*l);
	for(int i=0;i<l;i++){
		vis[mp(node[i]-1,i)]=1;
	}
	queue<pair<int,int> > q;	
	q.push({mp(0,0),0});
	vis[0]=1;
	while(q.size())	{
		auto cur =q.front();
		q.pop();
		if((cur.first%n)==(n-1)){
			cout<<cur.second<<"\n";
			return 0;
		}
		int u = cur.first%n;
		int t = cur.first/n;
		if(!vis[mp(u,t+1)]){
			vis[mp(u,t+1)]=1;
			q.push({mp(u,t+1),cur.second+1});
		}
		for(auto i : side[u]){
			if(!vis[mp(i,t+1)]){
				vis[mp(i,t+1)]=1;
				q.push({mp(i,t+1),cur.second+1});
			}
		}
	}
	cout<<"impossible\n";

	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 13 ms 1880 KB Output is correct
2 Incorrect 307 ms 8608 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 13 ms 1744 KB Output is correct
2 Incorrect 313 ms 8760 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 13 ms 1744 KB Output is correct
2 Incorrect 313 ms 8760 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 13 ms 1744 KB Output is correct
2 Incorrect 313 ms 8760 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 13 ms 1880 KB Output is correct
2 Incorrect 307 ms 8608 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 13 ms 1880 KB Output is correct
2 Incorrect 307 ms 8608 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 13 ms 1880 KB Output is correct
2 Incorrect 307 ms 8608 KB Output isn't correct
3 Halted 0 ms 0 KB -