#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define sc second
const int MAXN = 500005;
vector< pair<int,int> > adj[MAXN];
int qtd[MAXN], visQtd;
void dfs(int S, int o)
{
if(qtd[S]==-1)visQtd++;
qtd[S]=o;
for(int i = 0; i < (int)adj[S].size(); i++)
{
int viz = adj[S][i].fi, tipo = adj[S][i].sc;
if(qtd[viz]>=qtd[S])continue;
if(tipo==1)
{
if(o==0)continue;
dfs(viz,0);
}
else dfs(viz,o);
}
return;
}
int main()
{
int N,M; cin>>N>>M;
for(int i = 1; i <= M; i++)
{
char c; int x,y,t=0;
cin>>x>>y>>c;
if(c=='A')t=1;
adj[x].pb({y,t});
adj[y].pb({x,t});
}
int ans = 0;
for(int s = 1; s <= N; s++)
{
for(int i = 1; i <= N; i++)qtd[i]=-1;
visQtd=0;
dfs(s,1);
if(visQtd==N)ans++;
}
cout<<ans<<"\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3090 ms |
37364 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3088 ms |
13780 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
12016 KB |
Output is correct |
2 |
Correct |
6 ms |
12028 KB |
Output is correct |
3 |
Correct |
21 ms |
12152 KB |
Output is correct |
4 |
Correct |
38 ms |
12184 KB |
Output is correct |
5 |
Correct |
103 ms |
12248 KB |
Output is correct |
6 |
Correct |
34 ms |
12188 KB |
Output is correct |
7 |
Correct |
8 ms |
11988 KB |
Output is correct |
8 |
Correct |
8 ms |
12056 KB |
Output is correct |
9 |
Correct |
54 ms |
12356 KB |
Output is correct |
10 |
Correct |
7 ms |
11988 KB |
Output is correct |
11 |
Correct |
8 ms |
12064 KB |
Output is correct |
12 |
Correct |
7 ms |
11988 KB |
Output is correct |
13 |
Correct |
13 ms |
12068 KB |
Output is correct |
14 |
Correct |
10 ms |
11980 KB |
Output is correct |
15 |
Correct |
32 ms |
12128 KB |
Output is correct |
16 |
Correct |
6 ms |
12044 KB |
Output is correct |
17 |
Correct |
6 ms |
11988 KB |
Output is correct |
18 |
Correct |
7 ms |
11988 KB |
Output is correct |
19 |
Correct |
9 ms |
11988 KB |
Output is correct |
20 |
Correct |
15 ms |
12164 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
12016 KB |
Output is correct |
2 |
Correct |
6 ms |
12028 KB |
Output is correct |
3 |
Correct |
21 ms |
12152 KB |
Output is correct |
4 |
Correct |
38 ms |
12184 KB |
Output is correct |
5 |
Correct |
103 ms |
12248 KB |
Output is correct |
6 |
Correct |
34 ms |
12188 KB |
Output is correct |
7 |
Correct |
8 ms |
11988 KB |
Output is correct |
8 |
Correct |
8 ms |
12056 KB |
Output is correct |
9 |
Correct |
54 ms |
12356 KB |
Output is correct |
10 |
Correct |
7 ms |
11988 KB |
Output is correct |
11 |
Correct |
8 ms |
12064 KB |
Output is correct |
12 |
Correct |
7 ms |
11988 KB |
Output is correct |
13 |
Correct |
13 ms |
12068 KB |
Output is correct |
14 |
Correct |
10 ms |
11980 KB |
Output is correct |
15 |
Correct |
32 ms |
12128 KB |
Output is correct |
16 |
Correct |
6 ms |
12044 KB |
Output is correct |
17 |
Correct |
6 ms |
11988 KB |
Output is correct |
18 |
Correct |
7 ms |
11988 KB |
Output is correct |
19 |
Correct |
9 ms |
11988 KB |
Output is correct |
20 |
Correct |
15 ms |
12164 KB |
Output is correct |
21 |
Correct |
506 ms |
12932 KB |
Output is correct |
22 |
Execution timed out |
3059 ms |
21852 KB |
Time limit exceeded |
23 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
12016 KB |
Output is correct |
2 |
Correct |
6 ms |
12028 KB |
Output is correct |
3 |
Correct |
21 ms |
12152 KB |
Output is correct |
4 |
Correct |
38 ms |
12184 KB |
Output is correct |
5 |
Correct |
103 ms |
12248 KB |
Output is correct |
6 |
Correct |
34 ms |
12188 KB |
Output is correct |
7 |
Correct |
8 ms |
11988 KB |
Output is correct |
8 |
Correct |
8 ms |
12056 KB |
Output is correct |
9 |
Correct |
54 ms |
12356 KB |
Output is correct |
10 |
Correct |
7 ms |
11988 KB |
Output is correct |
11 |
Correct |
8 ms |
12064 KB |
Output is correct |
12 |
Correct |
7 ms |
11988 KB |
Output is correct |
13 |
Correct |
13 ms |
12068 KB |
Output is correct |
14 |
Correct |
10 ms |
11980 KB |
Output is correct |
15 |
Correct |
32 ms |
12128 KB |
Output is correct |
16 |
Correct |
506 ms |
12932 KB |
Output is correct |
17 |
Execution timed out |
3059 ms |
21852 KB |
Time limit exceeded |
18 |
Halted |
0 ms |
0 KB |
- |