이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <algorithm>
#include <cassert>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> plli;
typedef vector<vector<ll>> matrix;
vector<int> edges[5000];
short dp[5000][5000][2];
int n;
const short INF = 30000;
void init() {
for(int s = 0; s < n; s++) {
for(int t = 0; t < n; t++) {
dp[s][t][0] = INF;
dp[s][t][1] = INF;
}
queue<int> q;
for(int out: edges[s]) {
dp[s][out][1] = 1;
q.push(out);
}
while(!q.empty()) {
int t = q.front();
q.pop();
for(int out: edges[t]) {
bool upd = false;
if(dp[s][out][1] > dp[s][t][0] + 1) {
dp[s][out][1] = dp[s][t][0] + 1;
upd = true;
}
if(dp[s][out][0] > dp[s][t][1] + 1) {
dp[s][out][0] = dp[s][t][1] + 1;
upd = true;
}
if(upd) q.push(out);
}
}
}
}
void solve() {
int m, q;
cin >> n >> m >> q;
while(m--) {
int a, b;
cin >> a >> b;
a--;
b--;
edges[a].push_back(b);
edges[b].push_back(a);
}
init();
while(q--) {
int a, b, w;
cin >> a >> b >> w;
a--;
b--;
if(dp[a][b][w%2] == INF) cout << "NIE\n";
else if(dp[a][b][w%2] <= w) cout << "TAK\n";
else cout << "NIE\n";
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
/*
int t;
cin >> t;
for(int i = 1; i <= t; i++) {
cout << "Case #" << i << ": ";
solve();
}
*/
solve();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |