Submission #123496

# Submission time Handle Problem Language Result Execution time Memory
123496 2019-07-01T14:03:00 Z mechfrog88 City Mapping (NOI18_citymapping) C++14
9 / 100
103 ms 6720 KB
#include "citymapping.h"
#include <bits/stdc++.h>
using namespace std;

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

vector <int> id;

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

void unio(int i,int j){
	int a = find(i);
	int 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());
	int c = 0;
	for (int z=0;z<arr.size();z++){
		int i = find(arr[z].a);
		int 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;
		c++;
	}
	return;
}

Compilation message

citymapping.cpp: In function 'void find_roads(int, int, int*, int*, int*)':
citymapping.cpp:41: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 97 ms 6592 KB Correct: 498501 out of 500000 queries used.
2 Correct 89 ms 6720 KB Correct: 499500 out of 500000 queries used.
3 Correct 71 ms 6608 KB Correct: 492528 out of 500000 queries used.
4 Correct 67 ms 6604 KB Correct: 494515 out of 500000 queries used.
5 Correct 85 ms 6592 KB Correct: 498501 out of 500000 queries used.
# Verdict Execution time Memory Grader output
1 Correct 97 ms 6592 KB Correct: 498501 out of 500000 queries used.
2 Correct 89 ms 6720 KB Correct: 499500 out of 500000 queries used.
3 Correct 71 ms 6608 KB Correct: 492528 out of 500000 queries used.
4 Correct 67 ms 6604 KB Correct: 494515 out of 500000 queries used.
5 Correct 85 ms 6592 KB Correct: 498501 out of 500000 queries used.
6 Incorrect 103 ms 6604 KB Reported list of edges differ from actual.
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 760 KB Too many calls to get_distance().
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 760 KB Too many calls to get_distance().
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 97 ms 6592 KB Correct: 498501 out of 500000 queries used.
2 Correct 89 ms 6720 KB Correct: 499500 out of 500000 queries used.
3 Correct 71 ms 6608 KB Correct: 492528 out of 500000 queries used.
4 Correct 67 ms 6604 KB Correct: 494515 out of 500000 queries used.
5 Correct 85 ms 6592 KB Correct: 498501 out of 500000 queries used.
6 Incorrect 103 ms 6604 KB Reported list of edges differ from actual.
7 Halted 0 ms 0 KB -