답안 #965529

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
965529 2024-04-18T19:24:54 Z FEDIKUS 통행료 (IOI18_highway) C++17
100 / 100
298 ms 23004 KB
#include "highway.h"
#include<bits/stdc++.h>

using namespace std;
using ll = long long;

const int maxn=90010;

vector<pair<int,int> > g[maxn];
int intime[maxn];
bool posetio[maxn];
vector<int> nisu;
vector<pair<int,int> > g2[maxn];
vector<int> redosled;

void bfs(int n,int m,int prva,int poc1,int poc2){
  queue<int> bfs;
  bfs.push(poc1);
  bfs.push(poc2);
  posetio[poc1]=true;
  posetio[poc2]=true;
  redosled.push_back(prva);
  g2[poc1].push_back({poc2,prva});
  g2[poc2].push_back({poc1,prva});

  int t=0;
  set<int> jesu;
  jesu.emplace(prva);

  while(!bfs.empty()){
    int node=bfs.front();
    intime[node]=t++;
    bfs.pop();

    for(auto [u,ind]:g[node]){
      if(posetio[u]) continue;
      //if(ind<prva) continue;
      posetio[u]=true;
      bfs.push(u);

      g2[node].push_back({u,ind});
      g2[u].push_back({node,ind});

      redosled.push_back(ind);
      jesu.emplace(ind);
    }
  }
  for(int i=0;i<m;i++) if(jesu.find(i)==jesu.end()) nisu.push_back(i);
}

bool bio[maxn];
set<int> tren;
vector<int> red;

void dfs(int node){
  bio[node]=true;
  for(auto [u,ind]:g2[node]){
    if(bio[u]) continue;
    tren.emplace(ind);
    dfs(u);
  }
}

int uradi(int n,int m,ll bez,int prva,int poc1,int poc2,vector<int> &u,vector<int> &v){
  tren.clear();
  for(int i=0;i<n;i++) bio[i]=false;
  for(auto [u,ind]:g2[poc1]) if(u!=poc2) bio[u]=true;
  dfs(poc1);
  red.clear();
  for(int i:redosled) if(tren.find(i)!=tren.end()) red.push_back(i);

  int l=0;
  int r=int(red.size())-1; // ?
  int ret=-1;
  while(l<=r){
    int mid=l+(r-l)/2;

    vector<int> w(m,0);
    //fill(w.begin(),w.begin()+prva,1);
    for(int i:nisu) w[i]=1;
    for(int i=mid;i<int(red.size());i++){
      w[red[i]]=1;
    }
    if(ask(w)>bez){
      ret=mid;
      l=mid+1;
    }else r=mid-1;
  }

  if(ret==0) return poc2;

  if(intime[u[red[ret]]]>intime[v[red[ret]]]){
    return u[red[ret]];
  }else return v[red[ret]];
}

