Submission #825814

#TimeUsernameProblemLanguageResultExecution timeMemory
825814AmylopectinThousands Islands (IOI22_islands)C++17
6.75 / 100
63 ms77844 KiB
#include "islands.h" #include <stdio.h> #include <variant> #include <vector> #include <algorithm> #include <iostream> using namespace std; const int mxn = 1e6 + 10; struct we { int to,idx; }; vector<struct we> pat[mxn] = {},rpat[mxn] = {}; vector<int> lii[mxn] = {},ans; int n,m,u[mxn] = {},in[mxn] = {},scc[mxn] = {},cou,sru,nmem[mxn] = {},fon[mxn] = {} ,tog[mxn] = {},upa[mxn] = {},of; int re(int cn) { int i,j,fn; u[cn] = 1; in[cou] = cn; cou ++; for(i=0; i<pat[cn].size(); i++) { fn = pat[cn][i].to; if(u[fn] == 0) { re(fn); } } return 0; } int re2(int cn) { int i,j,fn; scc[cn] = sru; nmem[sru] ++; for(i=0; i<rpat[cn].size(); i++) { fn = rpat[cn][i].to; if(scc[fn] == 0) { re2(fn); } } return 0; } int re3(int cn,int v) { int i,j,fn; if(nmem[scc[cn]] > 1) { of = 1; fon[v] = cn; return 0; } for(i=0; i<pat[cn].size(); i++) { fn = pat[cn][i].to; if(u[fn] == -1) { continue; } lii[v].push_back(pat[cn][i].idx); re3(fn,v); if(of == 0) { u[fn] = -1; lii[v].pop_back(); } else { break; } } return 0; } int re4(int cn,int v,int tar) { int i,j,fn,fid; for(i=0; i<pat[cn].size(); i++) { fn = pat[cn][i].to; fid = pat[cn][i].idx; if(scc[cn] != scc[fn] || upa[fid] == 1 || upa[fid] == 2) { continue; } upa[fid] = 1; lii[v].push_back(fid); if(fn == tar) { upa[fid] = 2; of = 1; return 0; } re4(fn,v,tar); if(of == 0) { upa[fid] = 0; lii[v].pop_back(); } else { upa[fid] = 2; break; } } return 0; } int re5(int cn,int v) { int i,j,fn,fid; for(i=0; i<pat[cn].size(); i++) { fn = pat[cn][i].to; fid = pat[cn][i].idx; if(scc[cn] != scc[fn] || upa[fid] == 1) { continue; } if(upa[fid] == 2) { fon[3] = fid; of = 1; return 0; } upa[fid] = 1; lii[v].push_back(fid); re5(fn,v); if(of == 0) { upa[fid] = 0; lii[v].pop_back(); } else { upa[fid] = 2; break; } } return 0; } std::variant<bool, std::vector<int>> find_journey(int nn, int mm , std::vector<int> uu, std::vector<int> vv) { // return false; int i,j,cn,cm,fn,fm,cru = 0,fou = 0; n = nn; m = mm; for(i=0; i<m; i++) { pat[uu[i]].push_back({vv[i],i}); rpat[vv[i]].push_back({uu[i],i}); } cou = 0; re(0); sru = 1; for(i=0; i<cou; i++) { if(scc[in[i]] == 0) { re2(in[i]); sru ++; } } // for(i=0; i<n; i++) // { // ans.push_back(scc[i]); // } // return ans; for(i=0; i<pat[0].size(); i++) { cn = pat[0][i].to; of = 0; lii[fou].push_back(pat[0][i].idx); if(scc[cn] == scc[0]) { fon[fou] = cn; tog[fou] = 1; fou ++; if(fou == 2) { break; } continue; } re3(cn,fou); if(of == 0) { lii[fou].pop_back(); } else { fou ++; if(fou == 2) { break; } } } if(fou < 2) { return false; } // printf("\n%d %d \n",fon[0],fon[1]); if(tog[0] == tog[1] && tog[0] == 1) { of = 0; lii[2].push_back(lii[0][0]); re4(fon[0],2,0); of = 0; lii[3].push_back(lii[1][0]); re5(fon[1],3); for(i=0; i<lii[2].size(); i++) { if(fon[3] == lii[2][i]) { cn = i-1; } ans.push_back(lii[2][i]); } for(i=0; i<lii[3].size(); i++) { ans.push_back(lii[3][i]); } for(i=cn; i>=0; i--) { ans.push_back(lii[2][i]); } for(i=lii[2].size()-1; i>cn; i--) { ans.push_back(lii[2][i]); } for(i=lii[3].size()-1; i>=0; i--) { ans.push_back(lii[3][i]); } } else if(scc[fon[0]] == scc[fon[1]]) { if(fon[0] == fon[1]) { of = 0; re4(fon[0],2,fon[0]); for(i=0; i<lii[0].size(); i++) { ans.push_back(lii[0][i]); } for(i=0; i<lii[2].size(); i++) { ans.push_back(lii[2][i]); } for(i=lii[0].size()-1; i>=0; i--) { ans.push_back(lii[0][i]); } for(i=0; i<lii[1].size(); i++) { ans.push_back(lii[1][i]); } for(i=lii[2].size()-1; i>=0; i--) { ans.push_back(lii[2][i]); } for(i=lii[1].size()-1; i>=0; i--) { ans.push_back(lii[1][i]); } } else { of = 0; re4(fon[0],2,fon[1]); of = 0; re4(fon[1],3,fon[0]); for(i=0; i<lii[0].size(); i++) { ans.push_back(lii[0][i]); } for(i=0; i<lii[2].size(); i++) { ans.push_back(lii[2][i]); } for(i=0; i<lii[3].size(); i++) { ans.push_back(lii[3][i]); } for(i=lii[0].size()-1; i>=0; i--) { ans.push_back(lii[0][i]); } for(i=0; i<lii[1].size(); i++) { ans.push_back(lii[1][i]); } for(i=lii[2].size()-1; i>=0; i--) { ans.push_back(lii[2][i]); } for(i=lii[3].size()-1; i>=0; i--) { ans.push_back(lii[3][i]); } for(i=lii[1].size()-1; i>=0; i--) { ans.push_back(lii[1][i]); } } } else { of = 0; re4(fon[0],2,fon[0]); of = 0; re4(fon[1],3,fon[1]); for(i=0; i<lii[0].size(); i++) { ans.push_back(lii[0][i]); } for(i=0; i<lii[2].size(); i++) { ans.push_back(lii[2][i]); } for(i=lii[0].size()-1; i>=0; i--) { ans.push_back(lii[0][i]); } for(i=0; i<lii[1].size(); i++) { ans.push_back(lii[1][i]); } for(i=0; i<lii[3].size(); i++) { ans.push_back(lii[3][i]); } for(i=lii[1].size()-1; i>=0; i--) { ans.push_back(lii[1][i]); } for(i=0; i<lii[0].size(); i++) { ans.push_back(lii[0][i]); } for(i=lii[2].size()-1; i>=0; i--) { ans.push_back(lii[2][i]); } for(i=lii[0].size()-1; i>=0; i--) { ans.push_back(lii[0][i]); } for(i=0; i<lii[1].size(); i++) { ans.push_back(lii[1][i]); } for(i=lii[3].size()-1; i>=0; i--) { ans.push_back(lii[3][i]); } for(i=lii[1].size()-1; i>=0; i--) { ans.push_back(lii[1][i]); } } return ans; }

