diff --git a/2201/220103.cpp b/2201/220103.cpp new file mode 100644 index 0000000..b28e875 --- /dev/null +++ b/2201/220103.cpp @@ -0,0 +1,33 @@ +#include +#include +#include + +class Solution { +private: + // Reduce cache miss! + // inline static int inDegree[1005]; + // inline static int outDegree[1005]; + inline static unsigned degrees[1005][2]; +public: + static int findJudge(int n, const std::vector>& trust) { + int len = trust.size(); + if (len < n - 1) return -1; + memset(degrees, 0, sizeof degrees); + // for (const auto& i : trust) { + for (int i = 0; i < len; ++i) { + ++degrees[trust[i][0]][0]; + ++degrees[trust[i][1]][1]; + } + for (int i = 1; i <= n; ++i) { + // if (!degrees[i][0] && degrees[i][1] == n - 1) + if (!(degrees[i][0] | (degrees[i][1] ^ n - 1))) + return i; + } + return -1; + } +}; + +int main() { + std::printf("%d\n", Solution::findJudge(4, {{1, 3}, {1, 4}, {2, 3}, {2, 4}, {4, 3}})); + return 0; +} diff --git a/2201/CMakeLists.txt b/2201/CMakeLists.txt index b7c25d0..ad10f0f 100644 --- a/2201/CMakeLists.txt +++ b/2201/CMakeLists.txt @@ -3,4 +3,4 @@ PROJECT(2201) SET(CMAKE_CXX_STANDARD 23) -ADD_EXECUTABLE(2201 220103-CN.cpp) \ No newline at end of file +ADD_EXECUTABLE(2201 220103.cpp) \ No newline at end of file