| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1368022 | kahoul | The Ties That Guide Us (CEOI23_incursion) | C++20 | 0 ms | 0 KiB |
#include <vector>
#include "incursion.h"
#include <cstdio>
#include <bits/stdc++.h>
using namespace std;
const int maxn = 45003;
int n;
vector<int> rel[maxn];
void bfs (int u) {
vector<bool> visited(n, 0);
queue<int> bfs;
bfs.push_back(safe);
vector<int> dist(n, 0);
dist[safe] = 0;
while (!bfs.empty()) {
int u = bfs.front();
bfs.pop();
if (visited[u]) continue;
visited[u] = 1;
for (auto v : rel[u]) {
if (dist[v] > dist[u] + 1) {
dist[v] = dist[u] + 1;
bfs.push(v);
}
}
}
return dist;
}
void build_graph (vector<pair<int, int>> &ar) {
for (int i = 0; i < ar.size(); i++) {
auto [u, v] = ar[i];
u--; v--;
rel[u].push_back(v);
rel[v].push_back(u);
}
}
const int mods[] = {1, 0, 1, 1, 0, 0};
vector<int> mark(vector<pair<int, int>> ar, int safe) {
n = ar.size() + 1;
build_graph(ar);
vector<int> dist = bfs(safe);
vector<int> vals(n);
for (int i = 0; i < n; i++) {
if (dist[i] == 0) { vals[i] = 0; continue; }
vals[i] = mods[(dist[i] - 1) % 6];
}
return {2, 2, 0};
}
vector<int> walk (vector<int> path) {
vector<int> resp;
for (auto v : path) {
int val = visit(v);
resp.push_back(val);
}
return resp;
}
void locate(vector<pair<int, int>> ar, int curr, int t) {
n = ar.size() + 1;
build_graph(ar);
vector<int> dist = bfs(curr);
vector<int> amt(n + 1, 0);
int dude = 0;
for (int i = 0; i < n; i++) amt[dist[i]]++;
for (int i = 0; i < n; i++) if (amt[i] == 2) dude = i;
int whereami = curr;
if (amt[dude] < 4) {
int v;
for (int i = 0; i < n; i++) if (dist[i] == amt[dude] && rel[i].size() == 1) {
v = i;
break;
}
vector<int> dist2 = bfs(v);
stack<int> s;
for (int i = 1; i < amt[dude]; i++) {
for (int u = 0; u < n; u++) {
if (dist[u] == i) {
s.push(i);
}
}
}
visit(s.top());
s.pop();
whereami = dude;
}
return;
}
