#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int>ii;
const int maxn=1e5+10;
vector<ii>adj[5*maxn];
int visitado[5*maxn];
int n,m;
void bfs(int x){
visitado[x]=0;
priority_queue<ii,vector<ii>,greater<ii>> fila;
fila.push({0,x});
while(!fila.empty()){
int atual=fila.top().second,dist=fila.top().first;
fila.pop();
if(visitado[atual]!=-1 and dist>visitado[atual]) continue;
visitado[atual]=dist;
if(visitado[atual]>1)continue;
for(int i=0; i<adj[atual].size(); i++){
int viz=adj[atual][i].first, d=adj[atual][i].second;
if(dist+d>1)continue;
else if(visitado[viz]==-1 and dist+d<=1){
visitado[viz]=d+dist;
fila.push({d+dist,viz});
}
else if(visitado[viz]>dist+d){
visitado[viz]=dist+d;
fila.push({d+dist,viz});
}
}
}
return;
}
int main(){
cin >> n>> m;
for(int i=0; i<m; i++){
int a,b;
char c;
cin >> a >> b >> c;
if(c=='T'){
adj[a].push_back({b,0});
adj[b].push_back({a,0});
}
else{
adj[a].push_back({b,1});
adj[b].push_back({a,1});
}
}
int res=0;
for(int i=1; i<=n; i++){
for(int j=0; j<=n; j++) visitado[j]=-1;
bfs(i);
int ok=1;
for(int j=1; j<=n; j++){
if(visitado[j]==-1 or visitado[j]>1){
ok=0;
break;
}
}
//if(ok)cout << i<<endl;
//cout << ok<<endl;
res+=ok;
}
cout << res<<endl;
return 0;
}
Compilation message
menesinis_bilietas.cpp: In function 'void bfs(int)':
menesinis_bilietas.cpp:22:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
22 | for(int i=0; i<adj[atual].size(); i++){
| ~^~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3093 ms |
29920 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3048 ms |
13780 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
11988 KB |
Output is correct |
2 |
Correct |
6 ms |
11984 KB |
Output is correct |
3 |
Correct |
10 ms |
12116 KB |
Output is correct |
4 |
Correct |
22 ms |
12184 KB |
Output is correct |
5 |
Correct |
44 ms |
12304 KB |
Output is correct |
6 |
Correct |
21 ms |
12220 KB |
Output is correct |
7 |
Correct |
7 ms |
11988 KB |
Output is correct |
8 |
Correct |
7 ms |
11988 KB |
Output is correct |
9 |
Correct |
27 ms |
12372 KB |
Output is correct |
10 |
Correct |
7 ms |
11988 KB |
Output is correct |
11 |
Correct |
9 ms |
12116 KB |
Output is correct |
12 |
Correct |
6 ms |
11988 KB |
Output is correct |
13 |
Correct |
8 ms |
12116 KB |
Output is correct |
14 |
Correct |
8 ms |
12108 KB |
Output is correct |
15 |
Correct |
40 ms |
12116 KB |
Output is correct |
16 |
Correct |
10 ms |
11988 KB |
Output is correct |
17 |
Correct |
8 ms |
12092 KB |
Output is correct |
18 |
Correct |
7 ms |
11988 KB |
Output is correct |
19 |
Correct |
12 ms |
12060 KB |
Output is correct |
20 |
Correct |
19 ms |
12256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
11988 KB |
Output is correct |
2 |
Correct |
6 ms |
11984 KB |
Output is correct |
3 |
Correct |
10 ms |
12116 KB |
Output is correct |
4 |
Correct |
22 ms |
12184 KB |
Output is correct |
5 |
Correct |
44 ms |
12304 KB |
Output is correct |
6 |
Correct |
21 ms |
12220 KB |
Output is correct |
7 |
Correct |
7 ms |
11988 KB |
Output is correct |
8 |
Correct |
7 ms |
11988 KB |
Output is correct |
9 |
Correct |
27 ms |
12372 KB |
Output is correct |
10 |
Correct |
7 ms |
11988 KB |
Output is correct |
11 |
Correct |
9 ms |
12116 KB |
Output is correct |
12 |
Correct |
6 ms |
11988 KB |
Output is correct |
13 |
Correct |
8 ms |
12116 KB |
Output is correct |
14 |
Correct |
8 ms |
12108 KB |
Output is correct |
15 |
Correct |
40 ms |
12116 KB |
Output is correct |
16 |
Correct |
10 ms |
11988 KB |
Output is correct |
17 |
Correct |
8 ms |
12092 KB |
Output is correct |
18 |
Correct |
7 ms |
11988 KB |
Output is correct |
19 |
Correct |
12 ms |
12060 KB |
Output is correct |
20 |
Correct |
19 ms |
12256 KB |
Output is correct |
21 |
Correct |
205 ms |
12956 KB |
Output is correct |
22 |
Execution timed out |
3070 ms |
22224 KB |
Time limit exceeded |
23 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
11988 KB |
Output is correct |
2 |
Correct |
6 ms |
11984 KB |
Output is correct |
3 |
Correct |
10 ms |
12116 KB |
Output is correct |
4 |
Correct |
22 ms |
12184 KB |
Output is correct |
5 |
Correct |
44 ms |
12304 KB |
Output is correct |
6 |
Correct |
21 ms |
12220 KB |
Output is correct |
7 |
Correct |
7 ms |
11988 KB |
Output is correct |
8 |
Correct |
7 ms |
11988 KB |
Output is correct |
9 |
Correct |
27 ms |
12372 KB |
Output is correct |
10 |
Correct |
7 ms |
11988 KB |
Output is correct |
11 |
Correct |
9 ms |
12116 KB |
Output is correct |
12 |
Correct |
6 ms |
11988 KB |
Output is correct |
13 |
Correct |
8 ms |
12116 KB |
Output is correct |
14 |
Correct |
8 ms |
12108 KB |
Output is correct |
15 |
Correct |
40 ms |
12116 KB |
Output is correct |
16 |
Correct |
205 ms |
12956 KB |
Output is correct |
17 |
Execution timed out |
3070 ms |
22224 KB |
Time limit exceeded |
18 |
Halted |
0 ms |
0 KB |
- |