Submission #244519

#TimeUsernameProblemLanguageResultExecution timeMemory
244519errorgornPotemkin cycle (CEOI15_indcyc)C++14
100 / 100
207 ms7288 KiB
//雪花飄飄北風嘯嘯 //天地一片蒼茫 #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; int am[1005][1005]; //id of each edge vector<int> al[100005]; //this is actually storing the edges adjacentcy bool vis[100005]; bool instack[100005]; vector<int> ans; int root; bool dfs(int i,int j){ int id=am[i][j]; if (vis[id]) return false; vis[id]=true; instack[id]=true; rep(x,1,n+1) if (x!=i && //dont go back to parent am[j][x] && am[i][x]==0){ //make sure that i,j,x is not triangle if (instack[am[j][x]]){ //this is confirm not cycle of length 3 root=j; ans.push_back(i); return true; } else if (dfs(j,x)){ ans.push_back(i); if (i==root){//we have reached the start of the cycle int s=0,e=sz(ans)-1; //rep(x,s,e+1) cout<<ans[x]<<" ";cout<<endl; for (int x=0;x<sz(ans);x++){ for (int y=x+2;y<sz(ans);y++){ if (am[ans[x]][ans[y]] && e-s>y-x){ s=x,e=y; } } } rep(x,s,e+1) cout<<ans[x]<<" "; exit(0); } return true; } } instack[id]=false; return false; } int main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin>>n>>m; int a,b; rep(x,1,m+1){ cin>>a>>b; am[a][b]=am[b][a]=x; } rep(x,1,n+1) rep(y,1,n+1) if (am[x][y] && !vis[am[x][y]]){ dfs(x,y); } cout<<"no"<<endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...