Compilation message (stderr)

islands.cpp: In function 'int re(int)':
islands.cpp:23:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<we>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |   for(i=0; i<pat[cn].size(); i++)
      |            ~^~~~~~~~~~~~~~~
islands.cpp:19:9: warning: unused variable 'j' [-Wunused-variable]
   19 |   int i,j,fn;
      |         ^
islands.cpp: In function 'int re2(int)':
islands.cpp:38:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<we>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |   for(i=0; i<rpat[cn].size(); i++)
      |            ~^~~~~~~~~~~~~~~~
islands.cpp:35:9: warning: unused variable 'j' [-Wunused-variable]
   35 |   int i,j,fn;
      |         ^
islands.cpp: In function 'int re3(int, int)':
islands.cpp:57:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<we>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |   for(i=0; i<pat[cn].size(); i++)
      |            ~^~~~~~~~~~~~~~~
islands.cpp:50:9: warning: unused variable 'j' [-Wunused-variable]
   50 |   int i,j,fn;
      |         ^
islands.cpp: In function 'int re4(int, int, int)':
islands.cpp:81:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<we>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   81 |   for(i=0; i<pat[cn].size(); i++)
      |            ~^~~~~~~~~~~~~~~
islands.cpp:80:9: warning: unused variable 'j' [-Wunused-variable]
   80 |   int i,j,fn,fid;
      |         ^