void find_pair(int n,vector<int> u,vector<int> v,int a,int b) {
  int m=u.size();
  int prva=0;
  int l=1,r=m;
  ll bez=ask(vector<int>(m,0));
  while(l<=r){
    int mid=l+(r-l)/2;
    vector<int> w(m,0);
    fill(w.begin(),w.begin()+mid,1);
    if(ask(w)>bez){
      prva=mid;
      r=mid-1;
    }else l=mid+1;
  }

  prva--;

  for(int i=0;i<m;i++){
    g[u[i]].push_back({v[i],i});
    g[v[i]].push_back({u[i],i});
  }

  bfs(n,m,prva,u[prva],v[prva]);

  int lik1=uradi(n,m,bez,prva,u[prva],v[prva],u,v);
  int lik2=uradi(n,m,bez,prva,v[prva],u[prva],u,v);

  //cout<<lik1<<" "<<lik2<<"\n";

  answer(lik1,lik2);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 5112 KB Output is correct
2 Correct 1 ms 5112 KB Output is correct
3 Correct 1 ms 5116 KB Output is correct
4 Correct 2 ms 5112 KB Output is correct
5 Correct 2 ms 5108 KB Output is correct
6 Correct 1 ms 5116 KB Output is correct
7 Correct 1 ms 5108 KB Output is correct
8 Correct 2 ms 5360 KB Output is correct
9 Correct 1 ms 5116 KB Output is correct
10 Correct 1 ms 5112 KB Output is correct
11 Correct 1 ms 5112 KB Output is correct
12 Correct 1 ms 5108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 5132 KB Output is correct
2 Correct 17 ms 6652 KB Output is correct
3 Correct 207 ms 18788 KB Output is correct
4 Correct 200 ms 19348 KB Output is correct
5 Correct 189 ms 19012 KB Output is correct
6 Correct 158 ms 18784 KB Output is correct
7 Correct 207 ms 19268 KB Output is correct
8 Correct 244 ms 18780 KB Output is correct
9 Correct 187 ms 18788 KB Output is correct
10 Correct 193 ms 18780 KB Output is correct
11 Correct 211 ms 18716 KB Output is correct
12 Correct 221 ms 19500 KB Output is correct
13 Correct 216 ms 19308 KB Output is correct
14 Correct 187 ms 19592 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 7180 KB Output is correct
2 Correct 29 ms 9204 KB Output is correct
3 Correct 37 ms 10880 KB Output is correct
4 Correct 130 ms 21292 KB Output is correct
5 Correct 148 ms 21412 KB Output is correct
6 Correct 123 ms 22132 KB Output is correct
7 Correct 134 ms 23004 KB Output is correct
8 Correct 131 ms 21896 KB Output is correct
9 Correct 133 ms 21672 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 5136 KB Output is correct
2 Correct 21 ms 6636 KB Output is correct
3 Correct 149 ms 15884 KB Output is correct
4 Correct 159 ms 18788 KB Output is correct
5 Correct 195 ms 18780 KB Output is correct
6 Correct 178 ms 19104 KB Output is correct
7 Correct 207 ms 18932 KB Output is correct
8 Correct 204 ms 18764 KB Output is correct
9 Correct 209 ms 18992 KB Output is correct
10 Correct 240 ms 18804 KB Output is correct
11 Correct 183 ms 19296 KB Output is correct
12 Correct 186 ms 19468 KB Output is correct
13 Correct 197 ms 19216 KB Output is correct
14 Correct 208 ms 19792 KB Output is correct
15 Correct 154 ms 18880 KB Output is correct
16 Correct 171 ms 18788 KB Output is correct
17 Correct 192 ms 19832 KB Output is correct
18 Correct 194 ms 19528 KB Output is correct
19 Correct 156 ms 18788 KB Output is correct
20 Correct 178 ms 19992 KB Output is correct
21 Correct 116 ms 19472 KB Output is correct
22 Correct 146 ms 19844 KB Output is correct
23 Correct 116 ms 19240 KB Output is correct
24 Correct 121 ms 19412 KB Output is correct
25 Correct 198 ms 22772 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 6680 KB Output is correct
2 Correct 26 ms 6716 KB Output is correct
3 Correct 226 ms 19100 KB Output is correct
4 Correct 215 ms 20112 KB Output is correct
5 Correct 234 ms 20848 KB Output is correct
6 Correct 258 ms 20584 KB Output is correct
7 Correct 262 ms 20764 KB Output is correct
8 Correct 225 ms 20712 KB Output is correct
9 Correct 142 ms 14220 KB Output is correct
10 Correct 140 ms 14112 KB Output is correct
11 Correct 134 ms 16172 KB Output is correct
12 Correct 194 ms 18932 KB Output is correct
13 Correct 207 ms 20256 KB Output is correct
14 Correct 269 ms 20752 KB Output is correct
15 Correct 246 ms 20544 KB Output is correct
16 Correct 191 ms 15776 KB Output is correct
17 Correct 187 ms 20000 KB Output is correct
18 Correct 187 ms 20020 KB Output is correct
19 Correct 139 ms 19700 KB Output is correct
20 Correct 174 ms 19812 KB Output is correct
21 Correct 297 ms 20864 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 6656 KB Output is correct
2 Correct 23 ms 6692 KB Output is correct
3 Correct 256 ms 19116 KB Output is correct
4 Correct 214 ms 19992 KB Output is correct
5 Correct 240 ms 20212 KB Output is correct
6 Correct 290 ms 20736 KB Output is correct
7 Correct 183 ms 19144 KB Output is correct
8 Correct 202 ms 19216 KB Output is correct
9 Correct 208 ms 19968 KB Output is correct
10 Correct 293 ms 20792 KB Output is correct
11 Correct 262 ms 21016 KB Output is correct
12 Correct 243 ms 21040 KB Output is correct
13 Correct 124 ms 16232 KB Output is correct
14 Correct 159 ms 14256 KB Output is correct
15 Correct 144 ms 15996 KB Output is correct
16 Correct 121 ms 14032 KB Output is correct
17 Correct 125 ms 16220 KB Output is correct
18 Correct 146 ms 14024 KB Output is correct
19 Correct 179 ms 18880 KB Output is correct
20 Correct 206 ms 19464 KB Output is correct
21 Correct 271 ms 20532 KB Output is correct
22 Correct 241 ms 20488 KB Output is correct
23 Correct 298 ms 20992 KB Output is correct
24 Correct 243 ms 20532 KB Output is correct
25 Correct 287 ms 20400 KB Output is correct
26 Correct 227 ms 20644 KB Output is correct
27 Correct 161 ms 19700 KB Output is correct
28 Correct 139 ms 19576 KB Output is correct
29 Correct 136 ms 20028 KB Output is correct
30 Correct 163 ms 19732 KB Output is correct
31 Correct 151 ms 20060 KB Output is correct
32 Correct 167 ms 19552 KB Output is correct
33 Correct 159 ms 19928 KB Output is correct
34 Correct 150 ms 19840 KB Output is correct
35 Correct 143 ms 20296 KB Output is correct
36 Correct 174 ms 19492 KB Output is correct
37 Correct 174 ms 20104 KB Output is correct
38 Correct 136 ms 19712 KB Output is correct
39 Correct 230 ms 21424 KB Output is correct
40 Correct 227 ms 21500 KB Output is correct
41 Correct 247 ms 21100 KB Output is correct
42 Correct 230 ms 20700 KB Output is correct