#include "simurgh.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 1e9;
int adj[505][505], n;
bool chk[505];
int calc(int p, int l, int r){
vector<int> Q;
for (int i=l;i<=r;i++) Q.push_back(adj[p][i]);
int cnt = 0;
Q.push_back(adj[0][p]);
if (chk[p]) cnt++;
for (int i=1;i<n;i++) if (!(l<=i && i<=r) && i!=p){
Q.push_back(adj[0][i]);
if (chk[i]) cnt++;
}
return count_common_roads(Q) - cnt;
}
std::vector<int> find_roads(int N, std::vector<int> u, std::vector<int> v) {
n = N;
fill(adj[0], adj[504]+505, -1);
for (int i=0;i<(int)u.size();i++) adj[u[i]][v[i]] = i;
vector<pair<int, int>> v1;
vector<int> Q;
for (int i=2;i<n;i++) Q.push_back(adj[1][i]);
int mn = INF;
for (int i=1;i<n;i++){
Q.push_back(adj[0][i]);
v1.emplace_back(i, count_common_roads(Q));
Q.pop_back();
mn = min(mn, v1.back().second);
}
int cnt = 0;
for (auto &p:v1) if (p.second==mn) cnt++;
vector<int> ans;
for (auto &p:v1) if (cnt==n-1 || p.second!=mn){
chk[p.first] = 1;
ans.push_back(adj[0][p.first]);
}
//for (int i=1;i<n;i++) printf("%d ", chk[i]);
//printf("\n");
for (int i=1;i<n;i++){
int prv = i;
while(calc(i, prv+1, n-1) > 0){
//printf("YES: %d\n", i);
int l = prv+1, r = n-1;
while(r-l > 0){
int m = (l+r)>>1;
if (calc(i, l, m) > 0) r = m;
else l = m+1;
}
ans.push_back(adj[i][l]);
prv = l;
}
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
1228 KB |
WA in grader: NO |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
1228 KB |
WA in grader: NO |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
1228 KB |
WA in grader: NO |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
1228 KB |
WA in grader: NO |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
1228 KB |
WA in grader: NO |
2 |
Halted |
0 ms |
0 KB |
- |