# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
34363 | mohammad_kilani | Potemkin cycle (CEOI15_indcyc) | C++14 | 1000 ms | 2452 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;
#define mod 1000007
#define oo 2000000000
const int N = 1010;
bitset < N > connected[N] , con2[N] , vis , vis2;
bitset< N * N > bridge;
vector< pair<int,int> > g[N] ;
vector< int > g2[N];
int n , m , dfs_low[N], dfs_num[N] , cur = 0 ;
void DFS(int node){
vis[node] = true;
dfs_low[node] = dfs_num[node] = cur++;
for(int i=0;i<g[node].size();i++){
int newnode = g[node][i].first;
if(vis[newnode]) dfs_low[node] = min(dfs_low[node],dfs_num[node]);
else{
DFS(newnode);
dfs_low[node] = min(dfs_low[node],dfs_low[newnode]);
if(dfs_low[node] > dfs_low[newnode]){
bridge[g[node][i].second] = true;
}
}
}
}
void DFS2(vector<int> &v,int node){
vis2[node] = true;
v.push_back(node);
for(int i=0;i<g2[node].size();i++){
if(vis2[g2[node][i]] && v.size() >= 4){
return;
}
else if(vis2[g2[node][i]]) continue;
DFS2(v,g2[node][i]);
return;
}
}
int main() {
//freopen("in.txt","r",stdin);
scanf("%d%d",&n,&m);
for(int i=0;i<m;i++){
int u ,v ;
scanf("%d%d",&u,&v);
connected[u][v] = true;
connected[v][u] = true;
con2[u][v] = con2[v][u] = true;
}
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
for(int k=1;k<=n;k++){
if(i == j || j == k || i == k) continue;
if(connected[i][j] == 1&& connected[i][k] == 1&& connected[j][k] == 1){
con2[i][j] = con2[j][i] = con2[i][k] = con2[k][i] = con2[j][k] = con2[k][j] = 0;
}
}
}
}
int cnt = 0 ;
for(int i=1;i<=n;i++){
for(int j=i+1;j<=n;j++){
if(con2[i][j] == 1){
g[i].push_back(make_pair(j,cnt));
g[j].push_back(make_pair(i,cnt++));
}
}
}
for(int i=1;i<=n;i++){
if(!vis[i]) DFS(i);
}
for(int i=1;i<=n;i++){
for(int j=0;j<g[i].size();j++){
if(bridge[g[i][j].second]) continue;
g2[i].push_back(g[i][j].first);
}
}
vector<int> ans;
for(int i=1;i<=n;i++){
if(g2[i].size() > 0){
DFS2(ans,i);
break;
}
}
if(ans.size() == 0){
puts("no");
return 0;
}
for(int i=0;i<ans.size();i++) printf((i == 0 ? "%d" : " %d"),ans[i]);
puts("");
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... |