| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 552505 | Vladth11 | Railway (BOI17_railway) | C++14 | 99 ms | 26452 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define debug(x) cerr << #x << " " << x << "\n"
#define debugs(x) cerr << #x << " " << x << " "
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <long double, pii> muchie;
const ll NMAX = 100001;
const ll VMAX = 1001;
const ll INF = (1LL << 60);
const ll MOD = 998244353;
const ll BLOCK = 447;
const ll base = 31;
const ll nr_of_bits = 21;
vector <int> sol;
vector <pii> v[NMAX];
int dp[NMAX][nr_of_bits + 1];
int sum[NMAX];
pii timp[NMAX];
int stamp;
bool isParent(int a, int b){
return (timp[a].first <= timp[b].first && timp[b].second <= timp[a].second);
}
int LCA(int a, int b){
int r = a, pas = nr_of_bits;
while(pas >= 0){
int nxt = dp[r][pas];
if(nxt != 0 && !isParent(nxt, b))
r = nxt;
pas--;
}
if(!isParent(r, b))
r = dp[r][0];
return r;
}
void DFS(int node, int p){
dp[node][0] = p;
timp[node].first = ++stamp;
for(auto x : v[node]){
if(x.first == p) continue;
DFS(x.first, node);
}
timp[node].second = stamp;
}
int c[NMAX];
bool cmp(int a, int b){
return timp[a].first < timp[b].first;
}
int k;
void Solve(int node, int p){
for(auto x : v[node]){
if(x.first == p) continue;
Solve(x.first, node);
sum[node] += sum[x.first];
if(sum[x.first] >= k){
sol.push_back(x.second);
}
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, m, i;
cin >> n >> m >> k;
for(i = 1; i < n; i++){
int a, b;
cin >> a >> b;
v[a].push_back({b, i});
v[b].push_back({a, i});
}
DFS(1, 0);
for(int j = 1; j <= nr_of_bits; j++){
for(i = 1; i <= n; i++){
dp[i][j] = dp[dp[i][j - 1]][j - 1];
}
}
for(i = 1; i <= m; i++){
int t;
cin >> t;
for(int j = 1; j <= t; j++) cin >> c[j];
vector <int> total, stiva;
total.push_back(c[t]);
for(int j = 1; j < t; j++){
total.push_back(c[j]);
total.push_back(LCA(c[j], c[j + 1]));
}
sort(total.begin(), total.end(), cmp);
for(int j = 0; j < total.size(); j++){
if(j > 0 && timp[total[j - 1]].first == timp[total[j]].first)
continue;
while(stiva.size() && timp[stiva.back()].second < timp[total[j]].first)
stiva.pop_back();
if(stiva.size()){
sum[stiva.back()]--;
sum[total[j]]++;
}
stiva.push_back(total[j]);
}
}
Solve(1, 0);
sort(sol.begin(), sol.end());
cout << sol.size() << "\n";
for(auto x : sol) cout << x << " ";
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