islands.cpp: In function 'int re5(int, int)':
islands.cpp:114:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<we>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  114 |   for(i=0; i<pat[cn].size(); i++)
      |            ~^~~~~~~~~~~~~~~
islands.cpp:113:9: warning: unused variable 'j' [-Wunused-variable]
  113 |   int i,j,fn,fid;
      |         ^
islands.cpp: In function 'std::variant<bool, std::vector<int, std::allocator<int> > > find_journey(int, int, std::vector<int>, std::vector<int>)':
islands.cpp:172:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<we>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  172 |   for(i=0; i<pat[0].size(); i++)
      |            ~^~~~~~~~~~~~~~
islands.cpp:215:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  215 |     for(i=0; i<lii[2].size(); i++)
      |              ~^~~~~~~~~~~~~~
islands.cpp:223:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  223 |     for(i=0; i<lii[3].size(); i++)
      |              ~^~~~~~~~~~~~~~
islands.cpp:246:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  246 |       for(i=0; i<lii[0].size(); i++)
      |                ~^~~~~~~~~~~~~~
islands.cpp:250:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  250 |       for(i=0; i<lii[2].size(); i++)
      |                ~^~~~~~~~~~~~~~
islands.cpp:258:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  258 |       for(i=0; i<lii[1].size(); i++)
      |                ~^~~~~~~~~~~~~~
islands.cpp:277:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  277 |       for(i=0; i<lii[0].size(); i++)
      |                ~^~~~~~~~~~~~~~
islands.cpp:281:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  281 |       for(i=0; i<lii[2].size(); i++)
      |                ~^~~~~~~~~~~~~~
islands.cpp:285:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  285 |       for(i=0; i<lii[3].size(); i++)
      |                ~^~~~~~~~~~~~~~
islands.cpp:293:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  293 |       for(i=0; i<lii[1].size(); i++)
      |                ~^~~~~~~~~~~~~~
islands.cpp:317:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  317 |     for(i=0; i<lii[0].size(); i++)
      |              ~^~~~~~~~~~~~~~
islands.cpp:321:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  321 |       for(i=0; i<lii[2].size(); i++)
      |                ~^~~~~~~~~~~~~~
islands.cpp:329:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  329 |       for(i=0; i<lii[1].size(); i++)
      |                ~^~~~~~~~~~~~~~
islands.cpp:333:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  333 |       for(i=0; i<lii[3].size(); i++)
      |                ~^~~~~~~~~~~~~~
islands.cpp:342:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  342 |       for(i=0; i<lii[0].size(); i++)
      |                ~^~~~~~~~~~~~~~
islands.cpp:354:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  354 |       for(i=0; i<lii[1].size(); i++)
      |                ~^~~~~~~~~~~~~~
islands.cpp:148:9: warning: unused variable 'j' [-Wunused-variable]
  148 |   int i,j,cn,cm,fn,fm,cru = 0,fou = 0;
      |         ^
islands.cpp:148:14: warning: unused variable 'cm' [-Wunused-variable]
  148 |   int i,j,cn,cm,fn,fm,cru = 0,fou = 0;
      |              ^~
islands.cpp:148:17: warning: unused variable 'fn' [-Wunused-variable]
  148 |   int i,j,cn,cm,fn,fm,cru = 0,fou = 0;
      |                 ^~
islands.cpp:148:20: warning: unused variable 'fm' [-Wunused-variable]
  148 |   int i,j,cn,cm,fn,fm,cru = 0,fou = 0;
      |                    ^~
islands.cpp:148:23: warning: unused variable 'cru' [-Wunused-variable]
  148 |   int i,j,cn,cm,fn,fm,cru = 0,fou = 0;
      |                       ^~~
#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...