제출 #828409

#제출 시각아이디문제언어결과실행 시간메모리
828409Amylopectin수천개의 섬 (IOI22_islands)C++17
19.25 / 100
78 ms80844 KiB
#include "islands.h" #include <stdio.h> #include <variant> #include <vector> #include <algorithm> #include <iostream> #include <queue> using namespace std; const int mxn = 1e6 + 10,mxm = 1e6 + 10; struct we { int to,idx; }; vector<struct we> pat[mxn] = {},rpat[mxn] = {}; vector<int> lii[mxn] = {},ans,stc; queue<int> qu; int n,m,u[mxn] = {},ou[mxn] = {},scc[mxn] = {},cou,sru,nmem[mxn] = {},fon[mxn] = {} ,tog[mxn] = {},upa[mxm] = {},of,cup[mxn] = {},cuu[mxn] = {},cue[mxm] = {}; int setu(int l) { int i,j; for(i=0; i<n; i++) { u[i] = 0; } return 0; } int re(int cn) { int i,j,fn; u[cn] = 1; for(i=0; i<pat[cn].size(); i++) { fn = pat[cn][i].to; if(u[fn] == 0) { re(fn); } } ou[cou] = cn; cou ++; 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,fid; 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; fid = pat[cn][i].idx; if(u[fn] == -1 || cue[fid] == 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; u[cn] = 1; 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 || cue[fid] == 1 || u[fn] == 1) { 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; } } u[cn] = 0; return 0; } int re5(int cn,int v) { int i,j,fn,fid; u[cn] = 1; 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 || cue[fid] == 1 || u[fn] == 1) { continue; } if(upa[fid] == 2) { fon[v] = 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; } } u[cn] = 0; 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,cst,ccou; 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=cou-1; i>=0; i--) { if(scc[ou[i]] == 0) { re2(ou[i]); sru ++; } } for(i=0; i<n; i++) { if(pat[i].size() == 0) { qu.push(i); } } while(!qu.empty()) { cn = qu.front(); qu.pop(); cuu[cn] = 1; for(i=0; i<rpat[cn].size(); i++) { fn = rpat[cn][i].to; cup[fn] ++; if(cup[fn] == pat[fn].size()) { qu.push(fn); } } } cst = 0; // pat[cst].size() - cup[cst] == 1 while(1) { ccou = 0; for(i=0; i<pat[cst].size(); i++) { fn = pat[cst][i].to; if(cuu[fn] == 0) { ccou ++; } } if(ccou != 1) { break; } for(i=0; i<pat[cst].size(); i++) { fn = pat[cst][i].to; if(cuu[fn] == 0) { cue[pat[cst][i].idx] = 1; cuu[cst] = 1; stc.push_back(pat[cst][i].idx); cst = fn; break; } } } // printf("\n"); // for(i=0; i<n; i++) // { // if(cuu[i] == 0) // for(j=0; j<pat[i].size(); j++) // { // fn = pat[i][j].to; // if(cuu[fn] == 0 && scc[i] == scc[fn] && scc[i] == 2) // { // printf("%d %d\n",i,fn); // } // } // } // for(i=0; i<n; i++) // { // ans.push_back(scc[i]); // } // return ans; for(i=0; i<pat[cst].size(); i++) { cn = pat[cst][i].to; if(cuu[cn] == 1) { continue; } of = 0; lii[fou].push_back(pat[cst][i].idx); if(scc[cn] == scc[cst]) { fon[fou] = cn; tog[fou] = 1; fou ++; if(fou == 2) { break; } continue; } fou ++; if(fou == 2) { break; } // of = 0; // re3(cn,fou); // if(of == 0) // { // lii[fou].pop_back(); // } // else // { // fou ++; // if(fou == 2) // { // break; // } // } } if(fou < 2) { return false; } return ans; for(i=0; i<stc.size(); i++) { ans.push_back(stc[i]); } // printf("\n%d %d \n",fon[0],fon[1]); if(tog[0] == tog[1] && tog[0] == 1) { of = 0; setu(0); upa[lii[0][0]] = 1; lii[2].push_back(lii[0][0]); re4(fon[0],2,cst); if(of == 0) { return false; } upa[lii[0][0]] = 2; of = 0; upa[lii[1][0]] = 1; lii[3].push_back(lii[1][0]); setu(0); re5(fon[1],3); if(of == 0) { return false; } upa[lii[1][0]] = 2; 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; setu(0); re4(fon[0],2,fon[0]); if(of == 0) { return false; } 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; setu(0); re4(fon[0],2,fon[1]); if(of == 0) { return false; } of = 0; setu(0); re4(fon[1],3,fon[0]); if(of == 0) { return false; } 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 { if(tog[0] == 1) { of = 0; setu(0); re4(cst,2,cst); lii[0].clear(); } else { of = 0; setu(0); re4(fon[0],2,fon[0]); } if(of == 0) { return false; } if(tog[1] == 1) { of = 0; setu(0); re4(cst,3,cst); lii[1].clear(); } else { of = 0; setu(0); re4(fon[1],3,fon[1]); } if(of == 0) { return false; } 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]); } } for(i=stc.size()-1; i>=0; i--) { ans.push_back(stc[i]); } return ans; }

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

islands.cpp: In function 'int setu(int)':
islands.cpp:21:9: warning: unused variable 'j' [-Wunused-variable]
   21 |   int i,j;
      |         ^
islands.cpp: In function 'int re(int)':
islands.cpp:32:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<we>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |   for(i=0; i<pat[cn].size(); i++)
      |            ~^~~~~~~~~~~~~~~
islands.cpp:30:9: warning: unused variable 'j' [-Wunused-variable]
   30 |   int i,j,fn;
      |         ^
islands.cpp: In function 'int re2(int)':
islands.cpp:49:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<we>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |   for(i=0; i<rpat[cn].size(); i++)
      |            ~^~~~~~~~~~~~~~~~
islands.cpp:46:9: warning: unused variable 'j' [-Wunused-variable]
   46 |   int i,j,fn;
      |         ^
islands.cpp: In function 'int re3(int, int)':
islands.cpp:68:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<we>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |   for(i=0; i<pat[cn].size(); i++)
      |            ~^~~~~~~~~~~~~~~
islands.cpp:61:9: warning: unused variable 'j' [-Wunused-variable]
   61 |   int i,j,fn,fid;
      |         ^
islands.cpp: In function 'int re4(int, int, int)':
islands.cpp:95:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<we>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   95 |   for(i=0; i<pat[cn].size(); i++)
      |            ~^~~~~~~~~~~~~~~
islands.cpp:93:9: warning: unused variable 'j' [-Wunused-variable]
   93 |   int i,j,fn,fid;
      |         ^
islands.cpp: In function 'int re5(int, int)':
islands.cpp:130:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<we>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  130 |   for(i=0; i<pat[cn].size(); i++)
      |            ~^~~~~~~~~~~~~~~
islands.cpp:128:9: warning: unused variable 'j' [-Wunused-variable]
  128 |   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:196:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<we>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  196 |     for(i=0; i<rpat[cn].size(); i++)
      |              ~^~~~~~~~~~~~~~~~
islands.cpp:200:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<we>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  200 |       if(cup[fn] == pat[fn].size())
      |          ~~~~~~~~^~~~~~~~~~~~~~~~~
islands.cpp:211:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<we>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  211 |     for(i=0; i<pat[cst].size(); i++)
      |              ~^~~~~~~~~~~~~~~~
islands.cpp:223:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<we>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  223 |     for(i=0; i<pat[cst].size(); i++)
      |              ~^~~~~~~~~~~~~~~~
islands.cpp:254:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<we>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  254 |   for(i=0; i<pat[cst].size(); i++)
      |            ~^~~~~~~~~~~~~~~~
islands.cpp:299:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  299 |   for(i=0; i<stc.size(); i++)
      |            ~^~~~~~~~~~~
islands.cpp:326:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  326 |     for(i=0; i<lii[2].size(); i++)
      |              ~^~~~~~~~~~~~~~
islands.cpp:334:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  334 |     for(i=0; i<lii[3].size(); i++)
      |              ~^~~~~~~~~~~~~~
islands.cpp:362:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  362 |       for(i=0; i<lii[0].size(); i++)
      |                ~^~~~~~~~~~~~~~
islands.cpp:366:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  366 |       for(i=0; i<lii[2].size(); i++)
      |                ~^~~~~~~~~~~~~~
islands.cpp:374:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  374 |       for(i=0; i<lii[1].size(); i++)
      |                ~^~~~~~~~~~~~~~
islands.cpp:403:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  403 |       for(i=0; i<lii[0].size(); i++)
      |                ~^~~~~~~~~~~~~~
islands.cpp:407:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  407 |       for(i=0; i<lii[2].size(); i++)
      |                ~^~~~~~~~~~~~~~
islands.cpp:411:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  411 |       for(i=0; i<lii[3].size(); i++)
      |                ~^~~~~~~~~~~~~~
islands.cpp:419:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  419 |       for(i=0; i<lii[1].size(); i++)
      |                ~^~~~~~~~~~~~~~
islands.cpp:473:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  473 |     for(i=0; i<lii[0].size(); i++)
      |              ~^~~~~~~~~~~~~~
islands.cpp:477:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  477 |       for(i=0; i<lii[2].size(); i++)
      |                ~^~~~~~~~~~~~~~
islands.cpp:485:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  485 |       for(i=0; i<lii[1].size(); i++)
      |                ~^~~~~~~~~~~~~~
islands.cpp:489:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  489 |       for(i=0; i<lii[3].size(); i++)
      |                ~^~~~~~~~~~~~~~
islands.cpp:498:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  498 |       for(i=0; i<lii[0].size(); i++)
      |                ~^~~~~~~~~~~~~~
islands.cpp:510:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  510 |       for(i=0; i<lii[1].size(); i++)
      |                ~^~~~~~~~~~~~~~
islands.cpp:165:9: warning: unused variable 'j' [-Wunused-variable]
  165 |   int i,j,cn,cm,fn,fm,cru = 0,fou = 0,cst,ccou;
      |         ^
islands.cpp:165:14: warning: unused variable 'cm' [-Wunused-variable]
  165 |   int i,j,cn,cm,fn,fm,cru = 0,fou = 0,cst,ccou;
      |              ^~
islands.cpp:165:20: warning: unused variable 'fm' [-Wunused-variable]
  165 |   int i,j,cn,cm,fn,fm,cru = 0,fou = 0,cst,ccou;
      |                    ^~
islands.cpp:165:23: warning: unused variable 'cru' [-Wunused-variable]
  165 |   int i,j,cn,cm,fn,fm,cru = 0,fou = 0,cst,ccou;
      |                       ^~~
#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...