Submission #530344

#TimeUsernameProblemLanguageResultExecution timeMemory
530344byunjaewoo기지국 (IOI20_stations)C++17
100 / 100
877 ms784 KiB
#include "stations.h" #include <bits/stdc++.h> using namespace std; const int Nmax=1010; int N, K, Size[Nmax], Dep[Nmax]; vector<int> adj[Nmax], L; void DFS_Size(int curr, int prev) { Size[curr]=1; for(int next:adj[curr]) if(next!=prev) { Dep[next]=Dep[curr]+1; DFS_Size(next, curr); Size[curr]+=Size[next]; } } void DFS_Label(int curr, int prev, int s, int e) { if(Dep[curr]%2) L[curr]=s++; else L[curr]=e--; for(int next:adj[curr]) if(next!=prev) { DFS_Label(next, curr, s, s+Size[next]-1); s+=Size[next]; } } vector<int> label(int n, int k, vector<int> u, vector<int> v) { for(int i=0; i<N; i++) adj[i].clear(), Size[i]=Dep[i]=0; N=n, K=k; for(int i=0; i<N-1; i++) { adj[u[i]].push_back(v[i]); adj[v[i]].push_back(u[i]); } DFS_Size(0, -1); L.clear(); L.resize(N); DFS_Label(0, -1, 0, N-1); return L; } int find_next_station(int s, int t, vector<int> c) { for(int i:c) if(i==t) return i; if(c.size()==1) return c[0]; if(c[0]>s) { if(t<s || t>c[c.size()-2]) return c.back(); else return (*lower_bound(c.begin(), c.end(), t)); } else { if(t<c[0] || t>s) return c[0]; else return (*(lower_bound(c.begin(), c.end(), t)-1)); } }
#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...