Submission #378213

#TimeUsernameProblemLanguageResultExecution timeMemory
378213AriaHRailway (BOI17_railway)C++11
100 / 100
308 ms125156 KiB
/** 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)

railway.cpp: In function 'int main()':
railway.cpp:72:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   72 |  scanf("%d%d%d", &n, &m, &k);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~
railway.cpp:76:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   76 |   scanf("%d%d", &a,&b);
      |   ~~~~~^~~~~~~~~~~~~~~
railway.cpp:82:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   82 |   scanf("%d", &sz[i]);
      |   ~~~~~^~~~~~~~~~~~~~
railway.cpp:86:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   86 |    scanf("%d", &x);
      |    ~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...