Submission #123515

# Submission time Handle Problem Language Result Execution time Memory
123515 2019-07-01T14:14:35 Z mechfrog88 City Mapping (NOI18_citymapping) C++14
25 / 100
127 ms 12788 KB
#include "citymapping.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

struct node{
	ll a,b,w;
	bool operator <(const node& rhs) const{
		return w < rhs.w;
	}
};

vector <ll> id;

ll find(ll i){
	if (id[i] < 0) return i;
	return id[i] = find(id[i]);
}

void unio(ll i,ll j){
	ll a = find(i);
	ll b = find(j);
	if (a == b) return;
	if (id[b] < id[a]) swap(a,b);
	id[a] += id[b];
	id[b] = a;
}


void find_roads(int n, int q, int a[], int b[], int w[]) {
	vector <node> arr(n+1);
	for (int z=1;z<=n;z++){
		for (int x=z+1;x<=n;x++){
			node temp;
			temp.a = z; temp.b = x; temp.w = get_distance(z,x);
			arr.push_back(temp);
		}
	}
	id.resize(n+1,-1);
	sort(arr.begin(),arr.end());
	vector <ll> count(n+1,0);
	ll c = 0;
	for (int z=0;z<arr.size();z++){
		if (count[arr[z].a] >= 3 || count[arr[z].b] >= 3) continue;
		ll i = find(arr[z].a);
		ll j = find(arr[z].b);
		if (i == j) continue;
		unio(i,j);
		a[c] = arr[z].a;
		b[c] = arr[z].b;
		w[c] = arr[z].w;
		count[arr[z].a]++;
		count[arr[z].b]++;
		c++;
	}
	return;
}

Compilation message

citymapping.cpp: In function 'void find_roads(int, int, int*, int*, int*)':
citymapping.cpp:43:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int z=0;z<arr.size();z++){
               ~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 112 ms 12680 KB Correct: 498501 out of 500000 queries used.
2 Correct 103 ms 12680 KB Correct: 499500 out of 500000 queries used.
3 Correct 84 ms 12588 KB Correct: 492528 out of 500000 queries used.
4 Correct 79 ms 12576 KB Correct: 494515 out of 500000 queries used.
5 Correct 99 ms 12696 KB Correct: 498501 out of 500000 queries used.
# Verdict Execution time Memory Grader output
1 Correct 112 ms 12680 KB Correct: 498501 out of 500000 queries used.
2 Correct 103 ms 12680 KB Correct: 499500 out of 500000 queries used.
3 Correct 84 ms 12588 KB Correct: 492528 out of 500000 queries used.
4 Correct 79 ms 12576 KB Correct: 494515 out of 500000 queries used.
5 Correct 99 ms 12696 KB Correct: 498501 out of 500000 queries used.
6 Correct 115 ms 12576 KB Correct: 495510 out of 500000 queries used.
7 Correct 126 ms 12788 KB Correct: 497503 out of 500000 queries used.
8 Correct 113 ms 12692 KB Correct: 497503 out of 500000 queries used.
9 Correct 110 ms 12576 KB Correct: 495510 out of 500000 queries used.
10 Correct 127 ms 12568 KB Correct: 496506 out of 500000 queries used.
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 980 KB Too many calls to get_distance().
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 980 KB Too many calls to get_distance().
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 112 ms 12680 KB Correct: 498501 out of 500000 queries used.
2 Correct 103 ms 12680 KB Correct: 499500 out of 500000 queries used.
3 Correct 84 ms 12588 KB Correct: 492528 out of 500000 queries used.
4 Correct 79 ms 12576 KB Correct: 494515 out of 500000 queries used.
5 Correct 99 ms 12696 KB Correct: 498501 out of 500000 queries used.
6 Correct 115 ms 12576 KB Correct: 495510 out of 500000 queries used.
7 Correct 126 ms 12788 KB Correct: 497503 out of 500000 queries used.
8 Correct 113 ms 12692 KB Correct: 497503 out of 500000 queries used.
9 Correct 110 ms 12576 KB Correct: 495510 out of 500000 queries used.
10 Correct 127 ms 12568 KB Correct: 496506 out of 500000 queries used.
11 Incorrect 5 ms 980 KB Too many calls to get_distance().
12 Halted 0 ms 0 KB -