# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
203294 | MKopchev | Tales of seafaring (POI13_mor) | C++14 | 2182 ms | 27384 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
const int nmax=5e3+42,kmax=1e6+42,inf=1e9+42;
int n,m,k;
vector<int> adj[nmax];
struct query
{
int from,to,dist,id;
};
query inp[kmax];
bool cmp(query a,query b)
{
return a.from<b.from;
}
bool output[kmax];
int dist[nmax][2];
queue< pair<int,bool> > active;
void bfs(int start)
{
for(int i=1;i<=n;i++)
{
dist[i][0]=inf;
dist[i][1]=inf;
}
active.push({start,0});
dist[start][0]=0;
while(active.size())
{
pair<int,bool> current=active.front();
active.pop();
int node=current.first;
bool type=current.second;
//cout<<node<<" "<<type<<" "<<dist[node][type]<<endl;
for(auto k:adj[node])
if(dist[node][type]+1<dist[k][!type])
{
dist[k][!type]=dist[node][type]+1;
active.push({k,!type});
}
}
}
int main()
{
scanf("%i%i%i",&n,&m,&k);
int u,v;
for(int i=1;i<=m;i++)
{
scanf("%i%i",&u,&v);
adj[u].push_back(v);
adj[v].push_back(u);
}
for(int i=1;i<=k;i++)
{
scanf("%i%i%i",&inp[i].from,&inp[i].to,&inp[i].dist);
inp[i].id=i;
}
sort(inp+1,inp+k+1,cmp);
int pointer=1;
for(int i=1;i<=n;i++)
{
bfs(i);
while(inp[pointer].from==i)
{
if(dist[inp[pointer].to][inp[pointer].dist%2]<=inp[pointer].dist)
{
if(dist[inp[pointer].to][inp[pointer].dist%2]==0&&adj[inp[pointer].to].size()==0)output[inp[pointer].id]=0;
else output[inp[pointer].id]=1;
}
pointer++;
}
}
for(int i=1;i<=k;i++)
if(output[i])printf("TAK\n");
else printf("NIE\n");
return 0;
}
Compilation message (stderr)
# | 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... |