Submission #576224

# Submission time Handle Problem Language Result Execution time Memory
576224 2022-06-12T14:37:46 Z jiahng From Hacks to Snitches (BOI21_watchmen) C++14
0 / 100
114 ms 89552 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
//~ #define ll int
#define int ll
typedef pair<int32_t, int32_t> pi;
typedef vector <int> vi;
typedef vector <pi> vpi;
typedef pair<pi, ll> pii;
typedef set <ll> si;
typedef long double ld;
#define f first
#define s second
#define mp make_pair
#define FOR(i,s,e) for(int i=s;i<=int(e);++i)
#define DEC(i,s,e) for(int i=s;i>=int(e);--i)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
#define aFOR(i,x) for (auto i: x)
#define mem(x,i) memset(x,i,sizeof x)
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define maxn 120001
#define INF 1e9
#define MOD 1000000007
typedef pair <vi, int> pvi;
typedef pair <int,pi> ipi;
typedef vector <pii> vpii;

int N,M,K;
int a,b;
vpi adj[maxn];

int spec[maxn], t[maxn],L[maxn];
bool vis[maxn];
queue <int> Q[maxn];

int32_t main(){
    fast;
    cin >> N >> M;
    FOR(i,1,M){
		cin >> a >> b;
		adj[a].pb(pi(b, i)); adj[b].pb(pi(a,i));
	}
	mem(spec, -1);
	cin >> K;
	FOR(i,1,K){
		cin >> L[i];
		FOR(j,0,L[i]-1){
			cin >> a;
			spec[a] = i;
			t[a] = j;
		}
	}
//~ return 0;
	Q[0].push(1);
	FOR(d,0,M){
		//~ cout << "DIST: " << d << '\n';
		while (!Q[d].empty()){
			int cur = Q[d].front(); Q[d].pop();
			//~ cout << cur << ' ';
			if (cur == N){
				cout << d; return 0;
			}
			aFOR(i,adj[cur]) if (!vis[i.s]){
				if (spec[i.f] == -1 || t[i.f] != (d + 1) % L[spec[i.f]]){
					if (spec[cur] == -1 || spec[i.f] == -1 || spec[cur] != spec[i.f] || t[i.f] != d % L[spec[i.f]] || t[cur] != (d + 1) % L[spec[cur]]){
						vis[i.s] = 1;
						Q[d+1].push(i.f);
					}
				}
				if (!vis[i.s]){
					if (spec[cur] == -1 || t[cur] != (d + 1) % L[spec[cur]]){
						vis[i.s] = 1; Q[d+2].push(i.f);
					}
				}
			
			}
		}
		
		//~ cout << "\n";
	}
	cout << "impossible";
}
# Verdict Execution time Memory Grader output
1 Correct 83 ms 87764 KB Output is correct
2 Incorrect 114 ms 89552 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 72 ms 87776 KB Output is correct
2 Incorrect 114 ms 89520 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 72 ms 87776 KB Output is correct
2 Incorrect 114 ms 89520 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 72 ms 87776 KB Output is correct
2 Incorrect 114 ms 89520 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 83 ms 87764 KB Output is correct
2 Incorrect 114 ms 89552 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 83 ms 87764 KB Output is correct
2 Incorrect 114 ms 89552 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 83 ms 87764 KB Output is correct
2 Incorrect 114 ms 89552 KB Output isn't correct
3 Halted 0 ms 0 KB -