# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
378213 | AriaH | Railway (BOI17_railway) | C++11 | 308 ms | 125156 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/** I can do this all day **/
#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
#define Mp make_pair
#define SZ(x) (int)x.size()
#define fast_io ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io freopen("in.txt" , "r+" , stdin) ; freopen("out.txt" , "w+" , stdout);
const int N = 1e6 + 10;
const ll mod = 1e9 + 7;
const ll mod2 = 998244353;
const ll inf = 8e18;
const int LOG = 22;
ll pw(ll a , ll b, ll M) { return (!b ? 1 : (b & 1 ? (a * pw(a * a % M, b / 2, M)) % M : pw(a * a % M, b / 2, M))); }
int n, m, k, sz[N];
map < int, int > mp[N];
vector < pii > G[N];
vector < int > tot, add[N];
void dfs(int v, int last = 0)
{
for(auto x : add[v])
{
mp[v][x] ++;
if(mp[v][x] == sz[x])
{
mp[v].erase(mp[v].find(x));
}
}
for(auto y : G[v])
{
int u = y.F, id = y.S;
if(id == last) continue;
dfs(u, id);
if(SZ(mp[v]) < SZ(mp[u]))
{
mp[v].swap(mp[u]);
}
for(auto it = mp[u].begin(); it != mp[u].end(); it ++)
{
if(it->S == 0) continue;
mp[v][it->F] += it->S;
if(sz[it->F] == mp[v][it->F])
{
mp[v].erase(mp[v].find(it->F));
}
}
}
if(SZ(mp[v]) >= k)
{
tot.push_back(last);
}
}
int main()
{
scanf("%d%d%d", &n, &m, &k);
for(int i = 1; i < n; i ++)
{
int a, b;
scanf("%d%d", &a,&b);
G[a].push_back(Mp(b, i));
G[b].push_back(Mp(a, i));
}
for(int i = 1; i <= m; i ++)
{
scanf("%d", &sz[i]);
for(int j = 1; j <= sz[i]; j ++)
{
int x;
scanf("%d", &x);
add[x].push_back(i);
}
}
dfs(1);
sort(all(tot));
printf("%d\n", SZ(tot));
for(auto x : tot) printf("%d ", x);
return 0;
}
/** test corner cases(n = 1?) watch for overflow or minus indices **/
Compilation message (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... |