Submission #881854

#TimeUsernameProblemLanguageResultExecution timeMemory
881854djs100201Thousands Islands (IOI22_islands)C++17
34 / 100
1038 ms145412 KiB
#include "islands.h" #include <variant> #include<bits/stdc++.h> #define all(v) v.begin(),v.end() using namespace std; using ll = int; using P = pair<ll, ll>; using PP = pair<ll, P>; const ll n_ = 1e5 + 505, inf = (ll)2e9 * (ll)1e9 + 7, mod = 998244353; ll n, m, tc = 1, a, b, c, d, sum, x, y, z, base, ans, k; vector<P>rev[n_]; ll prob[n_],out[n_],checked[n_]; set<P>v[n_],edge[n_]; P To[n_]; variant<bool, std::vector<int>> find_journey(int N, int M, std::vector<int> U, std::vector<int> V) { n=N,m=M; for(int i=0;i<m;i++){ out[U[i]]++; v[U[i]].insert({V[i],i}); rev[V[i]].push_back({U[i],i}); } fill(prob,prob+n+1,1); //가능성이 존재한다. queue<ll>q; for(int i=0;i<n;i++){ if(v[i].size())continue; q.push(i); } while(q.size()){ a=q.front(); q.pop(); prob[a]=0; for(auto nxt:rev[a]){ v[nxt.first].erase({a,nxt.second}); if(v[nxt.first].size()==0){ q.push(nxt.first); } } } ll now=0; vector<int>ret,ret_rev; while(1){ if(!v[now].size())return false; if(v[now].size()==1){ ret.push_back((*v[now].begin()).second); ret_rev.push_back((*v[now].begin()).second); queue<ll>q; for(auto nxt:rev[now]){ v[nxt.first].erase({now,nxt.second}); if(v[nxt.first].size()==0)q.push(nxt.first); } while(q.size()){ x=q.front(); q.pop(); for(auto nxt:rev[x]){ v[nxt.first].erase({now,nxt.second}); if(v[nxt.first].size()==0)q.push(nxt.first); } } out[now]=0; now=(*v[now].begin()).first; } else{ for(int i=0;i<n;i++){ if(i==now || !v[i].size())continue; auto cur=*v[i].begin(); //v[i].clear(); edge[i].insert(cur); //cout<<i<<' '<<cur.first<<' '<<cur.second<<endl; //v[i].insert(a); } auto it=v[now].end(); it--; edge[now].insert(*it); it--; edge[now].insert(*it); x=now; ll bef=-1,cnt=0; vector<int>inv(m); while(1){ P nxt; for(auto i:edge[x]){ if(i.second==bef)continue; nxt=i; bef=i.second; break; } if(inv[nxt.second])cnt--; else cnt++; inv[nxt.second]^=1; edge[nxt.first].insert({x,nxt.second}); edge[x].erase(nxt); ret.push_back(nxt.second); x=nxt.first; if(now==0 && cnt==0)break; } break; } } reverse(all(ret_rev)); for(auto i:ret_rev)ret.push_back(i); return ret; }

Compilation message (stderr)

islands.cpp:9:40: warning: integer overflow in expression of type 'll' {aka 'int'} results in '1321730048' [-Woverflow]
    9 | const ll n_ = 1e5 + 505, inf = (ll)2e9 * (ll)1e9 + 7, mod = 998244353;
      |                                ~~~~~~~~^~~~~~~~~
#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...