Submission #431671

#TimeUsernameProblemLanguageResultExecution timeMemory
431671dreezy기지국 (IOI20_stations)C++17
100 / 100
1009 ms796 KiB
#include "stations.h" #include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define pi pair<int,int> vector<int> labels; vector<vector<int>> graph; vector<pi> ord; int cnt = 0; void dfs1(int n,int p, bool first){//calc sizes if(first) labels[n] = cnt++; //ord[n].first = cnt++; for(int adj : graph[n]) { if(adj == p) continue; dfs1(adj, n, !first); } if(!first) labels[n ] = cnt++; //ord[n].second = cnt++; } void name_subtree(int n, int p, bool first){ if(first) labels[n] = ord[n].first; else labels[n] = ord[n].second; for(int adj : graph[n]){ if(adj == p) continue; name_subtree(adj, n, !first); } } vector<int> label(int n, int k, vector<int> u, vector<int> v) { cnt = 0; ord.clear(); labels.clear(); graph.clear(); ord.assign(n, {0,0}); labels.assign(n, 0); graph.assign( n, vector<int>()); for (int i = 0; i < n - 1; i++) { graph[u[i]].pb(v[i]); graph[v[i]].pb(u[i]); } dfs1(0,-1, 1); int root = 0; //for(int i =0; i<n; i++) cout <<i<<": "<< ord[i].first<<", "<<ord[i].second<<endl; //name_subtree(root, -1, 1); //for(int i =0; i<n; i++) cout <<i<<": "<< labels[i]<<endl; return labels; } int find_next_station(int s, int t, vector<int> c) { if(c.size() == 1) return c[0]; bool isfirst = c[0] > s; if(isfirst){ if(t < s) return c[c.size() - 1]; for(int adj : c){ if(t <= adj) return adj; } return c[c.size()-1] ; } else{ reverse(c.begin(), c.end()); if( t > s) return c[c.size()-1]; for(int adj : c) if(t >= adj) return adj; return c[c.size()-1]; } } /************/

Compilation message (stderr)

stations.cpp: In function 'std::vector<int> label(int, int, std::vector<int>, std::vector<int>)':
stations.cpp:58:6: warning: unused variable 'root' [-Wunused-variable]
   58 |  int root = 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...