답안 #703462

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
703462 2023-02-27T12:37:09 Z Chal1shkan Stranded Far From Home (BOI22_island) C++14
0 / 100
1000 ms 32004 KB
# include <bits/stdc++.h>
 
# define pb push_back
# define ff first
# define ss second
# define nl "\n"
# define sz(x) ((int)(x).size())
# define deb(x) cerr << #x  << " = " << x << endl; 
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
 
const ll maxn = 2e5 + 25;
const ll inf = 2e9 + 0;
const ll mod = 998244353;
const ll dx[] = {-1, 1, 0, 0};
const ll dy[] = {0, 0, -1, 1};
 
using namespace std;

ll n, m, s[maxn];
vector <ll> g[maxn];
ll q[maxn];
bool used[maxn];

void dfs (ll v)
{
	used[v] = 1;
	vector <pair <ll, ll> > x;
	for (ll to : g[v])
	{
		if (!used[to])
		{
			x.pb({s[to], to});
		}
	}
	sort(x.begin(), x.end());
	for (auto i : x)
	{
		ll to = i.ss;
		if (!used[to] && q[v] >= s[to])
		{
			q[v] += s[to];
			dfs(to);
		}
	}
}

void ma1n (/* SABR */)
{
	cin >> n >> m;
	for (ll i = 1; i <= n; ++i)
	{
		cin >> s[i];
		q[i] = s[i];
	}
	for (ll i = 1, u, v; i <= m; ++i)
	{
		cin >> u >> v;
		g[u].pb(v);
		g[v].pb(u);	
	}	
	string ans = "";
	for (ll i = 1; i <= n; ++i)
	{
		dfs(i);
		bool ok = 1;
		for (ll j = 1; j <= n; ++j)
		{
			if (!used[j]) ok = 0;
		}
		ans += char(ok + '0');
		memset(used, 0, sizeof(used));
	}
	cout << ans;
}
 
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
//  freopen("file.in", "r", stdin);
//  freopen("file.out", "w", stdout);
    int ttt = 1;
//  cin >> ttt;
    for (int test = 1; test <= ttt; ++test)
    {
//      cout << "Case " << test << ":" << ' ';
        ma1n();
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5144 KB Output is correct
2 Correct 3 ms 5204 KB Output is correct
3 Correct 3 ms 5164 KB Output is correct
4 Incorrect 27 ms 5336 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5156 KB Output is correct
2 Correct 4 ms 5132 KB Output is correct
3 Execution timed out 1068 ms 32004 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 5204 KB Output is correct
2 Execution timed out 1060 ms 18976 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5204 KB Output is correct
2 Execution timed out 1064 ms 20164 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 5144 KB Output is correct
2 Correct 3 ms 5204 KB Output is correct
3 Correct 3 ms 5164 KB Output is correct
4 Incorrect 27 ms 5336 KB Output isn't correct
5 Halted 0 ms 0 KB -