Submission #616187

#TimeUsernameProblemLanguageResultExecution timeMemory
616187John3_141592Stations (IOI20_stations)C++14
5 / 100
967 ms672 KiB
#include "stations.h" #include <bits/stdc++.h> using namespace std; vector <int> grafo[1003]; map <int,bool> mapa; int arr[1003]; bool vis[1003]; void dfs1(int node,int c){ vis[node]=true,arr[node]=c; for(auto i:grafo[node]) if(!vis[i]) dfs1(i,c+1); } void dfs2(int node,int c){ vis[node]=true,arr[node]=c; for(auto i:grafo[node]) if(!vis[i]) dfs2(i,c-1); } std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) { if(n==2){ vector <int> vec; vec.push_back(0); vec.push_back(1); return vec; } mapa.clear(); for(int i=0;i<n;i++) grafo[i].clear(); for(int i=0;i<n-1;i++){ grafo[u[i]].push_back(v[i]); grafo[v[i]].push_back(u[i]); } int a=-1,b=-1,c=-1; for(int i=0;i<n;i++){ if(grafo[i].size()==1){ if(a==-1) a=i; else b=i; } if(grafo[i].size()>2) c=i; } if(c==-1) c=grafo[a][0]; else{ for(auto i:grafo[c]) mapa[i]=true; a=-1,b=-1; for(int i=0;i<n;i++){ if(grafo[i].size()==1 && !mapa.count(i)){ if(a==-1) a=i; else b=i; } } if(a==-1){ for(auto i:grafo[c]){ if(grafo[i].size()!=1) continue; if(a==-1) a=i; else b=i; } } else if(b==-1){ for(auto i:grafo[c]){ if(grafo[i].size()!=1) continue; if(b==-1) b=i; } } } fill(arr,arr+n+1,0); fill(vis,vis+n+1,false); vis[c]=true; int aux=0; dfs1(a,0); for(int i=0;i<n;i++) if(vis[i] && i!=c) aux++; dfs2(b,n-1); arr[c]=aux++; for(int i=0;i<n;i++) if(!vis[i]) arr[i]=aux++; vector <int> solve; for(int i=0;i<n;i++) solve.push_back(arr[i]); return solve; } int find_next_station(int s, int t, std::vector<int> c) { if(c.size()==1) return c[0]; if(c.size()==2){ if(s<t) return c[1]; return c[0]; } bool band=false; for(auto i:c) if(t==i) band=true; if(band) return t; if(s<t) return c.back(); return c[0]; }
#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...