Submission #985414

#TimeUsernameProblemLanguageResultExecution timeMemory
985414sopaconkStations (IOI20_stations)C++17
100 / 100
593 ms1484 KiB
#include "stations.h" #include <vector> #include<bits/stdc++.h> using namespace std; #define pb push_back void dfs(int n, int par, vector<int> &ini, vector<int>&fin, vector<int> &prof, vector<vector<int>> &adj, int &cont, int &height){ ini[n]=cont; prof[n]=height; height++; for(int x: adj[n]){ if(x==par) continue; cont++; dfs(x, n, ini, fin, prof, adj, cont, height); } height--; cont++; fin[n]=cont; } vector<int> label(int n, int k, vector<int> u, vector<int> v) { vector<int> ans (n); vector<int> ini (n); vector<int> fin (n); vector<int> prof (n); int cont=0; vector<vector<int>> adj (n); for(int i=0; i<n-1; ++i){ adj[u[i]].pb(v[i]); adj[v[i]].pb(u[i]); } int height=0; priority_queue<pair<int,int>, vector<pair<int,int>>, greater<pair<int,int>>> pq; dfs(0, -1, ini, fin, prof, adj, cont, height); for(int i=0; i<n; ++i){ if(prof[i]%2){ ans[i]=ini[i]; } else{ ans[i]=fin[i]; } pq.push({ans[i], i}); } int aux=0; while(!pq.empty()){ int x=pq.top().first; int y=pq.top().second; pq.pop(); ans[y]=aux; aux++; } return ans; } int find_next_station(int s, int t, vector<int> c) { if(c.size()==1) return c[0]; int x=c.size(); if(c[0]>s){ if(t<s) return c[x-1]; if(t>c[x-2]) return c[x-1]; for(int i=0; i<x-1; ++i){ if(t<=c[i]) return c[i]; } } else{ if(t>s) return c[0]; if(t<c[1]) return c[0]; for(int i=1; i<x; ++i){ // if(t==c[i]) return c[i]; if(t<c[i]) return c[i-1]; } return c[x-1]; } return c[0]; }

Compilation message (stderr)

stations.cpp: In function 'std::vector<int> label(int, int, std::vector<int>, std::vector<int>)':
stations.cpp:46:7: warning: unused variable 'x' [-Wunused-variable]
   46 |   int x=pq.top().first;
      |       ^
#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...