이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/*
Code by @marlov
*/
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <utility>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>
#include <iterator>
using namespace std;
typedef long long ll;
typedef pair<int,int> pi;
#define maxN 5005
#define INF 100000000
int N,M,K;
vector<int> adj[maxN];
//from u to v min even and min odd
int dist[maxN][maxN][2];
void dfs(int cn,int cd,int p){
for(int i=0;i<adj[cn].size();i++){
int nn=adj[cn][i];
if(nn!=p&&cd+1<dist[p][nn][(cd+1)%2]){
dist[p][nn][(cd+1)%2]=cd+1;
dfs(nn,cd+1,p);
}
}
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
for(int i=0;i<maxN;i++){
for(int j=0;j<maxN;j++){
if(i!=j){
dist[i][j][0]=INF;
dist[i][j][1]=INF;
}
}
}
cin>>N>>M>>K;
int u,v;
for(int i=0;i<M;i++){
cin>>u>>v;
u--;
v--;
adj[u].push_back(v);
adj[v].push_back(u);
}
for(int i=0;i<N;i++){
dfs(i,0,i);
}
int a,b,d;
for(int i=0;i<K;i++){
cin>>a>>b>>d;
a--;
b--;
if(dist[a][b][d%2]<=d){
cout<<"TAK"<<'\n';
}else{
cout<<"NIE"<<"\n";
}
}
return 0;
}
/* stuff you should look for
* int overflow, array bounds
* special cases (n=1,n=0?)
* do smth instead of nothing and stay organized
*/
컴파일 시 표준 에러 (stderr) 메시지
mor.cpp: In function 'void dfs(int, int, int)':
mor.cpp:34:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<adj[cn].size();i++){
~^~~~~~~~~~~~~~~
# | 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... |