# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
230454 | BamiTorabi | Pipes (BOI13_pipes) | C++14 | 505 ms | 56416 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//Sasayego! Sasayego! Shinzou wo Sasageyo!
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <ctime>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <numeric>
#include <bitset>
#include <ctime>
#define debug(x) cerr << #x << " = " << x << endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair <ll, ll> pll;
typedef pair <int, int> pii;
const int maxN = 1e5 + 5;
const int maxM = 5e5 + 5;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
bool mark[maxN];
int c[maxN];
set <int> G[maxN];
vector <int> vec;
vector <pii> E;
map <pii, int> mp;
queue <int> Q;
pii sorted(int u, int v){
pii pp = {u, v};
if (pp.first > pp.second)
swap(pp.first, pp.second);
return pp;
}
int main(){
time_t START = clock();
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n, m; scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++){
scanf("%d", c + i);
c[i] *= 2;
}
for (int i = 0; i < m; i++){
int u, v; scanf("%d%d", &u, &v);
tie(u, v) = sorted(u, v);
G[u].insert(v);
G[v].insert(u);
E.push_back({u, v});
}
if (m > n)
return printf("0\n"), 0;
for (int i = 1; i <= n; i++)
if ((int)G[i].size() == 1)
Q.push(i);
while (!Q.empty()){
int v = Q.front();
Q.pop();
if ((int)G[v].size() != 1)
continue;
int u = *G[v].begin();
G[v].clear();
mp[sorted(u, v)] = c[v];
c[u] -= c[v];
G[u].erase(G[u].lower_bound(v));
if ((int)G[u].size() == 1)
Q.push(u);
}
int cnt = 0;
for (int i = 1; i <= n; i++)
cnt += ((int)G[i].size() == 2);
if (cnt > 0 && cnt % 2 == 0)
return printf("0\n"), 0;
if (cnt)
for (int i = 1; i <= n; i++)
if ((int)G[i].size() == 2){
vec.push_back(i);
int u = *(G[i].begin());
G[i].erase(G[i].begin());
int x = *(G[i].begin());
G[x].erase(G[x].lower_bound(i));
ll ans = c[i];
while (x != i){
vec.push_back(x);
ans = c[x] - ans;
int y = *(G[x].begin());
G[x].erase(G[x].begin());
if (y != i)
G[y].erase(G[y].lower_bound(x));
x = y;
}
c[u] -= ans / 2;
c[i] -= ans / 2;
mp[sorted(i, u)] = ans / 2;
break;
}
for (int i = 1; i < (int)vec.size(); i++){
mp[sorted(vec[i - 1], vec[i])] = c[vec[i - 1]];
c[vec[i]] -= c[vec[i - 1]];
}
for (pii e : E)
printf("%d\n", mp[e]);
time_t FINISH = clock();
cerr << "Execution time: " << (ld)(FINISH - START) / CLOCKS_PER_SEC * 1000.0 << " milliseconds.\n";
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |