Submission #881864

#TimeUsernameProblemLanguageResultExecution timeMemory
881864djs100201수천개의 섬 (IOI22_islands)C++17
34 / 100
1074 ms147984 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; ll prob[n_],out[n_],checked[n_]; set<P>v[n_],edge[n_],rev[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]].insert({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()){ x=q.front(); q.pop(); for(auto nxt:v[x])rev[nxt.first].erase({x,nxt.second}); for(auto nxt:rev[x]){ v[nxt.first].erase({x,nxt.second}); if(v[nxt.first].size()==0)q.push(nxt.first); } v[x].clear(),rev[x].clear(); } 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; q.push(now); ll tmp=(*v[now].begin()).first; while(q.size()){ x=q.front(); q.pop(); for(auto nxt:v[x])rev[nxt.first].erase({x,nxt.second}); for(auto nxt:rev[x]){ v[nxt.first].erase({x,nxt.second}); if(v[nxt.first].size()==0)q.push(nxt.first); } v[x].clear(),rev[x].clear(); } now = tmp; } else{ for(int i=0;i<n;i++){ if(i==now || !v[i].size())continue; auto cur=*v[i].begin(); edge[i].insert(cur); } 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...