Submission #1030796

# Submission time Handle Problem Language Result Execution time Memory
1030796 2024-07-22T10:13:24 Z vjudge1 City Mapping (NOI18_citymapping) C++17
0 / 100
6 ms 1628 KB
#include "citymapping.h"
#include <bits/stdc++.h>
using namespace std;


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;


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, long long int pd){
    int st = dis[pos].second, dd = dis[pos].first;
    if(adj[u].size() == 0){
        un(u, st, pd);
        return;
    }

    if(adj[u].size() == 1){
        int x = adj[u][0];
        long long 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];
        long long int d = get_distance(x, st);
        
        if(d < pd) dfs(x, u, pos, d);
        else{
            long long 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[]) {
    // 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].second, dis[0].first);

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

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


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

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

Compilation message

citymapping.cpp: In function 'void dfs(int, int, int, long long int)':
citymapping.cpp:24:31: warning: unused variable 'dd' [-Wunused-variable]
   24 |     int st = dis[pos].second, dd = dis[pos].first;
      |                               ^~
citymapping.cpp: In function 'void find_roads(int, int, int*, int*, int*)':
citymapping.cpp:74:9: warning: unused variable 'aa' [-Wunused-variable]
   74 |     int aa[n-1], bb[n-1], cc[n-1];
      |         ^~
citymapping.cpp:74:18: warning: unused variable 'bb' [-Wunused-variable]
   74 |     int aa[n-1], bb[n-1], cc[n-1];
      |                  ^~
citymapping.cpp:74:27: warning: unused variable 'cc' [-Wunused-variable]
   74 |     int aa[n-1], bb[n-1], cc[n-1];
      |                           ^~
# Verdict Execution time Memory Grader output
1 Runtime error 6 ms 1628 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 6 ms 1628 KB Execution killed with signal 11
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 Incorrect 1 ms 860 KB Too many calls to get_distance().
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 6 ms 1628 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -