Submission #424885

# Submission time Handle Problem Language Result Execution time Memory
424885 2021-06-12T11:14:13 Z patrikpavic2 From Hacks to Snitches (BOI21_watchmen) C++17
0 / 100
217 ms 109632 KB
#include <cstdio>
#include <vector>
#include <cstring>

#define PB push_back
#define X first
#define Y second

using namespace std;

const int N = 3e5 + 500;

int rit[N], kad[N], dis[N], tko[N];
vector < int > doso[10 * N], v[N];
int n, m;

bool dobar(int cv, int ds){
	if(!rit[cv]) return true;
	return ds % rit[cv] != kad[cv];
}

int main(){
	memset(dis, -1, sizeof(dis));
	scanf("%d%d", &n, &m);
	for(int i = 0;i < m;i++){
		int x, y; scanf("%d%d", &x, &y);
		v[x].PB(y), v[y].PB(x);
	}
	int q; scanf("%d", &q);
	for(;q--;){
		int ln; scanf("%d", &ln);
		for(int i = 0;i < ln;i++){
			int x; scanf("%d", &x);
			rit[x] = ln, kad[x] = i; tko[x] = q + 1;
		}
	}
	doso[0].PB(1);
	for(int i = 0;i < 3 * N;i++){
		for(int x : doso[i]){
			if(dis[x] != -1) continue;
			dis[x] = i; 
			for(int k = 0;k < 10;k++){
				if(!dobar(x, dis[x] + k)) break;
				for(int y : v[x]){
					if((tko[x] != tko[y] || !tko[x]) && dobar(y, dis[x] + k + 1))
						doso[dis[x] + k + 1].PB(y);
					if(tko[x] == tko[y] && dobar(y, dis[x] + k + 1) 
						&& !(kad[x] == (kad[y] + 1) % rit[x] && !dobar(y, dis[x] + k)))
						doso[dis[x] + k + 1].PB(y);
				}
			}
		}
	}
	if(dis[n] == -1)
		printf("impossible\n");
	else
		printf("%d\n", dis[n]);
	return 0;
}

Compilation message

watchmen.cpp: In function 'int main()':
watchmen.cpp:24:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |  scanf("%d%d", &n, &m);
      |  ~~~~~^~~~~~~~~~~~~~~~
watchmen.cpp:26:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |   int x, y; scanf("%d%d", &x, &y);
      |             ~~~~~^~~~~~~~~~~~~~~~
watchmen.cpp:29:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |  int q; scanf("%d", &q);
      |         ~~~~~^~~~~~~~~~
watchmen.cpp:31:16: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |   int ln; scanf("%d", &ln);
      |           ~~~~~^~~~~~~~~~~
watchmen.cpp:33:16: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |    int x; scanf("%d", &x);
      |           ~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 104 ms 89152 KB Output is correct
2 Incorrect 213 ms 109632 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 99 ms 89196 KB Output is correct
2 Incorrect 217 ms 109572 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 99 ms 89196 KB Output is correct
2 Incorrect 217 ms 109572 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 99 ms 89196 KB Output is correct
2 Incorrect 217 ms 109572 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 104 ms 89152 KB Output is correct
2 Incorrect 213 ms 109632 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 104 ms 89152 KB Output is correct
2 Incorrect 213 ms 109632 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 104 ms 89152 KB Output is correct
2 Incorrect 213 ms 109632 KB Output isn't correct
3 Halted 0 ms 0 KB -