Submission #233085

#TimeUsernameProblemLanguageResultExecution timeMemory
233085crossing0verTropical Garden (IOI11_garden)C++17
69 / 100
5069 ms87544 KiB
#include<bits/stdc++.h> #include "gardenlib.h" #include "garden.h" using namespace std; pair<int,int> D[150001][31][2]; pair<int,int> mn[150001][2]; vector<pair<int,int>> adj[150001]; void count_routes(int N, int M, int P, int R[][2], int Q, int G[]){ P++; for (int i = 0; i < M; i++) { R[i][0]++; R[i][1]++; adj[R[i][0]].push_back({R[i][1],i + 1}); adj[R[i][1]].push_back({R[i][0],i+1}); } for (int i = 1; i <= N; i++) { if (adj[i].size() == 1) mn[i][0] = {adj[i][0].second,adj[i][0].first}, mn[i][1] = {adj[i][0].second,adj[i][0].first}; else mn[i][0] = {adj[i][0].second,adj[i][0].first}, mn[i][1] = {adj[i][1].second,adj[i][1].first}; } for (int i = 1; i <= N; i++) { D[i][0][0] = {mn[i][0].second,mn[i][0].first}; D[i][0][1] = {mn[i][1].second,mn[i][1].first}; } for (int j = 1; j <= 30; j++) { for (int i = 1; i <= N; i++) { auto S = D[i][j-1][0]; int x = S.first; int val = S.second; if (val == mn[x][0].first) { D[i][j][0] = D[x][j-1][1]; } else D[i][j][0] = D[x][j-1][0]; S = D[i][j-1][1]; x = S.first; val = S.second; if (val == mn[x][0].first) D[i][j][1] = D[x][j-1][1]; else D[i][j][1] = D[x][j-1][0]; } } for (int q = 0,k; q < Q; q++) { k = G[q]; pair<int,int> cur; int ans = 0; for (int i = 1; i <= N; i++) { cur = {i,0}; for (int j = 0; j <= 30; j++) if (k & (1<< j) ) { if (cur.second != mn[cur.first][0].first) cur = D[cur.first][j][0]; else cur = D[cur.first][j][1]; } if (cur.first == P) ans ++; } answer(ans); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...