이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vb = vector<bool>;
using vvb = vector<vb>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vc = vector<char>;
using vvc = vector<vc>;
using vs = vector<string>;
const ll mod = 1e9 + 7,inf = 1e18;
#define pb push_back
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
void setIO()
{
fast;
}
int n = 1e5 + 5,m,k,TIMER;
vvi adj(n),anc(n,vi(21));
vi pref(n),in(n),out(n);
void dfs(int u,int p)
{
in[u] = ++TIMER;
anc[u][0] = p;
for (int i = 1;i<=20;i++)anc[u][i] = anc[anc[u][i - 1]][i - 1];
for (int v:adj[u]){
if (v == p)continue;
dfs(v,u);
}
out[u] = ++TIMER;
}
void dfs2(int u,int p)
{
for (int v:adj[u]){
if (v == p)continue;
dfs2(v,u);
pref[u] += pref[v];
}
}
bool cmp(int a,int b)
{
return in[a] <= in[b];
}
bool is_ancestor(int u,int v)
{
return in[u] <= in[v] && out[u] >= out[v];
}
int LCA(int u,int v)
{
if (in[u] > in[v])swap(u,v);
if (is_ancestor(u,v))return u;
for (int i = 20;i>=0;i--)
if (!is_ancestor(anc[v][i],u))v = anc[v][i];
return anc[v][0];
}
int main()
{
setIO();
cin>>n>>m>>k;
vvi edges;
vi ind(n + 1);
for (int i = 1;i<n;i++){int u,v;cin>>u>>v;adj[u].pb(v),adj[v].pb(u);edges.pb({u,v});}
dfs(1,1);
while (m--){
int num;
cin>>num;
vi vals(num);
for (int i = 0;i<num;i++)cin>>vals[i];
sort(vals.begin(),vals.end(),cmp);
// for (int i = 0;i<num - 1;i++){
// cout<<vals[i]<<" "<<vals[i + 1]<<" "<<LCA(vals[i],vals[i + 1])<<'\n';
// }
// cout<<'\n';
for (int i = 0;i<num;i++){
int lca = LCA(vals[i],vals[(i + 1)%num]);
pref[vals[i]]++;
pref[vals[(i + 1)%num]]++;
pref[lca] -= 2;
}
}
dfs2(1,1);
vi all;
for (int i = 0;i<edges.size();i++){
int u = edges[i][0],v = edges[i][1];
if (in[u] > in[v])swap(u,v);
ind[v] = i;
}
for (int i = 1;i<=n;i++)if (pref[i] >= 2 * k)all.pb(ind[i]);
cout<<all.size()<<'\n';
sort(all.begin(),all.end());
for (auto it:all)cout<<it + 1<<" ";
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
railway.cpp: In function 'int main()':
railway.cpp:85:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
85 | for (int i = 0;i<edges.size();i++){
| ~^~~~~~~~~~~~~
# | 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... |