답안 #315827

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
315827 2020-10-24T03:42:06 Z shrek12357 Tales of seafaring (POI13_mor) C++14
0 / 100
296 ms 131072 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <climits>
#include <cmath>
#include <fstream>
#include <queue>
#include <stack>
#include <bitset>
using namespace std;
#define ll long long
//cin.tie(0);ios_base::sync_with_stdio(0); 
 
const int MAXN = 4005;
 
vector<int> adjList[MAXN];
int paths[MAXN][MAXN][2];
 
int main() {
	cin.tie(0);ios_base::sync_with_stdio(0); 
	int n, m, k;
	cin >> n >> m >> k;
 
	for (int i = 0; i < 5005; i++) {
		for (int j = 0; j < 5005; j++) {
			paths[i][j][0] = INT_MAX;
			paths[i][j][1] = INT_MAX;
		}
	}
	for (int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		paths[a][a][0] = 0;
		paths[b][b][0] = 0;
		adjList[a].push_back(b);
		adjList[b].push_back(a);
	}
	queue<pair<int, int>> q;
	for (int i = 0; i < n; i++) {
		q.push({ i, 0 });
		while (q.size() > 0) {
			int cur = q.front().first;
			int num = q.front().second;
			q.pop();
			for (auto j : adjList[cur]) {
				if (paths[i][j][(num + 1) % 2] == -1 || paths[i][j][(num + 1) % 2] > num + 1) {
					q.push({ j, num + 1 });
					paths[i][j][(num + 1) % 2] = num + 1;
				}
			}
		}
 
	}
	for (int i = 0; i < k; i++) {
		int a, b, c;
		cin >> a >> b >> c;
		a--;
		b--;
		if (paths[a][b][c%2] == INT_MAX || c < paths[a][b][c % 2]) {
			cout << "NIE" << endl;
		}
		else {
			cout << "TAK" << endl;
		}
	}
	/*
	int a, b, d;
	for (int i = 0; i<k; i++) {
		cin >> a >> b >> d;
		a--;
		b--;
		if (paths[a][b][d % 2] != INT_MAX && paths[a][b][d % 2] <= d) {
			cout << "TAK" << '\n';
		}
		else {
			cout << "NIE" << "\n";
		}
	}
	*/
}

Compilation message

mor.cpp: In function 'int main()':
mor.cpp:29:19: warning: iteration 4005 invokes undefined behavior [-Waggressive-loop-optimizations]
   29 |    paths[i][j][0] = INT_MAX;
      |                   ^
mor.cpp:28:21: note: within this loop
   28 |   for (int j = 0; j < 5005; j++) {
      |                   ~~^~~~~~
mor.cpp:29:19: warning: iteration 4005 invokes undefined behavior [-Waggressive-loop-optimizations]
   29 |    paths[i][j][0] = INT_MAX;
      |                   ^
mor.cpp:27:20: note: within this loop
   27 |  for (int i = 0; i < 5005; i++) {
      |                  ~~^~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 296 ms 131072 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 286 ms 131072 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 287 ms 131072 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 288 ms 131072 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 288 ms 131072 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 289 ms 131072 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 284 ms 131072 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 290 ms 131072 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 283 ms 131072 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 288 ms 131072 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -