Submission #244076

# Submission time Handle Problem Language Result Execution time Memory
244076 2020-07-02T14:43:41 Z errorgorn Potemkin cycle (CEOI15_indcyc) C++14
50 / 100
1000 ms 2688 KB
//雪花飄飄北風嘯嘯
//天地一片蒼茫

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
#define ll long long
#define ii pair<ll,ll>
#define iii pair<ii,ll>
#define fi first
#define se second
#define endl '\n'
#define debug(x) cout << #x << " is " << x << endl;

#define rep(x,start,end) for(auto x=(start)-((start)>(end));x!=(end)-((start)>(end));((start)<(end)?x++:x--))
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()

ll MAX(ll a){return a;}
ll MIN(ll a){return a;}
template<typename... Args>
ll MAX(ll a,Args... args){return max(a,MAX(args...));}
template<typename... Args>
ll MIN(ll a,Args... args){return min(a,MIN(args...));}

#define indexed_set tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>

mt19937 rng(chrono::system_clock::now().time_since_epoch().count());

int n,m;
vector<int> al[1005];
bool am[1005][1005]; //bruh

int A,B;

bool vis[1005];
vector<int> stk;

bool dfs(int i){
	if (vis[i]) return false;
	vis[i]=true;
	if (am[i][A] && am[i][B]) return false;
	stk.push_back(i);
	if (i==B) return true;
	
	for (auto &it:al[i]){
		if (i==A && it==B) continue;
		if (dfs(it)) return true;
	}
	
	stk.pop_back();
	
	return false;
}

void test(int i,int j){
	memset(vis,false,sizeof(vis));
	stk.clear();
	
	A=i,B=j;
	if (dfs(i)){
		//cout<<i<<" "<<j<<endl;
		//for (auto &it:stk) cout<<it<<" ";cout<<endl;
		
		for (int x=0;x<sz(stk);x++){
			for (int y=x+2;y<sz(stk)-1;y++){
				//cout<<"debug: "<<x<<" "<<y<<endl;
				if (am[stk[x]][stk[y]]){
					stk.erase(stk.begin()+x+1,stk.begin()+y);
					y=x+2;
				}
			}
		}
		
		for (auto &it:stk) cout<<it<<" "; cout<<endl;
		exit(0);
	}
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	cin>>n>>m;
	
	int a,b;
	while (m--){
		cin>>a>>b;
		
		am[a][b]=am[b][a]=true;
		al[a].push_back(b);
		al[b].push_back(a);
	}
	
	rep(x,1,n+1) rep(y,x+1,n+1) if (am[x][y]) test(x,y);
	
	cout<<"no"<<endl;
}

Compilation message

indcyc.cpp: In function 'void test(int, int)':
indcyc.cpp:79:3: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   for (auto &it:stk) cout<<it<<" "; cout<<endl;
   ^~~
indcyc.cpp:79:37: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   for (auto &it:stk) cout<<it<<" "; cout<<endl;
                                     ^~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 256 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 512 KB Output is correct
2 Correct 9 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 49 ms 768 KB Output is correct
2 Incorrect 6 ms 768 KB Wrong adjacency
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 768 KB Wrong adjacency
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 118 ms 2304 KB Wrong adjacency
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 33 ms 1828 KB Output is correct
2 Execution timed out 1086 ms 1792 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Correct 66 ms 2432 KB Output is correct
2 Correct 287 ms 2552 KB Output is correct
3 Incorrect 437 ms 2688 KB Wrong adjacency
4 Halted 0 ms 0 KB -