#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;
if (q == 12000){
for (int z=2;z<=n;z++){
node temp;
temp.a = 1; temp.b = z; temp.w = get_distance(1,z);
arr.push_back(temp);
}
sort(arr.begin(),arr.end());
ll left = 0;
ll right = 0;
ll leftpos = 1;
ll rightpos = 1;
ll c = 0;
for (int z=0;z<n-1;z++){
ll temp = get_distance(leftpos,arr[z].b);
if (left+temp == arr[z].w){
left += temp;
a[c] = leftpos;
b[c] = arr[z].b;
w[c] = temp;
leftpos = arr[z].b;
c++;
continue;
}
temp = get_distance(rightpos,arr[z].b);
if (right+temp == arr[z].w){
right += temp;
a[c] = rightpos;
b[c] = arr[z].b;
w[c] = temp;
rightpos = arr[z].b;
c++;
continue;
}
}
return;
}
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:80:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int z=0;z<arr.size();z++){
~^~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
115 ms |
13068 KB |
Correct: 498501 out of 500000 queries used. |
2 |
Correct |
103 ms |
12888 KB |
Correct: 499500 out of 500000 queries used. |
3 |
Correct |
83 ms |
12892 KB |
Correct: 492528 out of 500000 queries used. |
4 |
Correct |
78 ms |
12888 KB |
Correct: 494515 out of 500000 queries used. |
5 |
Correct |
97 ms |
13016 KB |
Correct: 498501 out of 500000 queries used. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
115 ms |
13068 KB |
Correct: 498501 out of 500000 queries used. |
2 |
Correct |
103 ms |
12888 KB |
Correct: 499500 out of 500000 queries used. |
3 |
Correct |
83 ms |
12892 KB |
Correct: 492528 out of 500000 queries used. |
4 |
Correct |
78 ms |
12888 KB |
Correct: 494515 out of 500000 queries used. |
5 |
Correct |
97 ms |
13016 KB |
Correct: 498501 out of 500000 queries used. |
6 |
Correct |
113 ms |
12888 KB |
Correct: 495510 out of 500000 queries used. |
7 |
Correct |
121 ms |
13044 KB |
Correct: 497503 out of 500000 queries used. |
8 |
Correct |
116 ms |
13016 KB |
Correct: 497503 out of 500000 queries used. |
9 |
Correct |
107 ms |
12888 KB |
Correct: 495510 out of 500000 queries used. |
10 |
Correct |
120 ms |
12888 KB |
Correct: 496506 out of 500000 queries used. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
632 KB |
Correct: 2051 out of 12000 queries used. |
2 |
Correct |
3 ms |
504 KB |
Correct: 2204 out of 12000 queries used. |
3 |
Correct |
3 ms |
504 KB |
Correct: 2314 out of 12000 queries used. |
4 |
Correct |
3 ms |
504 KB |
Correct: 2301 out of 12000 queries used. |
5 |
Correct |
3 ms |
504 KB |
Correct: 2797 out of 12000 queries used. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
632 KB |
Correct: 2051 out of 12000 queries used. |
2 |
Correct |
3 ms |
504 KB |
Correct: 2204 out of 12000 queries used. |
3 |
Correct |
3 ms |
504 KB |
Correct: 2314 out of 12000 queries used. |
4 |
Correct |
3 ms |
504 KB |
Correct: 2301 out of 12000 queries used. |
5 |
Correct |
3 ms |
504 KB |
Correct: 2797 out of 12000 queries used. |
6 |
Correct |
3 ms |
504 KB |
Correct: 2519 out of 12000 queries used. |
7 |
Correct |
3 ms |
560 KB |
Correct: 2378 out of 12000 queries used. |
8 |
Correct |
3 ms |
504 KB |
Correct: 2195 out of 12000 queries used. |
9 |
Correct |
3 ms |
504 KB |
Correct: 2220 out of 12000 queries used. |
10 |
Correct |
3 ms |
508 KB |
Correct: 2299 out of 12000 queries used. |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
115 ms |
13068 KB |
Correct: 498501 out of 500000 queries used. |
2 |
Correct |
103 ms |
12888 KB |
Correct: 499500 out of 500000 queries used. |
3 |
Correct |
83 ms |
12892 KB |
Correct: 492528 out of 500000 queries used. |
4 |
Correct |
78 ms |
12888 KB |
Correct: 494515 out of 500000 queries used. |
5 |
Correct |
97 ms |
13016 KB |
Correct: 498501 out of 500000 queries used. |
6 |
Correct |
113 ms |
12888 KB |
Correct: 495510 out of 500000 queries used. |
7 |
Correct |
121 ms |
13044 KB |
Correct: 497503 out of 500000 queries used. |
8 |
Correct |
116 ms |
13016 KB |
Correct: 497503 out of 500000 queries used. |
9 |
Correct |
107 ms |
12888 KB |
Correct: 495510 out of 500000 queries used. |
10 |
Correct |
120 ms |
12888 KB |
Correct: 496506 out of 500000 queries used. |
11 |
Correct |
3 ms |
632 KB |
Correct: 2051 out of 12000 queries used. |
12 |
Correct |
3 ms |
504 KB |
Correct: 2204 out of 12000 queries used. |
13 |
Correct |
3 ms |
504 KB |
Correct: 2314 out of 12000 queries used. |
14 |
Correct |
3 ms |
504 KB |
Correct: 2301 out of 12000 queries used. |
15 |
Correct |
3 ms |
504 KB |
Correct: 2797 out of 12000 queries used. |
16 |
Correct |
3 ms |
504 KB |
Correct: 2519 out of 12000 queries used. |
17 |
Correct |
3 ms |
560 KB |
Correct: 2378 out of 12000 queries used. |
18 |
Correct |
3 ms |
504 KB |
Correct: 2195 out of 12000 queries used. |
19 |
Correct |
3 ms |
504 KB |
Correct: 2220 out of 12000 queries used. |
20 |
Correct |
3 ms |
508 KB |
Correct: 2299 out of 12000 queries used. |
21 |
Incorrect |
6 ms |
1396 KB |
Too many calls to get_distance(). |
22 |
Halted |
0 ms |
0 KB |
- |