# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
915155 |
2024-01-23T12:18:01 Z |
Abito |
Graph (BOI20_graph) |
C++14 |
|
700 ms |
8788 KB |
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define F first
#define S second
#define pb push_back
#define ppb pop_back
#define ep insert
#define endl '\n'
#define elif else if
#define pow pwr
#define sqrt sqrtt
//#define int long long
#define ll long long
#define y1 YONE
#define free freeee
#define lcm llcm
/*
⠄⠄⠄⠄⢠⣿⣿⣿⣿⣿⢻⣿⣿⣿⣿⣿⣿⣿⣿⣯⢻⣿⣿⣿⣿⣆⠄⠄⠄
⠄⠄⣼⢀⣿⣿⣿⣿⣏⡏⠄⠹⣿⣿⣿⣿⣿⣿⣿⣿⣧⢻⣿⣿⣿⣿⡆⠄⠄
⠄⠄⡟⣼⣿⣿⣿⣿⣿⠄⠄⠄⠈⠻⣿⣿⣿⣿⣿⣿⣿⣇⢻⣿⣿⣿⣿⠄⠄
⠄⢰⠃⣿⣿⠿⣿⣿⣿⠄⠄⠄⠄⠄⠄⠙⠿⣿⣿⣿⣿⣿⠄⢿⣿⣿⣿⡄⠄
⠄⢸⢠⣿⣿⣧⡙⣿⣿⡆⠄⠄⠄⠄⠄⠄⠄⠈⠛⢿⣿⣿⡇⠸⣿⡿⣸⡇⠄
⠄⠈⡆⣿⣿⣿⣿⣦⡙⠳⠄⠄⠄⠄⠄⠄⢀⣠⣤⣀⣈⠙⠃⠄⠿⢇⣿⡇⠄
⠄⠄⡇⢿⣿⣿⣿⣿⡇⠄⠄⠄⠄⠄⣠⣶⣿⣿⣿⣿⣿⣿⣷⣆⡀⣼⣿⡇⠄
⠄⠄⢹⡘⣿⣿⣿⢿⣷⡀⠄⢀⣴⣾⣟⠉⠉⠉⠉⣽⣿⣿⣿⣿⠇⢹⣿⠃⠄
⠄⠄⠄⢷⡘⢿⣿⣎⢻⣷⠰⣿⣿⣿⣿⣦⣀⣀⣴⣿⣿⣿⠟⢫⡾⢸⡟⠄.
⠄⠄⠄⠄⠻⣦⡙⠿⣧⠙⢷⠙⠻⠿⢿⡿⠿⠿⠛⠋⠉⠄⠂⠘⠁⠞⠄⠄⠄
⠄⠄⠄⠄⠄⠈⠙⠑⣠⣤⣴⡖⠄⠿⣋⣉⣉⡁⠄⢾⣦⠄⠄⠄⠄⠄⠄⠄⠄
*/
typedef unsigned long long ull;
using namespace std;
const int N=2e5+5;
int a[N],n,m,e[N][3],val[N];
vector<pair<int,int>> adj[N];
bool vis[N],used[N];
set<int> comp;
void getcomp(int x){
comp.ep(x);
vis[x]=true;
for (auto u:adj[x]){
if (vis[u.F] || used[u.F]) continue;
getcomp(u.F);
}return;
}
void bfs(int s){
queue<int> q;
q.push(s);
vis[s]=true;
while (!q.empty()){
int x=q.front();
q.pop();
for (auto u:adj[x]){
if (vis[u.F] || used[u.F]) continue;
a[u.F]=u.S-a[x];
vis[u.F]=true;
q.push(u.F);
}
}return;
}
bool check(int x){
bool y=true;
vis[x]=true;
for (auto u:adj[x]){
y&=(a[u.F]+a[x]==u.S);
if (!y) return 0;
if (!vis[u.F]) y&=check(u.F);
if (!y) return 0;
}return y;
}
int32_t main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
cin>>n>>m;
for (int i=1;i<=m;i++){
for (int j=0;j<3;j++) cin>>e[i][j];
e[i][2]*=1000000;
adj[e[i][0]].pb({e[i][1],e[i][2]});
adj[e[i][1]].pb({e[i][0],e[i][2]});
}
int ans=0;
bool ok=true;
for (int i=1;i<=n;i++){
if (used[i]) continue;
getcomp(i);
int ansx=INT_MAX;
for (int x=-2e6;x<=2e6;x++){
for (auto u:comp) vis[u]=false;
a[i]=x;
bfs(i);
for (auto u:comp) vis[u]=false;
bool y=check(i);
if (!y) continue;
int s=0;
for (auto u:comp) s+=abs(a[u]);
if (s<ansx){
for (auto u:comp) val[u]=a[u];
ansx=s;
}
}
//for (int i=1;i<=n;i++) cout<<a[i]<<' ';
//cout<<endl;
if (ansx==INT_MAX) ok=false;
else ans+=ansx;
for (auto u:comp) used[u]=true;
}
if (!ok) cout<<"NO"<<endl;
else{
cout<<"YES"<<endl;
for (int i=1;i<=n;i++) cout<<fixed<<setprecision(9)<<val[i]/double(1e6)<<' ';
cout<<endl;
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
282 ms |
8788 KB |
answer = YES |
2 |
Correct |
287 ms |
8644 KB |
answer = YES |
3 |
Correct |
353 ms |
8648 KB |
answer = YES |
4 |
Correct |
491 ms |
8540 KB |
answer = NO |
5 |
Execution timed out |
980 ms |
8644 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
282 ms |
8788 KB |
answer = YES |
2 |
Correct |
287 ms |
8644 KB |
answer = YES |
3 |
Correct |
353 ms |
8648 KB |
answer = YES |
4 |
Correct |
491 ms |
8540 KB |
answer = NO |
5 |
Execution timed out |
980 ms |
8644 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
282 ms |
8788 KB |
answer = YES |
2 |
Correct |
287 ms |
8644 KB |
answer = YES |
3 |
Correct |
353 ms |
8648 KB |
answer = YES |
4 |
Correct |
491 ms |
8540 KB |
answer = NO |
5 |
Execution timed out |
980 ms |
8644 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
282 ms |
8788 KB |
answer = YES |
2 |
Correct |
287 ms |
8644 KB |
answer = YES |
3 |
Correct |
353 ms |
8648 KB |
answer = YES |
4 |
Correct |
491 ms |
8540 KB |
answer = NO |
5 |
Execution timed out |
980 ms |
8644 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
282 ms |
8788 KB |
answer = YES |
2 |
Correct |
287 ms |
8644 KB |
answer = YES |
3 |
Correct |
353 ms |
8648 KB |
answer = YES |
4 |
Correct |
491 ms |
8540 KB |
answer = NO |
5 |
Execution timed out |
980 ms |
8644 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |