제출 #826776

#제출 시각아이디문제언어결과실행 시간메모리
826776Amylopectin수천개의 섬 (IOI22_islands)C++17
31 / 100
1094 ms82652 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 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; 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) { 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 || cue[fid] == 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; } } 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; } of = 0; re3(cn,fou); if(of == 0) { lii[fou].pop_back(); } else { fou ++; if(fou == 2) { break; } } } if(fou < 2) { return false; } 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; 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]); 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; 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; re4(fon[0],2,fon[1]); if(of == 0) { return false; } of = 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; re4(cst,2,cst); lii[0].clear(); } else { of = 0; re4(fon[0],2,fon[0]); } if(of == 0) { return false; } if(tog[1] == 1) { of = 0; re4(cst,3,cst); lii[1].clear(); } else { of = 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 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:21:9: warning: unused variable 'j' [-Wunused-variable]
   21 |   int i,j,fn;
      |         ^
islands.cpp: In function 'int re2(int)':
islands.cpp:40:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<we>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |   for(i=0; i<rpat[cn].size(); i++)
      |            ~^~~~~~~~~~~~~~~~
islands.cpp:37:9: warning: unused variable 'j' [-Wunused-variable]
   37 |   int i,j,fn;
      |         ^
islands.cpp: In function 'int re3(int, int)':
islands.cpp:59:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<we>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |   for(i=0; i<pat[cn].size(); i++)
      |            ~^~~~~~~~~~~~~~~
islands.cpp:52:9: warning: unused variable 'j' [-Wunused-variable]
   52 |   int i,j,fn,fid;
      |         ^
islands.cpp: In function 'int re4(int, int, int)':
islands.cpp:84:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<we>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   84 |   for(i=0; i<pat[cn].size(); i++)
      |            ~^~~~~~~~~~~~~~~
islands.cpp:83:9: warning: unused variable 'j' [-Wunused-variable]
   83 |   int i,j,fn,fid;
      |         ^
islands.cpp: In function 'int re5(int, int)':
islands.cpp:117:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<we>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  117 |   for(i=0; i<pat[cn].size(); i++)
      |            ~^~~~~~~~~~~~~~~
islands.cpp:116:9: warning: unused variable 'j' [-Wunused-variable]
  116 |   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:182:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<we>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  182 |     for(i=0; i<rpat[cn].size(); i++)
      |              ~^~~~~~~~~~~~~~~~
islands.cpp:186:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<we>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  186 |       if(cup[fn] == pat[fn].size())
      |          ~~~~~~~~^~~~~~~~~~~~~~~~~
islands.cpp:197:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<we>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  197 |     for(i=0; i<pat[cst].size(); i++)
      |              ~^~~~~~~~~~~~~~~~
islands.cpp:209:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<we>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  209 |     for(i=0; i<pat[cst].size(); i++)
      |              ~^~~~~~~~~~~~~~~~
islands.cpp:240:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<we>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  240 |   for(i=0; i<pat[cst].size(); i++)
      |            ~^~~~~~~~~~~~~~~~
islands.cpp:279:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  279 |   for(i=0; i<stc.size(); i++)
      |            ~^~~~~~~~~~~
islands.cpp:304:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  304 |     for(i=0; i<lii[2].size(); i++)
      |              ~^~~~~~~~~~~~~~
islands.cpp:312:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  312 |     for(i=0; i<lii[3].size(); i++)
      |              ~^~~~~~~~~~~~~~
islands.cpp:339:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  339 |       for(i=0; i<lii[0].size(); i++)
      |                ~^~~~~~~~~~~~~~
islands.cpp:343:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  343 |       for(i=0; i<lii[2].size(); i++)
      |                ~^~~~~~~~~~~~~~
islands.cpp:351:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  351 |       for(i=0; i<lii[1].size(); i++)
      |                ~^~~~~~~~~~~~~~
islands.cpp:378:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  378 |       for(i=0; i<lii[0].size(); i++)
      |                ~^~~~~~~~~~~~~~
islands.cpp:382:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  382 |       for(i=0; i<lii[2].size(); i++)
      |                ~^~~~~~~~~~~~~~
islands.cpp:386:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  386 |       for(i=0; i<lii[3].size(); i++)
      |                ~^~~~~~~~~~~~~~
islands.cpp:394:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  394 |       for(i=0; i<lii[1].size(); i++)
      |                ~^~~~~~~~~~~~~~
islands.cpp:444:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  444 |     for(i=0; i<lii[0].size(); i++)
      |              ~^~~~~~~~~~~~~~
islands.cpp:448:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  448 |       for(i=0; i<lii[2].size(); i++)
      |                ~^~~~~~~~~~~~~~
islands.cpp:456:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  456 |       for(i=0; i<lii[1].size(); i++)
      |                ~^~~~~~~~~~~~~~
islands.cpp:460:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  460 |       for(i=0; i<lii[3].size(); i++)
      |                ~^~~~~~~~~~~~~~
islands.cpp:469:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  469 |       for(i=0; i<lii[0].size(); i++)
      |                ~^~~~~~~~~~~~~~
islands.cpp:481:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  481 |       for(i=0; i<lii[1].size(); i++)
      |                ~^~~~~~~~~~~~~~
islands.cpp:151:9: warning: unused variable 'j' [-Wunused-variable]
  151 |   int i,j,cn,cm,fn,fm,cru = 0,fou = 0,cst,ccou;
      |         ^
islands.cpp:151:14: warning: unused variable 'cm' [-Wunused-variable]
  151 |   int i,j,cn,cm,fn,fm,cru = 0,fou = 0,cst,ccou;
      |              ^~
islands.cpp:151:20: warning: unused variable 'fm' [-Wunused-variable]
  151 |   int i,j,cn,cm,fn,fm,cru = 0,fou = 0,cst,ccou;
      |                    ^~
islands.cpp:151:23: warning: unused variable 'cru' [-Wunused-variable]
  151 |   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...