Submission #2711887
Source Code Expand
#include <bits/stdc++.h>
#define F(i,a,b) for(int i=(a);i<=(b);++i)
#define F_(i,a,b) for(int i=(a);i>=(b);--i)
#define G(i,u) for(int i=head[u];i;i=nxt[i])
typedef long long ll;
const int N = 100005;
template<typename T> inline T min(T& a, T b) {return a<b?a:a=b;}
int head[N], to[N<<1], nxt[N<<1], a[N], b[N], r[N], g[N], son[N], ecnt;
void add(int u, int v) { to[++ecnt] = v; nxt[ecnt] = head[u]; head[u] = ecnt; }
bool cmp(const int& x, const int& y) { return a[x] < a[y]; }
int find(int x) { return g[x] == x? x: g[x] = find(g[x]); }
ll f[N], sum[N];
int main() {
int n, m;
scanf("%d%d", &n, &m);
F(i,1,n) {
scanf("%d%d", &a[i], &b[i]);
a[i] = std::max(a[i]-b[i],0);
r[i] = i;
}
F(i,1,m) {
int u, v;
scanf("%d%d", &u, &v);
add(u,v); add(v,u);
}
std::sort(r+1,r+n+1,cmp);
F(i,1,n) {
int x = r[i], tot = 0; g[x] = x; sum[x] = b[x];
G(j,x) {
int v = to[j], p = find(v);
if(!p || p == x) continue;
son[++tot] = p;
sum[x] += sum[p];
g[p] = x;
}
f[x] = a[x] + sum[x];
F(j,1,tot) min(f[x],sum[x]-sum[son[j]]+std::max(f[son[j]],1ll*a[x]));
}
printf("%lld\n", f[r[n]]);
return 0;
}
Submission Info
Submission Time |
|
Task |
C - Attention |
User |
Jeff_Lee |
Language |
C++14 (GCC 5.4.1) |
Score |
0 |
Code Size |
1179 Byte |
Status |
RE |
Exec Time |
124 ms |
Memory |
3968 KB |
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:19:23: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &n, &m);
^
./Main.cpp:21:30: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &a[i], &b[i]);
^
./Main.cpp:27:24: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &u, &v);
^
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
0 / 300 |
Status |
|
|
Set Name |
Test Cases |
Sample |
sample_01.txt, sample_02.txt, sample_03.txt |
All |
sample_01.txt, sample_02.txt, sample_03.txt, sample_01.txt, sample_02.txt, sample_03.txt, subtask_1_01.txt, subtask_1_02.txt, subtask_1_03.txt, subtask_1_04.txt, subtask_1_05.txt, subtask_1_06.txt, subtask_1_07.txt, subtask_1_08.txt, subtask_1_09.txt, subtask_1_10.txt, subtask_1_11.txt, subtask_1_12.txt, subtask_1_13.txt, subtask_1_14.txt, subtask_1_15.txt, subtask_1_16.txt, subtask_1_17.txt, subtask_1_18.txt, subtask_1_19.txt, subtask_1_20.txt |
Case Name |
Status |
Exec Time |
Memory |
sample_01.txt |
WA |
2 ms |
2304 KB |
sample_02.txt |
WA |
2 ms |
2304 KB |
sample_03.txt |
WA |
2 ms |
2304 KB |
subtask_1_01.txt |
RE |
121 ms |
2304 KB |
subtask_1_02.txt |
AC |
6 ms |
3200 KB |
subtask_1_03.txt |
RE |
112 ms |
2304 KB |
subtask_1_04.txt |
RE |
111 ms |
2304 KB |
subtask_1_05.txt |
AC |
10 ms |
3968 KB |
subtask_1_06.txt |
RE |
123 ms |
2432 KB |
subtask_1_07.txt |
RE |
122 ms |
2432 KB |
subtask_1_08.txt |
RE |
123 ms |
2432 KB |
subtask_1_09.txt |
RE |
115 ms |
2304 KB |
subtask_1_10.txt |
RE |
123 ms |
2560 KB |
subtask_1_11.txt |
RE |
122 ms |
2432 KB |
subtask_1_12.txt |
RE |
123 ms |
2560 KB |
subtask_1_13.txt |
RE |
123 ms |
2560 KB |
subtask_1_14.txt |
RE |
123 ms |
2560 KB |
subtask_1_15.txt |
RE |
123 ms |
2432 KB |
subtask_1_16.txt |
RE |
123 ms |
2432 KB |
subtask_1_17.txt |
RE |
124 ms |
2432 KB |
subtask_1_18.txt |
RE |
124 ms |
2432 KB |
subtask_1_19.txt |
RE |
122 ms |
2560 KB |
subtask_1_20.txt |
RE |
124 ms |
2432 KB |