Submission #116977

# Submission time Handle Problem Language Result Execution time Memory
116977 2019-06-14T10:37:51 Z pzdba Highway Tolls (IOI18_highway) C++14
0 / 100
1500 ms 5156 KB
#include <bits/stdc++.h>
#include "highway.h"
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
vector<pii> g[90005], g2[90005];
bool vis[90005];
int arr[2][90005];
int par[90005];
int k = 1;
void dfs(int u, int p, int j, int d, int t){
    par[u] = j;
    arr[t][k++] = u;
    for(int i=0;i<g2[u].size();i++){
        int v = g2[u][i].first, j = g2[u][i].second;
        if(v == p) continue;
        dfs(v, u, j, d+1, t);
    }
}
void find_pair(int n, std::vector<int> U, std::vector<int> V, int a, int b){
    int s, t;
    int m = U.size();
    for(int i=0;i<m;i++){
        int a = U[i], b = V[i];
        g[a].push_back(pii(b, i));
        g[b].push_back(pii(a, i));
    }
    vector<int> w;
    w.resize(m);
    LL base = ask(w);
    int lo = 0, hi = m-1, j = 0;
    while(lo <= hi){
        int mid = (lo+hi)/2;
        for(int i=0;i<m;i++) w[i] = 0;
        for(int i=0;i<=mid;i++) w[i] = 1;
        LL tmp = ask(w);
        if(tmp > base) j = mid, hi = mid-1;
        else lo = mid+1;
    }
    int u = U[j], v = V[j];
    vis[u] = 1;
    vis[v] = 1;
    queue<int> q;
    q.push(u);
    q.push(v);
    while(!q.empty()){
        int u = q.front();
        for(int i=0;i<g[u].size();i++){
            int v = g[u][i].first, j = g[u][i].second;
            if(vis[v]) continue;
            vis[v] = 1;
            g2[u].push_back(pii(v, j));
            g2[v].push_back(pii(u, j));
        }
    }
    k = 1;
    dfs(u, -1, 0, 0, 0);
    int sz1 = k;
    k = 1;
    dfs(v, -1, 0, 0, 0);
    int sz2 = k;

    lo = 1, hi = sz1;
    while(lo <= hi){
        int mid = (lo+hi)/2;
        for(int i=0;i<m;i++) w[i] = 0;
        for(int i=mid;i<=sz1;i++){
            int u = arr[0][i];
            w[par[u]] = 1;
        }
        LL tmp = ask(w);
        if(tmp > base) s = arr[0][mid], lo = mid+1;
        else hi = mid-1;
    }
    lo = 1, hi = sz2;
    while(lo <= hi){
        int mid = (lo+hi)/2;
        for(int i=0;i<m;i++) w[i] = 0;
        for(int i=mid;i<=sz2;i++){
            int u = arr[1][i];
            w[par[u]] = 1;
        }
        LL tmp = ask(w);
        if(tmp > base) t = arr[1][mid], lo = mid+1;
        else hi = mid-1;
    }
    answer(s, t);
}

Compilation message

highway.cpp: In function 'void dfs(int, int, int, int, int)':
highway.cpp:14:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<g2[u].size();i++){
                 ~^~~~~~~~~~~~~
highway.cpp: In function 'void find_pair(int, std::vector<int>, std::vector<int>, int, int)':
highway.cpp:48:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int i=0;i<g[u].size();i++){
                     ~^~~~~~~~~~~~
highway.cpp:87:11: warning: 't' may be used uninitialized in this function [-Wmaybe-uninitialized]
     answer(s, t);
     ~~~~~~^~~~~~
highway.cpp:87:11: warning: 's' may be used uninitialized in this function [-Wmaybe-uninitialized]
# Verdict Execution time Memory Grader output
1 Execution timed out 3058 ms 4608 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3014 ms 4688 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3076 ms 5008 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3061 ms 4608 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3091 ms 5156 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3049 ms 5152 KB Time limit exceeded
2 Halted 0 ms 0 KB -