답안 #424884

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
424884 2021-06-12T11:13:39 Z patrikpavic2 From Hacks to Snitches (BOI21_watchmen) C++17
0 / 100
112 ms 42592 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[3 * 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 < 3;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);
      |           ~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 60 ms 33956 KB Output is correct
2 Incorrect 110 ms 42592 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 48 ms 34008 KB Output is correct
2 Incorrect 112 ms 42492 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 48 ms 34008 KB Output is correct
2 Incorrect 112 ms 42492 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 48 ms 34008 KB Output is correct
2 Incorrect 112 ms 42492 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 60 ms 33956 KB Output is correct
2 Incorrect 110 ms 42592 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 60 ms 33956 KB Output is correct
2 Incorrect 110 ms 42592 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 60 ms 33956 KB Output is correct
2 Incorrect 110 ms 42592 KB Output isn't correct
3 Halted 0 ms 0 KB -