Submission #260786

#TimeUsernameProblemLanguageResultExecution timeMemory
260786updown1Tales of seafaring (POI13_mor)C++17
60 / 100
2447 ms102804 KiB
/* Code by @marlov */ #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> pi; #define maxN 5005 const short INF = 30000; int N,M,K; vector<int> adj[maxN]; //from u to v min even and min odd short dist[maxN][maxN][2]; void bfs(int p){ queue< pair<int,int> > q; dist[p][p][0]=0; q.push(make_pair(p,0)); while(!q.empty()){ int cn=q.front().first; int cd=q.front().second; q.pop(); assert(cd < INF); for(int i=0;i<adj[cn].size();i++){ int nn=adj[cn][i]; if(dist[p][nn][(cd+1)%2]>cd+1){ dist[p][nn][(cd+1)%2]=cd+1; q.push(make_pair(nn,cd+1)); } } } } 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++){ bfs(i); } int a,b,d; for(int i=0;i<K;i++){ cin>>a>>b>>d; a--; b--; if(dist[a][b][d%2]<=min(INF-1, 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 */

Compilation message (stderr)

mor.cpp: In function 'void bfs(int)':
mor.cpp:26:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i=0;i<adj[cn].size();i++){
               ~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...