답안 #733385

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
733385 2023-04-30T15:55:02 Z PoonYaPat 통행료 (IOI18_highway) C++14
100 / 100
245 ms 12808 KB
#include "highway.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

int n,m,u,v,disU[90001],disV[90001],con;
ll Base,a,b;
vector<int> w;
vector<pii> adj[90001],Edge;
bool vis[90001];

void F(int* dis, int start) {
    memset(vis,0,sizeof(vis));
    for (int i=0; i<n; ++i) dis[i]=1e9;

    queue<int> q;
    q.push(start);
    dis[start]=0;

    while (!q.empty()) {
        int node=q.front();
        q.pop();

        if (vis[node]) continue;
        vis[node]=true;

        for (auto s : adj[node]) {
            if (dis[s.first]>dis[node]+1) {
                dis[s.first]=dis[node]+1;
                q.push(s.first);
            }
        }
    }
}

int f(int* dis1, int* dis2, int start) {
    memset(vis,0,sizeof(vis));

    queue<int> q;
    vector<int> edge,temp;
    for (int i=0; i<m; ++i) temp.push_back(0);

    q.push(start);
    vis[start]=true;

    while (!q.empty()) {
        int node=q.front();
        q.pop();

        for (auto s : adj[node]) {
            if (vis[s.first]) temp[s.second]=1;
            else if (dis1[s.first]>=dis2[s.first]) temp[s.second]=1;
            else {
                vis[s.first]=true;
                edge.push_back(s.second);
                q.push(s.first);
            }
        }
    }
    temp[con]=0;

    int l=-1, r=edge.size()-1;
    while (l<r) {
        int mid=(l+r+1)/2;

        for (int i=0; i<edge.size(); ++i) {
            if (i<mid) temp[edge[i]]=0;
            else temp[edge[i]]=1;
        }

        if (ask(temp)==Base) r=mid-1;
        else l=mid;
    }

    if (l==-1) return start;
    if (dis1[Edge[edge[l]].first]<dis1[Edge[edge[l]].second]) return Edge[edge[l]].second;
    else return Edge[edge[l]].first;
}

void find_pair(int N, vector<int> U, vector<int> V, int A, int B) {
    m=U.size();
    n=N; a=A; b=B;

    for (int i=0; i<m; ++i) {
        w.push_back(0);
        adj[U[i]].push_back({V[i],i});
        adj[V[i]].push_back({U[i],i});
        Edge.push_back({U[i],V[i]});
    }
    Base=ask(w);

    int l=0, r=m-1;
    while (l<r) {
        int mid=(l+r)/2;
        for (int i=0; i<m; ++i) {
            if (i<=mid) w[i]=0;
            else w[i]=1;
        }
        if (ask(w)==Base) r=mid;
        else l=mid+1;
    }

    u=U[l];
    v=V[l];
    con=l;

    F(disU,u);
    F(disV,v);

    answer(f(disU,disV,u),f(disV,disU,v));
}

Compilation message

