제출 #710480

#제출 시각아이디문제언어결과실행 시간메모리
710480myrcella수천개의 섬 (IOI22_islands)C++17
3.50 / 100
452 ms7944 KiB
//by szh #include<bits/stdc++.h> using namespace std; #define fi first #define se second #define pii pair<int,int> #define pll pair<long long,long long> #define pb push_back #define debug(x) cerr<<#x<<"="<<x<<endl #define pq priority_queue #define inf 0x3f #define rep(i,a,b) for (int i=a;i<(b);i++) #define MP make_pair #define SZ(x) (int(x.size())) #define ll long long #define mod 1000000007 #define ALL(x) x.begin(),x.end() void inc(int &a,int b) {a=(a+b)%mod;} void dec(int &a,int b) {a=(a-b+mod)%mod;} int lowbit(int x) {return x&(-x);} ll p0w(ll base,ll p) {ll ret=1;while(p>0){if (p%2ll==1ll) ret=ret*base%mod;base=base*base%mod;p/=2ll;}return ret;} #include "islands.h" #include <variant> #include <vector> const int maxn = 1010; int dis[maxn][maxn]; vector <int> pos; vector <int> cyc; int cnt[maxn]; std::variant<bool, std::vector<int>> find_journey( int n, int M, std::vector<int> U, std::vector<int> V) { rep(i,0,M) { dis[U[i]][V[i]] = 1; if (U[i]==0) pos.pb(V[i]),cnt[V[i]]++; } sort(ALL(pos)); pos.erase(unique(ALL(pos)),pos.end()); rep(k,0,n) rep(i,0,n) if (dis[i][k]) rep(j,0,n) { dis[i][j]|=dis[k][j]; } rep(i,0,n) if (dis[i][i]==1) cyc.pb(i); vector <int> ret; rep(i,0,SZ(pos)) { if (dis[pos[i]][pos[i]] and cnt[pos[i]]>1) return ret; rep(j,0,i) for (int k:cyc) { if (dis[pos[i]][k] and dis[pos[j]][k]) { // cout<<pos[i]<<" "<<pos[j]<<" "<<k<<endl; return ret; } } } return false; } /* int main() { int N, M; assert(2 == scanf("%d %d", &N, &M)); std::vector<int> U(M), V(M); for (int i = 0; i < M; ++i) { assert(2 == scanf("%d %d", &U[i], &V[i])); } std::variant<bool, std::vector<int>> result = find_journey(N, M, U, V); if (result.index() == 0) { printf("0\n"); if (std::get<bool>(result)) { printf("1\n"); } else { printf("0\n"); } } else { printf("1\n"); std::vector<int> &canoes = std::get<std::vector<int>>(result); printf("%d\n", static_cast<int>(canoes.size())); for (int i = 0; i < static_cast<int>(canoes.size()); ++i) { if (i > 0) { printf(" "); } printf("%d", canoes[i]); } printf("\n"); } return 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...