Submission #2337651
Source Code Expand
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto& (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define sar(a,n) cout<<#a<<":";rep(pachico,n)cout<<" "<<a[pachico];cout<<endl
#define svec(v) cout<<#v<<":";rep(pachico,v.size())cout<<" "<<v[pachico];cout<<endl
#define svecp(v) cout<<#v<<":";each(pachico,v)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl
#define sset(s) cout<<#s<<":";each(pachico,s)cout<<" "<<pachico;cout<<endl
#define smap(m) cout<<#m<<":";each(pachico,m)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl
using namespace std;
typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;
const int MAX_N = 100005;
template<typename T> class bellman_ford {
public:
struct edge{
int from,to;
T cost;
};
vector<int> d;
vector<edge> es;
int edge_id;
int V,E;
bellman_ford(int node_size){
edge_id = 0, V = node_size;
d.resize(node_size,numeric_limits<T>::max());
}
void add_edge(int from,int to,T cost){
es.push_back((edge){from,to,cost});
}
//sからの最短路長およびsからたどり着ける負の閉路の検出(trueなら負の閉路が存在する)
bool solve(int s){
E = (int)es.size();
int cnt = 0;
d[s] = 0;
while(cnt < V){
bool update = false;
rep(i,E){
edge e = es[i];
if(d[e.from] != numeric_limits<T>::max() && d[e.to] > d[e.from] + e.cost){
d[e.to] = d[e.from] + e.cost;
update = true;
}
}
if(!update) break;
cnt++;
}
return (cnt == V);
}
//すべての負の閉路の検出(trueなら負の閉路が存在する)
bool find_negative_loop(){
E = (int)es.size();
fill(d.begin(),d.end(),0);
int cnt = 0;
while(cnt < V){
bool update = false;
rep(i,E){
edge e = es[i];
if(d[e.to] > d[e.from] + e.cost){
d[e.to] = d[e.from] + e.cost;
update = true;
}
}
if(!update) break;
cnt++;
}
return (cnt == V);
}
//sからtへの最短路上に存在する負の閉路の検出(trueなら負の閉路が存在する)
bool find_negative_loop(int s,int t){
E = (int)es.size();
d[s] = 0;
rep(i,2*V){
rep(j,E){
edge e = es[j];
if(d[e.from] != numeric_limits<T>::max() && d[e.to] > d[e.from] + e.cost){
d[e.to] = d[e.from] + e.cost;
if(i >= V-1 && e.to == t){
return true;
}
}
}
}
return false;
}
};
int main()
{
cin.tie(0);
ios::sync_with_stdio(false);
int n,m;
cin >> n >> m;
bellman_ford<int> bf(2*n+1);
rep(i,n){
int p;
cin >> p;
bf.add_edge(2*n,i,p);
bf.add_edge(i,2*n,0);
}
rep(i,n){
int q;
cin >> q;
bf.add_edge(2*n,n+i,0);
bf.add_edge(n+i,2*n,q);
}
rep(i,m){
int x,y,a,b;
cin >> x >> y >> a >> b;
--x,--y;
bf.add_edge(n+y,x,b);
bf.add_edge(x,n+y,-a);
}
if(bf.find_negative_loop()){
cout << "no\n";
}else{
cout << "yes\n";
}
return 0;
}
Submission Info
Submission Time |
|
Task |
H - Asteroids2 |
User |
kopricky |
Language |
C++14 (GCC 5.4.1) |
Score |
0 |
Code Size |
3826 Byte |
Status |
WA |
Exec Time |
75 ms |
Memory |
4852 KB |
Judge Result
Set Name |
All |
Score / Max Score |
0 / 200 |
Status |
|
Set Name |
Test Cases |
All |
00-sample-00, 00-sample-01, 10-small_yes-00, 10-small_yes-01, 10-small_yes-02, 10-small_yes-03, 10-small_yes-04, 10-small_yes-05, 10-small_yes-06, 10-small_yes-07, 10-small_yes-08, 20-small_disturb-00, 20-small_disturb-01, 20-small_disturb-02, 20-small_disturb-03, 20-small_disturb-04, 20-small_disturb-05, 20-small_disturb-06, 20-small_disturb-07, 20-small_disturb-08, 30-large_yes-00, 30-large_yes-01, 30-large_yes-02, 30-large_yes-03, 30-large_yes-04, 40-large_disturb-00, 40-large_disturb-01, 40-large_disturb-02, 40-large_disturb-03, 40-large_disturb-04, 40-large_disturb-05, 40-large_disturb-06, 40-large_disturb-07, 40-large_disturb-08, 40-large_disturb-09, 40-large_disturb-10, 40-large_disturb-11, 40-large_disturb-12, 40-large_disturb-13, 40-large_disturb-14, 40-large_disturb-15 |
Case Name |
Status |
Exec Time |
Memory |
00-sample-00 |
AC |
1 ms |
256 KB |
00-sample-01 |
AC |
1 ms |
256 KB |
10-small_yes-00 |
AC |
1 ms |
256 KB |
10-small_yes-01 |
AC |
1 ms |
256 KB |
10-small_yes-02 |
AC |
1 ms |
256 KB |
10-small_yes-03 |
AC |
1 ms |
256 KB |
10-small_yes-04 |
AC |
1 ms |
256 KB |
10-small_yes-05 |
AC |
1 ms |
256 KB |
10-small_yes-06 |
AC |
4 ms |
828 KB |
10-small_yes-07 |
AC |
4 ms |
828 KB |
10-small_yes-08 |
AC |
4 ms |
828 KB |
20-small_disturb-00 |
AC |
1 ms |
256 KB |
20-small_disturb-01 |
AC |
1 ms |
256 KB |
20-small_disturb-02 |
AC |
1 ms |
256 KB |
20-small_disturb-03 |
AC |
1 ms |
256 KB |
20-small_disturb-04 |
AC |
1 ms |
256 KB |
20-small_disturb-05 |
AC |
1 ms |
256 KB |
20-small_disturb-06 |
WA |
9 ms |
828 KB |
20-small_disturb-07 |
WA |
9 ms |
828 KB |
20-small_disturb-08 |
WA |
9 ms |
828 KB |
30-large_yes-00 |
AC |
35 ms |
4852 KB |
30-large_yes-01 |
AC |
34 ms |
3444 KB |
30-large_yes-02 |
AC |
34 ms |
3956 KB |
30-large_yes-03 |
AC |
35 ms |
3444 KB |
30-large_yes-04 |
AC |
35 ms |
3444 KB |
40-large_disturb-00 |
WA |
72 ms |
4596 KB |
40-large_disturb-01 |
WA |
74 ms |
4084 KB |
40-large_disturb-02 |
WA |
75 ms |
4724 KB |
40-large_disturb-03 |
WA |
72 ms |
3444 KB |
40-large_disturb-04 |
WA |
71 ms |
4852 KB |
40-large_disturb-05 |
WA |
74 ms |
3444 KB |
40-large_disturb-06 |
WA |
73 ms |
4596 KB |
40-large_disturb-07 |
WA |
73 ms |
3444 KB |
40-large_disturb-08 |
WA |
73 ms |
4852 KB |
40-large_disturb-09 |
WA |
74 ms |
4596 KB |
40-large_disturb-10 |
WA |
72 ms |
4724 KB |
40-large_disturb-11 |
WA |
75 ms |
3444 KB |
40-large_disturb-12 |
WA |
69 ms |
4596 KB |
40-large_disturb-13 |
WA |
74 ms |
3444 KB |
40-large_disturb-14 |
WA |
75 ms |
3444 KB |
40-large_disturb-15 |
WA |
72 ms |
4724 KB |