# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
945463 |
2024-03-13T20:34:24 Z |
LucaIlie |
Graph (BOI20_graph) |
C++17 |
|
2 ms |
4700 KB |
#include <bits/stdc++.h>
using namespace std;
struct edge {
int u, v, c;
int other( int x ) {
return u ^ v ^ x;
}
};
const int MAX_N = 1e5;
const int MAX_M = 2e5;
bool vis[MAX_N + 1];
int a[MAX_N + 1], b[MAX_N + 1];
double val[MAX_N + 1];
edge edges[MAX_M];
vector<int> adj[MAX_N + 1];
bool sePoate;
bool fixedX;
double x;
vector<int> vert;
void dfs( int u ) {
vert.push_back( u );
vis[u] = true;
for ( int e: adj[u] ) {
int v = edges[e].other( u ), c = edges[e].c;
if ( !vis[v] ) {
a[v] = -a[u];
b[v] = c - b[u];
dfs( v );
} else {
if ( a[u] + a[v] == 0 ) {
if ( b[u] + b[v] != c )
sePoate = false;
} else {
double xx = ((double)c - b[u] - b[v]) / (a[u] + a[v]);
if ( fixedX && x != xx )
sePoate = false;
else {
fixedX = true;
x = xx;
}
}
}
}
}
int main() {
int n, m;
cin >> n >> m;
for ( int i = 0; i < m; i++ ) {
cin >> edges[i].u >> edges[i].v >> edges[i].c;
adj[edges[i].u].push_back( i );
adj[edges[i].v].push_back( i );
}
for ( int v = 1; v <= n; v++ ) {
if ( vis[v] )
continue;
a[v] = 1;
b[v] = 0;
sePoate = true;
fixedX = false;
vert.clear();
dfs( v );
if ( !sePoate ) {
cout << "NO\n";
return 0;
}
//for ( int u: vert )
// cout << u << " " << a[u] << " " << b[u] << "\n";
if ( !fixedX ) {
map<int, vector<int>> events;
int sa = 0, sb = 0;
for ( int u: vert ) {
sa--;
if ( a[u] == 1 )
sb -= b[u];
else
sb += b[u];
events[(-b[u] / a[u])].push_back( u );
//cout << (-b[u] / a[u]) << "\n";
}
int minS = 1e9;
for ( auto p: events ) {
for ( int u: p.second ) {
if ( a[u] == 1 ) {
sa += 2;
sb += b[u] * 2;
} else {
sa -= 2;
sb -= b[u] * 2;
}
}
int xx = p.first;
if ( sa >= 0 )
xx = p.first;
if ( sa * xx + sb < minS ) {
minS = sa * xx + sb;
x = xx;
}
//cout << xx << " " << sa << " " << sb << " " << sa * xx + sb << "\n";
}
}
for ( int u: vert )
val[u] = x * a[u] + b[u];
}
cout << "YES\n";
for ( int v = 1; v <= n; v++ )
cout << val[v] << " ";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4696 KB |
answer = YES |
2 |
Correct |
1 ms |
4700 KB |
answer = YES |
3 |
Incorrect |
2 ms |
4700 KB |
participant answer is larger than the answer of jury |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4696 KB |
answer = YES |
2 |
Correct |
1 ms |
4700 KB |
answer = YES |
3 |
Incorrect |
2 ms |
4700 KB |
participant answer is larger than the answer of jury |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4696 KB |
answer = YES |
2 |
Correct |
1 ms |
4700 KB |
answer = YES |
3 |
Incorrect |
2 ms |
4700 KB |
participant answer is larger than the answer of jury |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4696 KB |
answer = YES |
2 |
Correct |
1 ms |
4700 KB |
answer = YES |
3 |
Incorrect |
2 ms |
4700 KB |
participant answer is larger than the answer of jury |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4696 KB |
answer = YES |
2 |
Correct |
1 ms |
4700 KB |
answer = YES |
3 |
Incorrect |
2 ms |
4700 KB |
participant answer is larger than the answer of jury |
4 |
Halted |
0 ms |
0 KB |
- |