Submission #280354

# Submission time Handle Problem Language Result Execution time Memory
280354 2020-08-22T16:38:40 Z spdskatr Joker (BOI20_joker) C++14
0 / 100
266 ms 19064 KB
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <cassert>
#define fi first
#define se second

using namespace std;
typedef pair<int, int> pii;

int N, M, Q, seen[200005], col[200005];
vector<pii> graph[200005];

int dfs(int x, int r) {
	seen[x] = 1;
	for (pii p : graph[x]) {
		int v = p.fi, e = p.se;
		if (e <= r) {
			if (seen[v]) {
				if (col[v] == col[x]) return 1;
			} else {
				col[v] = !col[x];
				if (dfs(v, r)) return 1;
			}
		}
	}
	return 0;
}
int decide(int r) {
	for (int i = 1; i <= N; i++) if (!seen[i]) if (dfs(i, r)) return 1;
	return 0;
}

int main() {
	scanf("%d %d %d", &N, &M, &Q);
	for (int i = 1; i <= M; i++) {
		int a, b;
		scanf("%d %d", &a, &b);
		graph[a].push_back({ b, i });
		graph[b].push_back({ a, i });
	}
	int lo = 1, hi = M+2;
	while (lo + 1 < hi) {
		int mid = (lo + hi) / 2;
		memset(seen, 0, sizeof(seen));
		memset(col, 0, sizeof(col));
		if (decide(mid)) hi = mid;
		else lo = mid;
	}
	for (int q = 0; q < Q; q++) {
		int l, r;
		scanf("%d %d", &l, &r);
		assert(l == 1);
		if (r <= lo) printf("NO\n");
		else printf("YES\n");
	}
}

Compilation message

Joker.cpp: In function 'int main()':
Joker.cpp:37:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   37 |  scanf("%d %d %d", &N, &M, &Q);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Joker.cpp:40:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   40 |   scanf("%d %d", &a, &b);
      |   ~~~~~^~~~~~~~~~~~~~~~~
Joker.cpp:54:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   54 |   scanf("%d %d", &l, &r);
      |   ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 6528 KB Output is correct
2 Correct 5 ms 6528 KB Output is correct
3 Runtime error 13 ms 13056 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 6528 KB Output is correct
2 Correct 5 ms 6528 KB Output is correct
3 Runtime error 13 ms 13056 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 6528 KB Output is correct
2 Correct 5 ms 6528 KB Output is correct
3 Incorrect 266 ms 19064 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 6528 KB Output is correct
2 Correct 5 ms 6528 KB Output is correct
3 Runtime error 13 ms 13056 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 6528 KB Output is correct
2 Correct 5 ms 6528 KB Output is correct
3 Runtime error 13 ms 13056 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 6528 KB Output is correct
2 Correct 5 ms 6528 KB Output is correct
3 Runtime error 13 ms 13056 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -