Submission #208722

#TimeUsernameProblemLanguageResultExecution timeMemory
208722E869120Senior Postmen (BOI14_postmen)C++14
55 / 100
537 ms42600 KiB
#include <iostream> #include <vector> #include <set> using namespace std; #pragma warning (disable: 4996) struct Node { int to, cap, rev; }; int N, M, A[1 << 19], B[1 << 19]; vector<Node> X[1 << 19]; int cur[1 << 19]; bool used[1 << 19]; int main() { scanf("%d%d", &N, &M); for (int i = 1; i <= M; i++) { scanf("%d%d", &A[i], &B[i]); X[A[i]].push_back(Node{ B[i], 1, (int)X[B[i]].size() }); X[B[i]].push_back(Node{ A[i], 1, (int)X[A[i]].size() - 1 }); } int num = M, cnt = 1; vector<vector<int>> ans; while (num > 0) { while (true) { while (cur[cnt] < X[cnt].size() && X[cnt][cur[cnt]].cap == 0) cur[cnt]++; if (cur[cnt] < X[cnt].size()) break; cnt++; } int cx = cnt; vector<int> vec; while (true) { vec.push_back(cx); int nex = -1, res = -1; while (X[cx][cur[cx]].cap == 0) cur[cx]++; nex = X[cx][cur[cx]].to; res = X[cx][cur[cx]].rev; X[cx][cur[cx]].cap = 0; X[nex][res].cap = 0; num--; if (nex == cnt) break; cx = nex; } vec.push_back(cnt); for (int i : vec) used[i] = false; vector<int> v1; for (int i = 0; i < vec.size(); i++) { if (used[vec[i]] == true) { vector<int> ret; while (true) { int cp = v1[v1.size() - 1]; ret.push_back(cp); used[cp] = false; v1.pop_back(); if (cp == vec[i]) break; } ans.push_back(ret); } used[vec[i]] = true; v1.push_back(vec[i]); } } for (int i = 0; i < ans.size(); i++) { for (int j = 0; j < ans[i].size(); j++) { if (j) printf(" "); printf("%d", ans[i][j]); } printf("\n"); } return 0; }

Compilation message (stderr)

postmen.cpp:5:0: warning: ignoring #pragma warning  [-Wunknown-pragmas]
 #pragma warning (disable: 4996)
 
postmen.cpp: In function 'int main()':
postmen.cpp:27:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    while (cur[cnt] < X[cnt].size() && X[cnt][cur[cnt]].cap == 0) cur[cnt]++;
           ~~~~~~~~~^~~~~~~~~~~~~~~
postmen.cpp:28:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    if (cur[cnt] < X[cnt].size()) break;
        ~~~~~~~~~^~~~~~~~~~~~~~~
postmen.cpp:49:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int i = 0; i < vec.size(); i++) {
                   ~~^~~~~~~~~~~~
postmen.cpp:65:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < ans.size(); i++) {
                  ~~^~~~~~~~~~~~
postmen.cpp:66:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int j = 0; j < ans[i].size(); j++) { if (j) printf(" "); printf("%d", ans[i][j]); }
                   ~~^~~~~~~~~~~~~~~
postmen.cpp:16:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &N, &M);
  ~~~~~^~~~~~~~~~~~~~~~
postmen.cpp:18:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &A[i], &B[i]);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...