Submission #1030781

# Submission time Handle Problem Language Result Execution time Memory
1030781 2024-07-22T09:57:36 Z vjudge1 City Mapping (NOI18_citymapping) C++14
0 / 100
11 ms 1116 KB
#include <bits/stdc++.h>
using namespace std;

// #define int long long
#define f first
#define s second

mt19937 gnd(time(NULL));


const int N = 1e4+5;
vector<int> adj[N];
int v[N], r[N], w[N]; 
vector<pair<long long int, int>> dis(N, {1e18+7, 0});
int pos = 0;

long long int get_distance(int a, int b);

// int get_distance(int a, int b){
//     cout << "?  " << a << " " << b << endl;
//     int d;
//     cin >> d;
//     return d;
// }


void un(int a, int b, int dis){
    adj[a].push_back(b);
    // adj[b].push_back(a);
    v[pos]=a;
    r[pos]=b;
    w[pos]=dis;
    pos++;
}


void dfs(int u, int p, int pos, int pd){
    int st = dis[pos].s, dd = dis[pos].f;
    if(adj[u].size() == 0){
        un(u, st, pd);
        return;
    }

    if(adj[u].size() == 1){
        int x = adj[u][0];
        int d = get_distance(x, st);
        if(d < pd) dfs(x, u, pos, d);
        else{
            un(u, st, pd);
            return;
        }
    }

    if(adj[u].size() == 2){
        int x = adj[u][0];
        int d = get_distance(x, st);
        
        if(d < pd) dfs(x, u, pos, d);
        else{
            int r = get_distance(adj[u][1], st);
            dfs(adj[u][1], u, pos, r);
        }
    }

    

}

void find_roads(int n, int q, int A[], int B[], int W[]){
    for(int i = n-1; i < N; i++) dis[i].f = 1e18+7;
    // vector<pair<long long int, int>> dis (n-1);
    for(int i = 0; i < n-1; i++){
        long long int d = get_distance(1, i+2);
        dis[i]={d, i+2};
    }
    sort(dis.begin(), dis.end());

    
    un(1, dis[0].s, dis[0].f);

    for(int i = 1; i < n-1; i++){
        dfs(1, -1, i, dis[i].f);
    }

    // for(int i = 0; i < n-1; i++){
    //     cout << v[i] << " " << r[i] << " " << w[i] << endl;
    // }


    for(int i = 0; i < n-1; i++){
        A[i] = v[i];
        B[i] = r[i];
        W[i] = w[i];
    }


}   

// void fr(int n, int q){
//     int a[n], b[n], w[n];
//     find_roads(n, q, a, b, w);
//     // cout << "s" << endl;
// }

// signed main(){
//     // ios::sync_with_stdio(0);
//     // cin.tie(0);
//     // cout.tie(0);
//     int t = 1;
//     cin >> t;
//     while(t--){
//         int n, q;
//         cin >> n >> q;
//         fr(n, q);

//     }
    
// }

Compilation message

citymapping.cpp: In function 'void dfs(int, int, int, int)':
citymapping.cpp:38:26: warning: unused variable 'dd' [-Wunused-variable]
   38 |     int st = dis[pos].s, dd = dis[pos].f;
      |                          ^~
# Verdict Execution time Memory Grader output
1 Correct 11 ms 1116 KB Correct: 251481 out of 500000 queries used.
2 Correct 10 ms 860 KB Correct: 308832 out of 500000 queries used.
3 Correct 2 ms 1112 KB Correct: 27160 out of 500000 queries used.
4 Incorrect 1 ms 860 KB Reported list of edges differ from actual.
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 11 ms 1116 KB Correct: 251481 out of 500000 queries used.
2 Correct 10 ms 860 KB Correct: 308832 out of 500000 queries used.
3 Correct 2 ms 1112 KB Correct: 27160 out of 500000 queries used.
4 Incorrect 1 ms 860 KB Reported list of edges differ from actual.
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 860 KB Too many calls to get_distance().
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 860 KB Too many calls to get_distance().
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 11 ms 1116 KB Correct: 251481 out of 500000 queries used.
2 Correct 10 ms 860 KB Correct: 308832 out of 500000 queries used.
3 Correct 2 ms 1112 KB Correct: 27160 out of 500000 queries used.
4 Incorrect 1 ms 860 KB Reported list of edges differ from actual.
5 Halted 0 ms 0 KB -