이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//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;
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]);
}
rep(k,0,n) rep(i,0,n) rep(j,0,n) {
dis[i][j]|=(dis[i][k]&dis[k][j]);
}
rep(i,0,n) if (dis[i][i]==1) cyc.pb(i);
vector <int> ret;
rep(i,0,SZ(pos))
rep(j,0,i)
for (int k:cyc) {
if (dis[pos[i]][k] and dis[pos[j]][k]) 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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |