이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define sz(x) ((int)((x).size()))
#define le(vec) vec[vec.size()-1]
#define all(x) (x).begin(), (x).end()
#define TSTS int ttt; cin >> ttt; while(ttt--) solve()
#define FOR(i, begin, end) for(int i = (begin); i < (end); i++)
#define FAST_IO ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef pair<long double, long double> pdd;
const int INF=1e9, MOD=1e9+7, mod=998244353;
const ll LINF=1e18;
void setIO()
{
FAST_IO;
}
void setIO(string s)
{
FAST_IO;
freopen((s+".in").c_str(), "r", stdin);
freopen((s+".out").c_str(), "w", stdout);
}
const int N=2e5+10;
int n, m, c[N], par[N], sm[N];
vi ad[N], ok[N];
map<int, vi> col;
set<int> dif;
bool can[N];
int fnd(int u)
{
return par[u]=par[u]==u?u:fnd(par[u]);
}
void mrg(int a, int b)
{
a=fnd(a); b=fnd(b);
if(a==b) return;
if(sz(ok[a])>sz(ok[b])) ok[a].swap(ok[b]);
for(auto x : ok[a]) ok[b].pb(x);
sm[b]+=sm[a];
par[a]=b;
}
int main()
{
setIO();
cin >> n >> m;
FOR(i, 0, n) cin >> c[i], dif.insert(c[i]), col[c[i]].pb(i), par[i]=i, ok[i].pb(i), can[i]=true, sm[i]=c[i];
FOR(i, 0, m)
{
int a, b;
cin >> a >> b;
ad[a-1].pb(b-1);
ad[b-1].pb(a-1);
}
for(auto val : dif){
for(auto i : col[val]){
for(auto x : ad[i]){
if(c[x]>c[i]) continue;
x=fnd(x);
if(sm[x]<c[i]){
while(sz(ok[x])){
can[ok[x].back()]=false;
ok[x].pop_back();
}
}
mrg(i, x);
}
}
}
FOR(i, 0, n) cout << can[i];
}
컴파일 시 표준 에러 (stderr) 메시지
island.cpp: In function 'void setIO(std::string)':
island.cpp:32:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
32 | freopen((s+".in").c_str(), "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
island.cpp:33:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
33 | freopen((s+".out").c_str(), "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |