제출 #650024

#제출 시각아이디문제언어결과실행 시간메모리
650024alvinpiterTropical Garden (IOI11_garden)C++17
49 / 100
16 ms9860 KiB
#include "garden.h" #include "gardenlib.h" #include<bits/stdc++.h> using namespace std; #define MAXN 150000 #define MAXE 300000 #define MAXLG 18 struct DirectedEdge { int id, from, to, beauty; DirectedEdge(int id_, int from_, int to_, int beauty_): id(id_), from(from_), to(to_), beauty(beauty_) {} bool operator<(DirectedEdge other) const { return beauty < other.beauty; } }; vector<DirectedEdge> directedEdges, goingOutEdges[MAXN + 3]; int nxt[MAXE + 3][MAXLG + 3]; void count_routes(int n, int m, int p, int r[][2], int q, int g[]) { int numberOfDirectedEdges = 0; for (int i = 0; i < m; i++) { int u = r[i][0], v = r[i][1], beauty = i; DirectedEdge uvEdge = DirectedEdge(numberOfDirectedEdges++, u, v, beauty); DirectedEdge vuEdge = DirectedEdge(numberOfDirectedEdges++, v, u, beauty); directedEdges.push_back(uvEdge); goingOutEdges[u].push_back(uvEdge); directedEdges.push_back(vuEdge); goingOutEdges[v].push_back(vuEdge); } for (int i = 0; i < n; i++) { sort(goingOutEdges[i].begin(), goingOutEdges[i].end()); } // cout << "\ngoingOutEdges\n"; // for (int i = 0; i < n; i++) { // cout << i << ":"; // for (auto edge: goingOutEdges[i]) { // cout << " (" << edge.id << ", " << edge.from << ", " << edge.to << ", " << edge.beauty << ")"; // } // cout << endl; // } for (auto directedEdge: directedEdges) { int firstEdgeId = directedEdge.id; int secondEdgeId; if (goingOutEdges[directedEdge.to].size() == 1) { secondEdgeId = goingOutEdges[directedEdge.to][0].id; } else { for (auto goingOutEdge: goingOutEdges[directedEdge.to]) { if (goingOutEdge.beauty != directedEdge.beauty) { secondEdgeId = goingOutEdge.id; break; } } } nxt[firstEdgeId][0] = secondEdgeId; } // cout << "\nnxt\n"; // for (int i = 0; i < numberOfDirectedEdges; i++) { // cout << i << ": " << nxt[i][0] << endl; // } for (int lg = 1; lg <= MAXLG; lg++) { for (int i = 0; i < numberOfDirectedEdges; i++) { nxt[i][lg] = nxt[nxt[i][lg - 1]][lg - 1]; } } for (int i = 0; i < q; i++) { int ans = 0; for (int startingNode = 0; startingNode < n; startingNode++) { int currentEdgeId = goingOutEdges[startingNode][0].id; // Jump (g[i] - 1) times int numJumps = g[i] - 1; for (int lg = 0; lg <= MAXLG; lg++) { if (numJumps & (1 << lg)) { currentEdgeId = nxt[currentEdgeId][lg]; } } if (directedEdges[currentEdgeId].to == p) { ans += 1; } } answer(ans); } }

컴파일 시 표준 에러 (stderr) 메시지

garden.cpp: In function 'void count_routes(int, int, int, int (*)[2], int, int*)':
garden.cpp:63:25: warning: 'secondEdgeId' may be used uninitialized in this function [-Wmaybe-uninitialized]
   63 |     nxt[firstEdgeId][0] = secondEdgeId;
      |     ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...