답안 #1030833

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1030833 2024-07-22T10:40:25 Z Hectorungo_18 City Mapping (NOI18_citymapping) C++14
컴파일 오류
0 ms 0 KB
#include "citymapping.h"
#include <bits/stdc++.h>
using namespace std;


const int N = 1e3+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 ps, long long int pd){
    int st = dis[ps].second, dd = dis[ps].first;

    if(adj[u].size() == 0){
        un(u, st, (int) 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, ps, d);
        else{
            un(u, st, (int) pd);
            return;
        }
		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, ps, d);
        else{
            long long int r = get_distance(adj[u][1], st);
            dfs(adj[u][1], u, ps, r);
        }
		return;
    }

    

}


void find_roads(int n, int q, int A[], int B[], int W[]) {
    // vector<pair<long long int, int>> dis (n-1);
	long long int mx,
	int mp;
	mx = -1;
   #include "citymapping.h"
#include <bits/stdc++.h>
using namespace std;


const int N = 1e3+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 ps, long long int pd){
    int st = dis[ps].second, dd = dis[ps].first;

    if(adj[u].size() == 0){
        un(u, st, (int) 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, ps, d);
        else{
            un(u, st, (int) pd);
            return;
        }
		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, ps, d);
        else{
            long long int r = get_distance(adj[u][1], st);
            dfs(adj[u][1], u, ps, r);
        }
		return;
    }

    

}


void find_roads(int n, int q, int A[], int B[], int W[]) {
    // vector<pair<long long int, int>> dis (n-1);
	long long int mx,
	int mp;
	mx = mp = -1;
    for(int i = 0; i < n-1; i++){
        long long int d = get_distance(1, i+2);
        // dis[i]={d, i+2};
		if(d > mx){
			mx = d;
			mp=i+2;
		}
    }
	int rr = 0;
	for(int i = 0; i < n; i++){
		if(i+2 != mp){
			long long int d = get_distance(mp, i+2);
			dis[i-r]={d, i+2};
		}
		else r++;
	}
    sort(dis.begin(), dis.end());

    
    un(mp, dis[0].second, dis[0].first);

    for(int i = 1; i < n-1; i++){
        dfs(mp, -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];
		// cout << A[i] << " " << B[i] << " " << W[i] << endl;
	}
	return;
}
mp = -1;
    for(int i = 0; i < n-1; i++){
        long long int d = get_distance(1, i+2);
        // dis[i]={d, i+2};
		if(d > mx){
			mx = d;
			mp=i+2;
		}
    }
	int rr = 0;
	for(int i = 0; i < n; i++){
		if(i+2 != mp){
			long long int d = get_distance(mp, i+2);
			dis[i-rr]={d, i+2};
		}
		else rr=1;
	}
    sort(dis.begin(), dis.end());

    
    un(mp, dis[0].second, dis[0].first);

    for(int i = 1; i < n-1; i++){
        dfs(mp, -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];
		// cout << A[i] << " " << B[i] << " " << W[i] << endl;
	}
	return;
}

Compilation message

citymapping.cpp: In function 'void dfs(int, int, int, long long int)':
citymapping.cpp:25:30: warning: unused variable 'dd' [-Wunused-variable]
   25 |     int st = dis[ps].second, dd = dis[ps].first;
      |                              ^~
citymapping.cpp: In function 'void find_roads(int, int, int*, int*, int*)':
citymapping.cpp:63:2: error: expected unqualified-id before 'int'
   63 |  int mp;
      |  ^~~
citymapping.cpp:78:31: error: a function-definition is not allowed here before '{' token
   78 | void un(int a, int b, int dis){
      |                               ^
citymapping.cpp:88:49: error: a function-definition is not allowed here before '{' token
   88 | void dfs(int u, int p, int ps, long long int pd){
      |                                                 ^
citymapping.cpp:124:58: error: a function-definition is not allowed here before '{' token
  124 | void find_roads(int n, int q, int A[], int B[], int W[]) {
      |                                                          ^
citymapping.cpp:178:1: error: 'mp' was not declared in this scope; did you mean 'mx'?
  178 | mp = -1;
      | ^~
      | mx
citymapping.cpp:74:5: warning: unused variable 'pos' [-Wunused-variable]
   74 | int pos = 0;
      |     ^~~