Skip to content

Commit 256ce49

Browse files
committed
Add olinfo task police: 100/100
simple graph
1 parent b9b7b7d commit 256ce49

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

olinfo/police/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# [Police Investigation (police)](https://training.olinfo.it/#/task/ois_police/statement)
2+
Score: 100/100

olinfo/police/main.cpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#pragma GCC optimize ("O3")
2+
#include <bits/stdc++.h>
3+
using namespace std;
4+
5+
#define int int64_t
6+
#define float long double
7+
8+
ifstream in{"input.txt"};
9+
ofstream out{"output.txt"};
10+
#ifdef DEBUG
11+
template<class A,class B>ostream&operator<<(ostream&o,const pair<A,B>&p){cout<<"("<<p.first<<", "<<p.second<<")";return o;}
12+
template<class T,typename=typename enable_if<!is_same<T, string>::value,decltype(*begin(declval<T>()))>::type>ostream&operator<<(ostream&o,const T&v){cout<<"[";for(auto it=v.begin();it!=v.end();++it){if(it!=v.begin()){cout<<", ";}cout<<*it;}cout<<"]";return o;}
13+
void deb(){cout<<"\n";}template<class T,class...Ts>void deb(const T&t,const Ts&...args){cout<<t;if(sizeof...(args)!=0){cout<<" ";}deb(args...);}
14+
#else
15+
#define deb(...)
16+
#endif
17+
18+
signed main() {
19+
int N,K;
20+
in>>N>>K;
21+
K--;
22+
23+
vector<int> V(N);
24+
for(int n=0;n<N;++n){
25+
in>>V[n];
26+
V[n]--;
27+
}
28+
29+
int cnt=0;
30+
vector<bool> vis(N, false);
31+
32+
int cur=0;
33+
while(cur != K && vis[cur] == false) {
34+
vis[cur] = true;
35+
cur = V[cur];
36+
++cnt;
37+
}
38+
39+
if (cur != K) {
40+
cnt=-1;
41+
}
42+
out<<cnt<<endl;
43+
}

0 commit comments

Comments
 (0)