#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define ll long long
#define itr ::iterator
typedef pair<int,int> pii;
const int MAX=1e5;
vector<int> cur,vec[MAX];
int N,edge,mark[MAX];
void Init(int N_)
{
N=N_;
for(int A=0;A<N;A++)
{
mark[A]=0;
vec[A].clear();
}
return ;
}
void Link(int A,int B)
{
//A++;
//B++;
vec[A].pb(B);
vec[B].pb(A);
return ;
}
void dfs(int node,int br)
{
cur.pb(node);
mark[node]=1;
for(auto A:vec[node])
{
if(A==br)
continue;
//cout<<"edge between "<<node<<" "<<A<<"\n";
edge++;
if(mark[A])
continue;
dfs(A,br);
}
return ;
}
int ok(int X)
{
for(auto A:cur)
{
if(vec[A].size()==3)
{
if(vec[A][0]!=X and vec[A][1]!=X and vec[A][2]!=X)
return 0;
}
else if(vec[A].size()>3)
return 0;
}
return 1;
}
int CountCritical()
{
int res=0,l;
for(int A=0;A<N;A++)
{
l=1;
for(int B=0;B<N;B++)
mark[B]=0;
for(int B=0;B<N and l==1;B++)
{
if(!mark[B] and (A!=B))
{
cur.clear();
edge=0;
dfs(B,A);
//cout<<"removing "<<A<<" component of "<<B<<" ed "<<edge<<" "<<cur.size()<<"\n";
//for(auto A:cur)
// cout<<"cuurent "<<A<<" ";
//cout<<"\n";
if(edge/2>=cur.size())
l=0;
else if(!ok(A))
l=0;
}
}
res+=l;
}
return res;
}
/*signed main()
{
ios_base::sync_with_stdio(false);
Init(7);
cout<<CountCritical()<<"\n";
Link(1,2);
cout<<CountCritical()<<"\n";
Link(0,5);
cout<<CountCritical()<<"\n";
Link(2,0);
cout<<CountCritical()<<"\n";
Link(3,2);
cout<<CountCritical()<<"\n";
Link(3,5);
cout<<CountCritical()<<"\n";
Link(4,3);
cout<<CountCritical()<<"\n";
return 0;
}*/
Compilation message
rings.cpp: In function 'int CountCritical()':
rings.cpp:88:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(edge/2>=cur.size())
~~~~~~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
2652 KB |
Output is correct |
2 |
Correct |
164 ms |
2992 KB |
Output is correct |
3 |
Correct |
473 ms |
3144 KB |
Output is correct |
4 |
Correct |
12 ms |
3144 KB |
Output is correct |
5 |
Correct |
232 ms |
3180 KB |
Output is correct |
6 |
Correct |
1006 ms |
3220 KB |
Output is correct |
7 |
Correct |
23 ms |
3220 KB |
Output is correct |
8 |
Correct |
91 ms |
3220 KB |
Output is correct |
9 |
Correct |
519 ms |
3268 KB |
Output is correct |
10 |
Correct |
149 ms |
3268 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
7 ms |
6340 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
2652 KB |
Output is correct |
2 |
Correct |
164 ms |
2992 KB |
Output is correct |
3 |
Correct |
473 ms |
3144 KB |
Output is correct |
4 |
Correct |
12 ms |
3144 KB |
Output is correct |
5 |
Correct |
232 ms |
3180 KB |
Output is correct |
6 |
Correct |
1006 ms |
3220 KB |
Output is correct |
7 |
Correct |
23 ms |
3220 KB |
Output is correct |
8 |
Correct |
91 ms |
3220 KB |
Output is correct |
9 |
Correct |
519 ms |
3268 KB |
Output is correct |
10 |
Correct |
149 ms |
3268 KB |
Output is correct |
11 |
Execution timed out |
4059 ms |
6340 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
2652 KB |
Output is correct |
2 |
Correct |
164 ms |
2992 KB |
Output is correct |
3 |
Correct |
473 ms |
3144 KB |
Output is correct |
4 |
Correct |
12 ms |
3144 KB |
Output is correct |
5 |
Correct |
232 ms |
3180 KB |
Output is correct |
6 |
Correct |
1006 ms |
3220 KB |
Output is correct |
7 |
Correct |
23 ms |
3220 KB |
Output is correct |
8 |
Correct |
91 ms |
3220 KB |
Output is correct |
9 |
Correct |
519 ms |
3268 KB |
Output is correct |
10 |
Correct |
149 ms |
3268 KB |
Output is correct |
11 |
Execution timed out |
4059 ms |
6340 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
2652 KB |
Output is correct |
2 |
Correct |
164 ms |
2992 KB |
Output is correct |
3 |
Correct |
473 ms |
3144 KB |
Output is correct |
4 |
Correct |
12 ms |
3144 KB |
Output is correct |
5 |
Correct |
232 ms |
3180 KB |
Output is correct |
6 |
Correct |
1006 ms |
3220 KB |
Output is correct |
7 |
Correct |
23 ms |
3220 KB |
Output is correct |
8 |
Correct |
91 ms |
3220 KB |
Output is correct |
9 |
Correct |
519 ms |
3268 KB |
Output is correct |
10 |
Correct |
149 ms |
3268 KB |
Output is correct |
11 |
Runtime error |
7 ms |
6340 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
12 |
Halted |
0 ms |
0 KB |
- |