highway.cpp: In function 'int f(int*, int*, int)':
highway.cpp:67:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |         for (int i=0; i<edge.size(); ++i) {
      |                       ~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2512 KB Output is correct
2 Correct 2 ms 2512 KB Output is correct
3 Correct 2 ms 2512 KB Output is correct
4 Correct 1 ms 2512 KB Output is correct
5 Correct 2 ms 2512 KB Output is correct
6 Correct 2 ms 2512 KB Output is correct
7 Correct 2 ms 2512 KB Output is correct
8 Correct 2 ms 2512 KB Output is correct
9 Correct 2 ms 2512 KB Output is correct
10 Correct 2 ms 2428 KB Output is correct
11 Correct 2 ms 2512 KB Output is correct
12 Correct 2 ms 2512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2512 KB Output is correct
2 Correct 18 ms 3292 KB Output is correct
3 Correct 116 ms 10292 KB Output is correct
4 Correct 115 ms 10296 KB Output is correct
5 Correct 111 ms 10304 KB Output is correct
6 Correct 114 ms 10304 KB Output is correct
7 Correct 109 ms 10292 KB Output is correct
8 Correct 108 ms 10296 KB Output is correct
9 Correct 123 ms 10244 KB Output is correct
10 Correct 124 ms 10296 KB Output is correct
11 Correct 157 ms 9616 KB Output is correct
12 Correct 169 ms 9916 KB Output is correct
13 Correct 165 ms 9716 KB Output is correct
14 Correct 137 ms 9860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 3272 KB Output is correct
2 Correct 21 ms 4120 KB Output is correct
3 Correct 29 ms 4872 KB Output is correct
4 Correct 93 ms 9520 KB Output is correct
5 Correct 101 ms 9700 KB Output is correct
6 Correct 96 ms 9632 KB Output is correct
7 Correct 88 ms 9720 KB Output is correct
8 Correct 117 ms 9368 KB Output is correct
9 Correct 96 ms 9628 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2488 KB Output is correct
2 Correct 13 ms 3372 KB Output is correct
3 Correct 99 ms 8716 KB Output is correct
4 Correct 111 ms 10376 KB Output is correct
5 Correct 131 ms 10348 KB Output is correct
6 Correct 120 ms 10300 KB Output is correct
7 Correct 145 ms 10316 KB Output is correct
8 Correct 152 ms 10304 KB Output is correct
9 Correct 132 ms 9936 KB Output is correct
10 Correct 133 ms 10348 KB Output is correct
11 Correct 137 ms 10008 KB Output is correct
12 Correct 128 ms 9768 KB Output is correct
13 Correct 126 ms 9412 KB Output is correct
14 Correct 135 ms 9604 KB Output is correct
15 Correct 168 ms 10328 KB Output is correct
16 Correct 109 ms 10360 KB Output is correct
17 Correct 120 ms 9968 KB Output is correct
18 Correct 123 ms 9996 KB Output is correct
19 Correct 116 ms 10356 KB Output is correct
20 Correct 117 ms 9960 KB Output is correct
21 Correct 91 ms 10696 KB Output is correct
22 Correct 91 ms 10692 KB Output is correct
23 Correct 106 ms 10240 KB Output is correct
24 Correct 129 ms 10040 KB Output is correct
25 Correct 134 ms 9792 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 3388 KB Output is correct
2 Correct 15 ms 3408 KB Output is correct
3 Correct 147 ms 10420 KB Output is correct
4 Correct 176 ms 11340 KB Output is correct
5 Correct 223 ms 12208 KB Output is correct
6 Correct 197 ms 12592 KB Output is correct
7 Correct 199 ms 12200 KB Output is correct
8 Correct 164 ms 12320 KB Output is correct
9 Correct 126 ms 10240 KB Output is correct
10 Correct 127 ms 10784 KB Output is correct
11 Correct 128 ms 11232 KB Output is correct
12 Correct 218 ms 11820 KB Output is correct
13 Correct 207 ms 11984 KB Output is correct
14 Correct 179 ms 12216 KB Output is correct
15 Correct 210 ms 12312 KB Output is correct
16 Correct 189 ms 11428 KB Output is correct
17 Correct 140 ms 10852 KB Output is correct
18 Correct 113 ms 10632 KB Output is correct
19 Correct 141 ms 10676 KB Output is correct
20 Correct 142 ms 10708 KB Output is correct
21 Correct 212 ms 12748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 3400 KB Output is correct
2 Correct 15 ms 3404 KB Output is correct
3 Correct 153 ms 10848 KB Output is correct
4 Correct 180 ms 10728 KB Output is correct
5 Correct 173 ms 11308 KB Output is correct
6 Correct 215 ms 12400 KB Output is correct
7 Correct 183 ms 10512 KB Output is correct
8 Correct 160 ms 10692 KB Output is correct
9 Correct 143 ms 11412 KB Output is correct
10 Correct 174 ms 12172 KB Output is correct
11 Correct 161 ms 12164 KB Output is correct
12 Correct 245 ms 12480 KB Output is correct
13 Correct 171 ms 11232 KB Output is correct
14 Correct 170 ms 10868 KB Output is correct
15 Correct 158 ms 11208 KB Output is correct
16 Correct 152 ms 10992 KB Output is correct
17 Correct 140 ms 11404 KB Output is correct
18 Correct 127 ms 10808 KB Output is correct
19 Correct 160 ms 11804 KB Output is correct
20 Correct 180 ms 12016 KB Output is correct
21 Correct 207 ms 12256 KB Output is correct
22 Correct 180 ms 12208 KB Output is correct
23 Correct 178 ms 12224 KB Output is correct
24 Correct 205 ms 12588 KB Output is correct
25 Correct 199 ms 12228 KB Output is correct
26 Correct 166 ms 12196 KB Output is correct
27 Correct 107 ms 10740 KB Output is correct
28 Correct 135 ms 10632 KB Output is correct
29 Correct 119 ms 10840 KB Output is correct
30 Correct 107 ms 10668 KB Output is correct
31 Correct 126 ms 10600 KB Output is correct
32 Correct 107 ms 10604 KB Output is correct
33 Correct 154 ms 10772 KB Output is correct
34 Correct 115 ms 10588 KB Output is correct
35 Correct 121 ms 10632 KB Output is correct
36 Correct 144 ms 10492 KB Output is correct
37 Correct 153 ms 10720 KB Output is correct
38 Correct 145 ms 10728 KB Output is correct
39 Correct 205 ms 12808 KB Output is correct
40 Correct 178 ms 12756 KB Output is correct
41 Correct 174 ms 12748 KB Output is correct
42 Correct 243 ms 12400 KB Output is correct