submission_id
stringlengths
10
10
problem_id
stringlengths
6
6
language
stringclasses
3 values
code
stringlengths
1
522k
compiler_output
stringlengths
43
10.2k
s281689288
p03722
C++
#include <bits/stdc++.h> using namespace std; typedef long long ll; struct bellford { const ll INF=LONG_LONG_MAX; struct edge {int u, v; ll w;}; int nv, ne; vector<ll> d; vector<int> p; vector<edge> E; bellford(int nv, int ne) : nv(nv), ne(ne) { d.resize(nv, INF); p.resize(nv,-1); } void relax(int u, int v, ll w) { if(d[u]!=INF && d[v]>d[u]+w) { d[v]=d[u]+w; p[v]=u; } } bool get(int s) { d[s]=0; for(int i=0; i<nv-1; i++) for(auto &e : E) relax(e.u, e.v, e.w); vector<bool> path(nv, false); path[nv-1]=true; int v=p[nv-1]; while(v!=-1 && !path[v]) { path[v]=true; v=p[v]; } if(v!=-1 && path[v]) return false; return true; } }; int main() { int N, M; scanf("%d%d", &N, &M); bellford g(N, M); for(int i=0; i<M; i++) { int a, b; ll c; scanf("%d%d%lld", &a, &b, &c); g.E.push_back({a-1, b-1, -c}); } if(g.get(0)) printf("%lld\n", -g.d[N-1]); else printf("inf\n"); return 0;
a.cc: In function 'int main()': a.cc:65:14: error: expected '}' at end of input 65 | return 0; | ^ a.cc:51:1: note: to match this '{' 51 | { | ^
s706634791
p03722
C++
#include<bits/stdc++.h> using namespace std; using ll = long long; #define _GLIBCXX_DEBUG #define rep(i, V) for (int i = 0; i < V; i++) #define repr(i, V) for (int i = V-1; i >= 0; i--) #define repval(i, a, V) for (int i = a; i < V ; i++) #define all(x) x.begin(), x.end() #define ld long double #define eps 0.0000000001 #define mod 1000000007 #define inf 1e9 #define vec vector #define each(i, mp) for(auto& i:mp) struct Edge { int to, cost; Edge(int b, int c){ to = b; cost = c; } }; int main(){ int n, m; //points, edge cin >> n >> m; vec<vec<Edge>> graph(n); vec<int> dist(n, inf); int a, b, c; rep(i, m){ cin >> a >> b >> c; a--; b--; graph[a].push_back(Edge(b, -c)); } bool negative = false; dist[0] = 0; rep(i, n){ rep(v, n){ rep(k, (int)(graph[v].size())){ Edge e = graph[v][k]; if (dist[v]!= inf && dist[e.to] > dist[v] + e.cost){ dist[e.to] = dist[v] + e.cost; if (i == n-1 && e.first == n-1){ negative = true; } } } } } if (!negative){ cout << -dist[n-1] << endl; } else { cout << "inf" << endl; } }
a.cc: In function 'int main()': a.cc:44:39: error: 'struct Edge' has no member named 'first' 44 | if (i == n-1 && e.first == n-1){ | ^~~~~
s424421176
p03722
C++
#include<bits/stdc++.h> using namespace std; ///Welcome to Nasif's Code #define bug printf("bug\n"); #define bug2(var) cout<<#var<<" "<<var<<endl; #define co(q) cout<<q<<endl; #define all(q) (q).begin(),(q).end() typedef long long int ll; typedef unsigned long long int ull; const int MOD = (int)1e9+7; const int MAX = 1e6; #define pi acos(-1) #define inf 1000000000000000LL #define FastRead ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); vector<pair<int,int > >graph[MAX]; bool visit[MAX],visit2[MAX]; ll clr[MAX],cost[MAX]; int cycle; void c_dfs(int src) { visit[src]=1; clr[src]=1; for(int i=0; i<graph[src].size(); i++) { int child=graph[src][i].first; if(visit[child]==0) c_dfs(child); else if(clr[child]==1) { cycle=1; return; } } clr[src]=2; } void dfs(int src) { for(int i=0; i<graph[src].size(); i++) { int child=graph[src][i].first; int cur=graph[src][i].second; if(cost[src]+cur>cost[child]) { cost[child]=cost[src]+cur; dfs(child); } } } int main() { FastRead //freopen("output.txt", "w", stdout); int n,m; cin>>n>>m; for(int i=2;i<=n;i++) cost[i]=-1e18; while(m--) { int a,b,c; cin>>a>>b>>c; graph[a].push_back({b,c}); } c_dfs(1); if(cycle) cout<<"inf"<<endl; else { dfs(1); cout<<cost[n]<<endl; } return 0; }
a.cc: In function 'void c_dfs(int)': a.cc:21:5: error: reference to 'visit' is ambiguous 21 | visit[src]=1; | ^~~~~ In file included from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:80, from a.cc:1: /usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)' 1855 | visit(_Visitor&& __visitor, _Variants&&... __variants) | ^~~~~ a.cc:16:6: note: 'bool visit [1000000]' 16 | bool visit[MAX],visit2[MAX]; | ^~~~~ a.cc:26:12: error: reference to 'visit' is ambiguous 26 | if(visit[child]==0) | ^~~~~ /usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)' 1855 | visit(_Visitor&& __visitor, _Variants&&... __variants) | ^~~~~ a.cc:16:6: note: 'bool visit [1000000]' 16 | bool visit[MAX],visit2[MAX]; | ^~~~~
s338709835
p03722
C++
/** * author: FromDihPout * created: 2020-07-26 **/ #include <bits/stdc++.h> using namespace std; const long long INF = 1e18; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; vector<pair<pair<int,int>, int>> edges(m); for (int i = 0; i < m; i++) { int u, v, w; cin >> u >> v >> w; u--; v--; edges[i] = {{u, v}, w}; } vector<long long> score(n, -INF); score[0] = 0; for (int i = 0; i < n; i++) { for (auto e : edges) { int u = e.f.f, v = e.f.s, w = e.s; if (score[u] >= -INF) { score[v] = max(score[v], score[u] + w); } } } long long prev = score[n-1]; for (int i = 0; i < n; i++) { for (auto e : edges) { int u = e.f.f, v = e.f.s, w = e.s; if (score[u] >= -INF) { score[v] = max(score[v], score[u] + w); } } } if (score[n-1] > prev) { cout << "inf" << '\n'; } else { cout << prev << '\n'; } return 0; }
a.cc: In function 'int main()': a.cc:30:23: error: 'struct std::pair<std::pair<int, int>, int>' has no member named 'f' 30 | int u = e.f.f, v = e.f.s, w = e.s; | ^ a.cc:32:23: error: 'v' was not declared in this scope 32 | score[v] = max(score[v], score[u] + w); | ^ a.cc:32:53: error: 'w' was not declared in this scope 32 | score[v] = max(score[v], score[u] + w); | ^ a.cc:39:23: error: 'struct std::pair<std::pair<int, int>, int>' has no member named 'f' 39 | int u = e.f.f, v = e.f.s, w = e.s; | ^ a.cc:41:23: error: 'v' was not declared in this scope 41 | score[v] = max(score[v], score[u] + w); | ^ a.cc:41:53: error: 'w' was not declared in this scope 41 | score[v] = max(score[v], score[u] + w); | ^
s561652083
p03722
C++
#include<iostream> #include<vector> #include<algorithm> #define rep(i,n) for(int i = 0; i < (n); i++) using ll = long long; using namespace std; int main() { const ll INF = -1e15; struct edge{ ll from; ll to; ll cost; }; ll n, m; cin >> n >> m; vector<edge>edges(m); rep(i,m){ int a, b, c; cin >> a >> b >> c; a--; b--; edges[i] = {a, b, c}; } vector<ll>ans(n, INF); ans[0] = 0; rep(i,n - 1){ rep(j, m){ if(ans[edges[j].from] != INF){ ans[edges[j].to] = max(ans[edges[j].to], ans[edges[j].from] + edges[j].cost); } } } bool ok = true; rep(j,m){ ll a = ans[edges[j].to]; if(ans[edges[j].from] != INF){ ans[edges[j].to] = max(ans[edges[j].to], ans[edges[j].from] + edges[j].cost); } if(a < ans[edges[j].to]) //ok = false; } if(!ok) cout << "inf" << endl; else cout << ans[n - 1] << endl; return 0; }
a.cc: In function 'int main()': a.cc:42:5: error: expected primary-expression before '}' token 42 | } | ^
s518557356
p03722
C++
//https://atcoder.jp/contests/abc061/tasks/abc061_d #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> pint; typedef pair<ll,ll> pll; typedef pair<int,pint> ppint; typedef pair<ll,pll> ppll; typedef vector<int> vint; typedef vector<ll> vll; const double pi=3.141592653589793; const int INF10 = 1000000001; const ll INF15 = 1e15 +1; const long long INF18 = 1e18 + 1; const int mod = 1000000007; //const int mod = 998244353; const double EPS=0.00001; #define rep(i, n) for (int i = 0; i < (ll)(n); i++) #define rep1(i, n) for (int i = 1; i <= (ll)(n); i++) #define rep2(i,start,end) for(int i=(ll)start;i<=(ll)end;i++) #define vrep(i, n) for(int i=(ll)n-1;i>=0;i--) #define vrep1(i, n) for(int i=(ll)n;i>0;i--) #define all(n) n.begin(),n.end() #define pb push_back #define debug(x) cerr << #x <<": " << x << '\n' #define arep(it,a) for(auto it : a ) struct edge{ edge(int s,int e,long long c){ to=e;from=s;cost=c; } edge(int i,long long c=1){ edge(-1,i,c); } int from; int to; long cost; }; typedef vector<edge> edges; //bを何回足せばaを超えるか(O(a/b)) //a+b-1/bとすればよし //2進数表示したときの最高桁(O(log n)) int bi_max(long n){ int m = 0; for (m; (1 << m) <= n; m++); m = m - 1; return m; } //bi_eに二進数表示したやつを代入(O(log^2 n)) //bitset<N> a(n)でnの二進数表示が得られて、a[i]=0or1でi番目のfragが立ってるかわかる //x^n mod m (nが負の時は0)(O(log n)) long myPow(long x, long n, long m=mod){ if (n < 0) return 0; if (n == 0) return 1; if (n % 2 == 0) return myPow(x * x % m, n / 2, m); else return x * myPow(x, n - 1, m) % m; } // auto mod int // https://youtu.be/L8grWxBlIZ4?t=9858 // https://youtu.be/ERZuLAxZffQ?t=4807 : optimize // https://youtu.be/8uowVvQ_-Mo?t=1329 : division struct mint{ ll x; // typedef long long ll; mint(ll x = 0) : x((x % mod + mod) % mod) {} mint operator-() const { return mint(-x); } mint &operator+=(const mint a) { if ((x += a.x) >= mod) x -= mod; return *this; } mint &operator-=(const mint a) { if ((x += mod - a.x) >= mod) x -= mod; return *this; } mint &operator*=(const mint a) { (x *= a.x) %= mod; return *this; } mint operator+(const mint a) const { return mint(*this) += a; } mint operator-(const mint a) const { return mint(*this) -= a; } mint operator*(const mint a) const { return mint(*this) *= a; } mint pow(ll t) const { if (!t) return 1; mint a = pow(t >> 1); a *= a; if (t & 1) a *= *this; return a; } // for prime mod mint inv() const { return pow(mod - 2); } mint &operator/=(const mint a) { return *this *= a.inv(); } mint operator/(const mint a) const { return mint(*this) /= a; } bool operator!=(const int a) { return this->x!=a; } bool operator==(const int a) { return this->x==a; } }; istream &operator>>(istream &is, const mint &a) { return is >> a.x; } ostream &operator<<(ostream &os, const mint &a) { return os << a.x; } // combination mod prime // https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619 struct combination{ vector<mint> fact, ifact; combination(int n) : fact(n + 1), ifact(n + 1) { assert(n < mod); fact[0] = 1; for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i; ifact[n] = fact[n].inv(); for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i; } mint operator()(int n, int k) { if (k < 0 || k > n) return 0; return fact[n] * ifact[k] * ifact[n - k]; } }; template<class T> bool maxin (T &a,T b){if(a<b){a=b;return 1;}return 0;} template<class T> bool minin (T &a,T b){if(a>b){a=b;return 1;}return 0;} template<class M,class N> constexpr common_type_t<M,N> gcd(M a,N b){ a=abs(a);b=abs(b); if(a < b) return gcd(b, a); M r; while ((r=a%b)) { a = b; b = r; } return b; } template<class M,class N> constexpr common_type_t<M,N> lcm(M a,N b){ return a*b/gcd(a,b); } const int N_MAX=100005; edges v; int n,m; bool BellmanFord(edges w,int n,int start,vector<ll> &res){ res.clear(); res.resize(n,INF15); res[start]=0; bool tof; for(int i=0;i<=n+1;i++){ tof=false; arep(i,w){ if(res[i.from]!=INF15&&minin(res[i.to],res[i.from]+i.cost)){ tof=true; } } if(!tof)break; if(i==n+1)return false; } return true; } void Main(){ int x=0,y=INF10,z=1; //入力 cin>>n>>m; rep(i,m){ cin>>x>>y>>z; v.pb(edge(x-1,y-1,-z)); } //処理 vll res(n,INF15); rep(j,n-1){ arep(i,v){ if(res[i.from]!=INF15)minin(res[i.to],res[i.from]+i.cost); } } ll ans=res[n-1]; vector<bool> negative(n,false); rep(j,n){ arep(i,v){ if(res[i.from]!=INF15&&minin(res[i.to],res[i.from]+i.cost)){ negative[i.from]=true; } if(negative[i.from])negative[i.to]=true; } } //出力 negative[n-1]?cout << "inf" <<endl;cout << -res[n-1] <<endl; } int main(){ cin.tie(nullptr); cout<<fixed<<setprecision(12); Main(); }
a.cc: In function 'void Main()': a.cc:207:39: error: expected ':' before ';' token 207 | negative[n-1]?cout << "inf" <<endl;cout << -res[n-1] <<endl; | ^ | : a.cc:207:39: error: expected primary-expression before ';' token
s189759795
p03722
C++
#include <bits/stdc++.h> #define ss second #define ff first #define all(x) x.begin(), x.end() using namespace std; using ll = long long; using pii = pair<ll, ll>; const ll oo = 1e11 + 7; const int mod = 1e9 + 7, maxn = (2 * 1e3) + 10; const long double PI = acos(-1); int main (){ ios_base::sync_with_stdio(false); cin.tie(0); ll n, m; cin >> n >> m; vector<ll> a(m), b(m), c(m), dist(n, oo); bitset<maxn> neg(0); for (int i=0; i<m; i++){ cin >> a[i] >> b[i] >> c[i]; a[i]--, b[i]--; c[i]*=-1; } dist[0] = 0; for (int loop=0; loop<n-1; loop++){ if (dist[a[i]] == oo) continue; for (int i=0; i<m; i++){ if (dist[b[i]] > dist[a[i]] + c[i]){ dist[b[i]] = dist[a[i]] + c[i]; } } } ll ans = dist[n-1]; for (int loop = 0; loop < n-1; loop++){ for (int i=0; i<m; i++){ if (dist[b[i]] > dist[a[i]] + c[i]){ neg[a[i]] = 1; dist[b[i]] = dist[a[i]] + c[i]; } if (neg[a[i]]) neg[b[i]] = 1; } } if (neg[n-1]) cout << "inf" << endl; else cout << -ans << endl; return 0; }
a.cc: In function 'int main()': a.cc:33:20: error: 'i' was not declared in this scope 33 | if (dist[a[i]] == oo) continue; | ^
s445102951
p03722
C++
#include <iostream> #include <vector> #include <algorithm> #include <string> #include <cmath> #include <stack> #include <queue> #include <functional> #include <set> #include <map> #include <tuple> #include <bitset> #include <random> #define REP(i,n) for(int i=0;i<n;i++) #define INF 100000000000000000 using namespace std; using pii=pair<int,int>; vector<int> dist; vector<int> pre; vector<bool> exist_negative_cycle; void Bellman_Ford(vector<vector<pii>> adj_list,int start){ /*trueなら負の閉路が存在*/ int n=adj_list.size(); /*初期化*/ dist=vector<int>(n,INF); pre=vector<int>(n);/*最短経路におけるひとつ前の頂点*/ exist_negative_cycle=vector<bool>(n,false);/*nまでの経路に負の閉路があるかどうか*/ dist.at(start)=0; REP(i,n){ REP(u,n){ for(auto vpair : adj_list.at(u)){ int weight_u_to_v,v; tie(v,weight_u_to_v)=vpair; if(dist.at(v)>dist.at(u)+weight_u_to_v){ dist.at(v)=dist.at(u)+weight_u_to_v; pre.at(v)=u; if (i == n - 1){ exist_negative_cycle.at(v)=true; }; // n回目にも更新があるなら負の閉路が存在 } } } } } int main() { int V,E; cin>>V>>E; vector<vector<pair<int,int>>> adj_list(V); REP(i,E){ int s,t,d; cin>>s>>t>>d; s--; t--;/*添字の調整*/ adj_list.at(s).push_back(make_pair(t,-d)); } Bellman_Ford(adj_list,0); if(exist_negative_cycle.at(n-1)){ cout<<"inf"<<endl; return 0; } cout<<-dist.at(V-1)<<endl; return 0; }
a.cc: In function 'void Bellman_Ford(std::vector<std::vector<std::pair<int, int> > >, int)': a.cc:15:13: warning: overflow in conversion from 'long int' to 'std::vector<int>::value_type' {aka 'int'} changes value from '100000000000000000' to '1569325056' [-Woverflow] 15 | #define INF 100000000000000000 | ^~~~~~~~~~~~~~~~~~ a.cc:32:24: note: in expansion of macro 'INF' 32 | dist=vector<int>(n,INF); | ^~~ a.cc: In function 'int main()': a.cc:73:30: error: 'n' was not declared in this scope 73 | if(exist_negative_cycle.at(n-1)){ | ^
s996845667
p03722
C++
#include<iostream> #include<string> #include<algorithm> #include<cmath> #include<map> #include<vector> #include<math.h> #include<stdio.h> #include<stack> #include<queue> #include<tuple> #include<cassert> #include<set> #include<functional> //#include<bits/stdc++.h> using ll = long long; using ld = long double; using namespace std; const ll INF = 1000000000000000000; const ll mod = 1000000007; const ld pi = 3.141592653589793238; //printf("%.10f\n", n); ll gcd(ll a, ll b) { if (a < b)swap(a, b); if (a % b == 0)return b; return gcd(b, a % b); } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } ll modpow(ll x, ll y) { ll res = 1; while (y) { if (y % 2) { res *= x; res %= mod; } x = x * x % mod; y /= 2; } return res; } //頂点fromから頂点toへのコストcostの辺 struct edge { ll from, to, cost; }; edge es[345678]; //辺 ll d[345678]; //最短距離 //Vは頂点数、Eは辺数 //s番目の頂点から各頂点への最短距離を求める void Bellman_Ford(ll V, ll E, ll s) { for (int i = 0; i <= V; i++) d[i] = INF; d[s] = 0; while (true) { bool update = false; for (int i = 0; i < E; i++) { edge e = es[i]; if (d[e.from] != INF && d[e.to] > d[e.from] + e.cost) { d[e.to] = d[e.from] + e.cost; update = true; } } if (!update)break; } } //trueなら負の経路が存在する bool find_negative_loop(ll V, ll E) { //Vは頂点数、Eは辺数 memset(d, 0, sizeof(d)); for (int i = 0; i <= V; i++) { for (int j = 0; j < E; j++) { edge e = es[j]; if (d[e.to] > d[e.from] + e.cost) { d[e.to] = d[e.from] + e.cost; //n回目にも更新があるなら負の経路が存在 if (i == V - 1)return true; } } } return false; } ll test[12345678]; signed main() { ll n, m, a, b, c; cin >> n >> m; for (int h = 0; h < m; h++) { cin >> a >> b >> c; es[h] = { a, b, 0 - c }; } if (find_negative_loop(n, m)) { cout << "inf" << endl; return 0; } Bellman_Ford(n, m, 1); cout << 0 - d[n] << endl; return 0; }
a.cc: In function 'bool find_negative_loop(ll, ll)': a.cc:64:9: error: 'memset' was not declared in this scope 64 | memset(d, 0, sizeof(d)); | ^~~~~~ a.cc:15:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>' 14 | #include<functional> +++ |+#include <cstring> 15 | //#include<bits/stdc++.h>
s589293808
p03722
C++
#include <iostream> #include <string> #include <vector> #include <algorithm> #include <utility> #include <tuple> #include <cstdint> #include <cstdio> #include <map> #include <queue> #include <set> #include <stack> #include <deque> #include <unordered_map> #include <unordered_set> #include <bitset> #include <cctype> #include <functional> #include <ctime> #include <cmath> #include <limits> #include <numeric> #include <type_traits> #include <iomanip> #include <float.h> #include <math.h> using namespace std; using ll = long long; unsigned euclidean_gcd(unsigned a, unsigned b) { if (a < b) return euclidean_gcd(b, a); unsigned r; while ((r = a % b)) { a = b; b = r; } return b; } class UnionFind { public: vector <ll> par; vector <ll> siz; UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) { for (ll i = 0; i < sz_; ++i) par[i] = i; } void init(ll sz_) { par.resize(sz_); siz.assign(sz_, 1LL); for (ll i = 0; i < sz_; ++i) par[i] = i; } ll root(ll x) { while (par[x] != x) { x = par[x] = par[par[x]]; } return x; } bool merge(ll x, ll y) { x = root(x); y = root(y); if (x == y) return false; if (siz[x] < siz[y]) swap(x, y); siz[x] += siz[y]; par[y] = x; return true; } bool issame(ll x, ll y) { return root(x) == root(y); } ll size(ll x) { return siz[root(x)]; } }; long long modpow(long long a, long long n, long long mod) { long long res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } long long modinv(long long a, long long mod) { return modpow(a, mod - 2, mod); } int main() { ll n,m; cin >> n >> m; vector<pair<pair<ll,ll>,ll>> z(m); for (int i = 0; i < m; i++) { cin >> z[i].first.first >> z[i].first.second >> z[i].second; z[i].first.first--; z[i].first.second--; } vector<ll> point(n, -100000000000000000); point[0] = 0; for (int iii = 0; iii < n; iii++) { for (int i = 0; i < m; i++) { point[z[i].first.second] = max(point[z[i].first.second], point[z[i].first.first] + z[i].second); } } for (int iii = 0; iii < n+5; iii++) { for (int i = 0; i < m; i++) { if (point[z[i].first.second] < point[z[i].first.first] + z[i].second && z[i].first.second == n - 1)point[n - 1] = -1000000000000000000; point[z[i].first.second] = max(point[z[i].first.second], point[z[i].first.first] + z[i].second); } } if (point[n - 1] == -1000000000000000000)cout << "inf" << endl; else cout << point[n - 1] << endl;
a.cc: In function 'int main()': a.cc:115:39: error: expected '}' at end of input 115 | else cout << point[n - 1] << endl; | ^ a.cc:92:12: note: to match this '{' 92 | int main() { | ^
s996663891
p03722
C++
#include <iostream> #include <string> #include <vector> #include <algorithm> #include <utility> #include <tuple> #include <cstdint> #include <cstdio> #include <map> #include <queue> #include <set> #include <stack> #include <deque> #include <unordered_map> #include <unordered_set> #include <bitset> #include <cctype> #include <functional> #include <ctime> #include <cmath> #include <limits> #include <numeric> #include <type_traits> #include <iomanip> #include <float.h> #include <math.h> using namespace std; using ll = long long; unsigned euclidean_gcd(unsigned a, unsigned b) { if (a < b) return euclidean_gcd(b, a); unsigned r; while ((r = a % b)) { a = b; b = r; } return b; } class UnionFind { public: vector <ll> par; vector <ll> siz; UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) { for (ll i = 0; i < sz_; ++i) par[i] = i; } void init(ll sz_) { par.resize(sz_); siz.assign(sz_, 1LL); for (ll i = 0; i < sz_; ++i) par[i] = i; } ll root(ll x) { while (par[x] != x) { x = par[x] = par[par[x]]; } return x; } bool merge(ll x, ll y) { x = root(x); y = root(y); if (x == y) return false; if (siz[x] < siz[y]) swap(x, y); siz[x] += siz[y]; par[y] = x; return true; } bool issame(ll x, ll y) { return root(x) == root(y); } ll size(ll x) { return siz[root(x)]; } }; long long modpow(long long a, long long n, long long mod) { long long res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } long long modinv(long long a, long long mod) { return modpow(a, mod - 2, mod); } int main() { ll n,m; cin >> n >> m; vector<pair<pair<ll,ll>,ll>> z(m); for (int i = 0; i < m; i++) { cin >> z[i].first.first >> z[i].first.second >> z[i].second; z[i].first.first--; z[i].first.second--; } vector<ll> point(n, -100000000000000000); point[0] = 0; for (int iii = 0; iii < n; iii++) { for (int i = 0; i < m; i++) { point[z[i].first.second] = max(point[z[i].first.second], point[z[i].first.first] + z[i].second); } } for (int i = 0; i < m; i++) { if (point[z[i].first.second] < point[z[i].first.first] + z[i].second && point[z[i].first.first] + z[i].second > -10000000000000000)point[n - 1] = -1000000000000000000; } if (point[n - 1] == -1000000000000000000)cout << "inf" << endl; else cout << point[n - 1] << endl;
a.cc: In function 'int main()': a.cc:112:39: error: expected '}' at end of input 112 | else cout << point[n - 1] << endl; | ^ a.cc:92:12: note: to match this '{' 92 | int main() { | ^
s550625643
p03722
C++
#include<bits/stdc++.h> #define rep(i, n) for(int i = 0; i < n; ++i) using namespace std; template<typename T> struct WG{ using P = tuple<int, int, T>; int n; T inf = 2000000000000000000; vector<bool> negative_loop(n, false); vector<P> edges; vector<T> ans; WG(int n_){ n = n_; ans.resize(n, inf); } void add_edge(int from, int to, T cost){ P edge = make_tuple(from, to, cost); edges.push_back(edge); } void bellmanford(int start){ ans[start] = 0; for(int i = 0; i < n; ++i){ for(int j = 0; j < edges.size()*2; ++j){ int from = get<0>(edges[j]); int to = get<1>(edges[j]); T cost = get<2>(edges[j]); if(ans[from] < inf && ans[to] > ans[from] + cost){ ans[to] = ans[from] + cost; if(i > n-2) negative_loop[to] = true; } } } } }; int main(){ int n, m; cin >> n >> m; WG<long> g(n); rep(i, m){ int a, b; long c; cin >> a >> b >> c; --a; --b; g.add_edge(a, b, -1*c); } g.bellmanford(0); if(g.negative_loop[n-1]) cout << "inf\n"; else cout << g.ans[n-1] * -1<< "\n"; return 0; }
a.cc:8:30: error: 'n' is not a type 8 | vector<bool> negative_loop(n, false); | ^ a.cc:8:33: error: expected identifier before 'false' 8 | vector<bool> negative_loop(n, false); | ^~~~~ a.cc:8:33: error: expected ',' or '...' before 'false' a.cc: In function 'int main()': a.cc:43:21: error: invalid types '<unresolved overloaded function type>[int]' for array subscript 43 | if(g.negative_loop[n-1]) cout << "inf\n"; | ^ a.cc: In instantiation of 'void WG<T>::bellmanford(int) [with T = long int]': a.cc:42:16: required from here 42 | g.bellmanford(0); | ~~~~~~~~~~~~~^~~ a.cc:28:23: error: invalid use of member function 'std::vector<bool> WG<T>::negative_loop(int, int) [with T = long int]' (did you forget the '()' ?) 28 | if(i > n-2) negative_loop[to] = true; | ^~~~~~~~~~~~~
s926577057
p03722
C++
#include <bits/stdc++.h> using namespace std; long long INF = 1000000000000000; int main(){ int N, M; cin >> N >> M; vector<vector<pair<int, int>>> E(N); for (int i = 0; i < M; i++){ int a, b, c; cin >> a >> b >> c; a--; b--; E[a].push_back(make_pair(c, b)); } vector<vector<long long>> dp(N + 1, vector<long long>(N, -INF)); dp[0][0] = 0; for (int i = 0; i < N; i++){ for (int j = 0; j < N; j++){ dp[i + 1][j] = dp[i][j]; } for (int j = 0; j < N; j++){ if (dp[i][j] != -INF){ for (auto P : E[j]){ dp[i + 1][P.second] = max(dp[i + 1][P.second], dp[i][j] + P.first); } } } } if (dp[N - 1][N - 1] != dp[N - 1]){ cout << "inf" << endl; } else { cout << dp[N - 1][N - 1] << endl; } }
a.cc: In function 'int main()': a.cc:29:24: error: no match for 'operator!=' (operand types are '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} and '__gnu_cxx::__alloc_traits<std::allocator<std::vector<long long int> >, std::vector<long long int> >::value_type' {aka 'std::vector<long long int>'}) 29 | if (dp[N - 1][N - 1] != dp[N - 1]){ In file included from /usr/include/c++/14/regex:68, from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:181, from a.cc:1: /usr/include/c++/14/bits/regex.h:1132:5: note: candidate: 'template<class _BiIter> bool std::__cxx11::operator!=(const sub_match<_BiIter>&, const sub_match<_BiIter>&)' 1132 | operator!=(const sub_match<_BiIter>& __lhs, const sub_match<_BiIter>& __rhs) | ^~~~~~~~ /usr/include/c++/14/bits/regex.h:1132:5: note: template argument deduction/substitution failed: a.cc:29:35: note: mismatched types 'const std::__cxx11::sub_match<_BiIter>' and '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} 29 | if (dp[N - 1][N - 1] != dp[N - 1]){ | ^ /usr/include/c++/14/bits/regex.h:1212:5: note: candidate: 'template<class _Bi_iter, class _Ch_traits, class _Ch_alloc> bool std::__cxx11::operator!=(__sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>&, const sub_match<_BiIter>&)' 1212 | operator!=(const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __lhs, | ^~~~~~~~ /usr/include/c++/14/bits/regex.h:1212:5: note: template argument deduction/substitution failed: a.cc:29:35: note: mismatched types 'std::__cxx11::__sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>' and '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} 29 | if (dp[N - 1][N - 1] != dp[N - 1]){ | ^ /usr/include/c++/14/bits/regex.h:1305:5: note: candidate: 'template<class _Bi_iter, class _Ch_traits, class _Ch_alloc> bool std::__cxx11::operator!=(const sub_match<_BiIter>&, __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>&)' 1305 | operator!=(const sub_match<_Bi_iter>& __lhs, | ^~~~~~~~ /usr/include/c++/14/bits/regex.h:1305:5: note: template argument deduction/substitution failed: a.cc:29:35: note: mismatched types 'const std::__cxx11::sub_match<_BiIter>' and '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} 29 | if (dp[N - 1][N - 1] != dp[N - 1]){ | ^ /usr/include/c++/14/bits/regex.h:1379:5: note: candidate: 'template<class _Bi_iter> bool std::__cxx11::operator!=(const typename std::iterator_traits<_Iter>::value_type*, const sub_match<_BiIter>&)' 1379 | operator!=(typename iterator_traits<_Bi_iter>::value_type const* __lhs, | ^~~~~~~~ /usr/include/c++/14/bits/regex.h:1379:5: note: template argument deduction/substitution failed: a.cc:29:35: note: '__gnu_cxx::__alloc_traits<std::allocator<std::vector<long long int> >, std::vector<long long int> >::value_type' {aka 'std::vector<long long int>'} is not derived from 'const std::__cxx11::sub_match<_BiIter>' 29 | if (dp[N - 1][N - 1] != dp[N - 1]){ | ^ /usr/include/c++/14/bits/regex.h:1473:5: note: candidate: 'template<class _Bi_iter> bool std::__cxx11::operator!=(const sub_match<_BiIter>&, const typename std::iterator_traits<_Iter>::value_type*)' 1473 | operator!=(const sub_match<_Bi_iter>& __lhs, | ^~~~~~~~ /usr/include/c++/14/bits/regex.h:1473:5: note: template argument deduction/substitution failed: a.cc:29:35: note: mismatched types 'const std::__cxx11::sub_match<_BiIter>' and '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} 29 | if (dp[N - 1][N - 1] != dp[N - 1]){ | ^ /usr/include/c++/14/bits/regex.h:1547:5: note: candidate: 'template<class _Bi_iter> bool std::__cxx11::operator!=(const typename std::iterator_traits<_Iter>::value_type&, const sub_match<_BiIter>&)' 1547 | operator!=(typename iterator_traits<_Bi_iter>::value_type const& __lhs, | ^~~~~~~~ /usr/include/c++/14/bits/regex.h:1547:5: note: template argument deduction/substitution failed: a.cc:29:35: note: '__gnu_cxx::__alloc_traits<std::allocator<std::vector<long long int> >, std::vector<long long int> >::value_type' {aka 'std::vector<long long int>'} is not derived from 'const std::__cxx11::sub_match<_BiIter>' 29 | if (dp[N - 1][N - 1] != dp[N - 1]){ | ^ /usr/include/c++/14/bits/regex.h:1647:5: note: candidate: 'template<class _Bi_iter> bool std::__cxx11::operator!=(const sub_match<_BiIter>&, const typename std::iterator_traits<_Iter>::value_type&)' 1647 | operator!=(const sub_match<_Bi_iter>& __lhs, | ^~~~~~~~ /usr/include/c++/14/bits/regex.h:1647:5: note: template argument deduction/substitution failed: a.cc:29:35: note: mismatched types 'const std::__cxx11::sub_match<_BiIter>' and '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} 29 | if (dp[N - 1][N - 1] != dp[N - 1]){ | ^ /usr/include/c++/14/bits/regex.h:2213:5: note: candidate: 'template<class _Bi_iter, class _Alloc> bool std::__cxx11::operator!=(const match_results<_BiIter, _Alloc>&, const match_results<_BiIter, _Alloc>&)' 2213 | operator!=(const match_results<_Bi_iter, _Alloc>& __m1, | ^~~~~~~~ /usr/include/c++/14/bits/regex.h:2213:5: note: template argument deduction/substitution failed: a.cc:29:35: note: mismatched types 'const std::__cxx11::match_results<_BiIter, _Alloc>' and '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} 29 | if (dp[N - 1][N - 1] != dp[N - 1]){ | ^ In file included from /usr/include/c++/14/bits/stl_algobase.h:64, from /usr/include/c++/14/algorithm:60, from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51: /usr/include/c++/14/bits/stl_pair.h:1052:5: note: candidate: 'template<class _T1, class _T2> constexpr bool std::operator!=(const pair<_T1, _T2>&, const pair<_T1, _T2>&)' 1052 | operator!=(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y) | ^~~~~~~~ /usr/include/c++/14/bits/stl_pair.h:1052:5: note: template argument deduction/substitution failed: a.cc:29:35: note: mismatched types 'const std::pair<_T1, _T2>' and '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} 29 | if (dp[N - 1][N - 1] != dp[N - 1]){ | ^ In file included from /usr/include/c++/14/bits/stl_algobase.h:67: /usr/include/c++/14/bits/stl_iterator.h:455:5: note: candidate: 'template<class _Iterator> constexpr bool std::operator!=(const reverse_iterator<_Iterator>&, const reverse_iterator<_Iterator>&)' 455 | operator!=(const reverse_iterator<_Iterator>& __x, | ^~~~~~~~ /usr/include/c++/14/bits/stl_iterator.h:455:5: note: template argument deduction/substitution failed: a.cc:29:35: note: mismatched types 'const std::reverse_iterator<_Iterator>' and '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} 29 | if (dp[N - 1][N - 1] != dp[N - 1]){ | ^ /usr/include/c++/14/bits/stl_iterator.h:500:5: note: candidate: 'template<class _IteratorL, class _IteratorR> constexpr bool std::operator!=(const reverse_iterator<_Iterator>&, const reverse_iterator<_IteratorR>&)' 500 | operator!=(const reverse_iterator<_IteratorL>& __x, | ^~~~~~~~ /usr/include/c++/14/bits/stl_iterator.h:500:5: note: template argument deduction/substitution failed: a.cc:29:35: note: mismatched types 'const std::reverse_iterator<_Iterator>' and '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} 29 | if (dp[N - 1][N - 1] != dp[N - 1]){ | ^ /usr/include/c++/14/bits/stl_iterator.h:1686:5: note: candidate: 'template<class _IteratorL, class _IteratorR> constexpr bool std::operator!=(const move_iterator<_IteratorL>&, const move_iterator<_IteratorR>&)' 1686 | operator!=(const move_iterator<_IteratorL>& __x, | ^~~~~~~~ /usr/include/c++/14/bits/stl_iterator.h:1686:5: note: template argument deduction/substitution failed: a.cc:29:35: note: mismatched types 'const std::move_iterator<_IteratorL>' and '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} 29 | if (dp[N - 1][N - 1] != dp[N - 1]){ | ^ /usr/include/c++/14/bits/stl_iterator.h:1753:5: note: candidate: 'template<class _Iterator> constexpr bool std::operator!=(const move_iterator<_IteratorL>&, const move_iterator<_IteratorL>&)' 1753 | operator!=(const move_iterator<_Iterator>& __x, | ^~~~~~~~ /usr/include/c++/14/bits/stl_iterator.h:1753:5: note: template argument deduction/substitution failed: a.cc:29:35: note: mismatched types 'const std::move_iterator<_IteratorL>' and '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} 29 | if (dp[N - 1][N - 1] != dp[N - 1]){ | ^ In file included from /usr/include/c++/14/bits/char_traits.h:42, from /usr/include/c++/14/string:42, from /usr/include/c++/14/bitset:52, from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52: /usr/include/c++/14/bits/postypes.h:197:5: note: candidate: 'template<class _StateT> bool std::operator!=(const fpos<_StateT>&, const fpos<_StateT>&)' 197 | operator!=(const fpos<_StateT>& __lhs, const fpos<_StateT>& __rhs) | ^~~~~~~~ /usr/include/c++/14/bits/postypes.h:197:5: note: template argument
s068896693
p03722
Java
import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.Arrays; import java.util.Comparator; import java.util.LinkedList; import java.util.List; import java.util.NoSuchElementException; import java.util.PriorityQueue; import java.util.ArrayDeque; import java.util.Queue; class Edge{ int to; long cost; Edge(int to,long cost){ this.to = to; this.cost = cost; } } class deg{ boolean from; boolean to; deg(boolean from,boolean to){ this.from = from; this.to = to; } } public class Main { public static void main(String[] args) { FastScanner fs = new FastScanner(); int n = fs.nextInt(); int m = fs.nextInt(); List<LinkedList<Edge>> graph = new ArrayList<>(); boolean[] visited = new boolean[n]; Arrays.fill(V,0); Arrays.fill(visited,true); List<LinkedList<deg>> D = new ArrayList<>(); for(int i=0;i<n;i++){ graph.add(new LinkedList<>()); D.add(new LinkedList<>()); D.get(i).add(new deg(false,false)); } int from,to,cost; for(int i=0;i<m;i++){ from = fs.nextInt()-1; to = fs.nextInt()-1; cost = fs.nextInt(); deg[from]++; deg[to]++; graph.get(from).add(new Edge(to,cost)); } long inf = 100000000000000L; long[] dist = new long[n]; Arrays.fill(dist,-inf); Queue<Integer> queue = new ArrayDeque<>(); queue.add(0); dist[0] = 0; while(!queue.isEmpty()){ int x = queue.poll(); D.get(x).from = true; for(Edge e : graph.get(x)){ D.get(e.to).to = true; if(visited[e.to]){ visited[e.to] = false; queue.add(e.to); } if(D.get(e.to).from){ System.out.println("inf"); System.exit(0); } dist[e.to] = Math.max(e.cost+dist[x],dist[e.to]); } } System.out.println(dist[n-1]); } } class FastScanner { private final InputStream in = System.in; private final byte[] buffer = new byte[1024]; private int ptr = 0; private int buflen = 0; private boolean hasNextByte(){ if(ptr < buflen){ return true; }else{ ptr = 0; try{ buflen = in.read(buffer); }catch(IOException e){ e.printStackTrace(); } if(buflen <=0){ return false; } } return true; } private int readByte(){ if(hasNextByte())return buffer[ptr++]; else return -1; } private static boolean isPrintableChar(int c){ return 33<=c && c<=126; } public boolean hasNext(){ while(hasNextByte() && !isPrintableChar(buffer[ptr]))ptr++; return hasNextByte(); } public String next(){ if(!hasNext()) throw new NoSuchElementException(); StringBuilder sb = new StringBuilder(); int b = readByte(); while(isPrintableChar(b)){ sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } public long nextLong(){ if(!hasNext()) throw new NoSuchElementException(); long n = 0; boolean minus = false; int b = readByte(); if(b == '-'){ minus = true; b = readByte(); } if(b < '0' || '9' < b){ throw new NumberFormatException(); } while(true){ if('0' <= b && b<='9'){ n*=10; n+=b-'0'; }else if(b==-1 || !isPrintableChar(b)){ return minus ? -n : n; }else{ throw new NumberFormatException(); } b = readByte(); } } public int nextInt(){ long nl = nextLong(); if(nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)throw new NumberFormatException(); return (int) nl; } public double nextDoutble(){return Double.parseDouble(next());} }
Main.java:35: error: cannot find symbol Arrays.fill(V,0); ^ symbol: variable V location: class Main Main.java:48: error: cannot find symbol deg[from]++; ^ symbol: variable deg location: class Main Main.java:49: error: cannot find symbol deg[to]++; ^ symbol: variable deg location: class Main Main.java:60: error: cannot find symbol D.get(x).from = true; ^ symbol: variable from location: class LinkedList<deg> Main.java:62: error: cannot find symbol D.get(e.to).to = true; ^ symbol: variable to location: class LinkedList<deg> Main.java:67: error: cannot find symbol if(D.get(e.to).from){ ^ symbol: variable from location: class LinkedList<deg> 6 errors
s548602908
p03722
C++
#include <bits/stdc++.h> using namespace std; typedef long long int ll; ll MOD = 1000000007; ll INFL = 1ll << 60; ll INF = 1 << 28; // =================グラフテンプレート================== // costの部分の型は指定できます template <typename T> struct edge { int from, to; T cost; edge(int to, T cost) : from(-1), to(to), cost(cost) {} edge(int from, int to, T cost) : from(from), to(to), cost(cost) {} // 行き先を代入できる edge &operator=(const int &x) { to = x; return *this; } // intにキャスト(?)するとかなんとか operator int() const { return to; } }; template <typename T> using Edges = vector<edge<T>>; template <typename T> using WeightedGraph = vector<Edges<T>>; template <typename T> using Matrix = vector<vector<T>>; using UnWeightedGraph = vector<vector<int>>; // =============ベルマン・フォード法============= // 負の閉路を検出できます(空のvectorを返します) // bellman<距離の型>(重み付き辺の集合,頂点数,始点) template <typename T> vector<T> bellman_ford(Edges<T> &edges, int V, int s) { const auto INF = numeric_limits<T>::max(); vector<T> dist(V, INF); dist[s] = 0; for (int i = 0; i < V - 1; i++) { for (auto &e : edges) { if (dist[e.from] != INF) // 遷移できるなら dist[e.to] = min(dist[e.to], dist[e.from] + e.cost); } } for (auto &e : edges) { // 離島、負の閉路について if (dist[e.from] == INF) continue; if (dist[e.from] + e.cost < dist[e.to]) return vector<T>(); } return dist; } // ==================================================================== int main() { int n, m; cin >> n >> m; Edges<ll> edges; for (int i = 0; i < m; i++) { int s, t; ll c; cin >> s >> t >> c; s--;t--; edges.push_back(edge<ll>{s, t, -c}); } vector<ll> ans = bellman_ford(edges, n, 0); if (ans.size()) cout<<-ans[N-1]<<endl; else cout << "inf" << endl; }
a.cc: In function 'int main()': a.cc:82:16: error: 'N' was not declared in this scope 82 | cout<<-ans[N-1]<<endl; | ^
s077877291
p03722
C++
// =================グラフテンプレート================== // costの部分の型は指定できます template <typename T> struct edge { int from, to; T cost; edge(int to, T cost) : from(-1), to(to), cost(cost) {} edge(int from, int to, T cost) : from(from), to(to), cost(cost) {} // 行き先を代入できる edge &operator=(const int &x) { to = x; return *this; } // intにキャスト(?)するとかなんとか operator int() const { return to; } }; template <typename T> using Edges = vector<edge<T>>; template <typename T> using WeightedGraph = vector<Edges<T>>; template <typename T> using Matrix = vector<vector<T>>; using UnWeightedGraph = vector<vector<int>>; // =============ベルマン・フォード法============= // 負の閉路を検出できます(空のvectorを返します) // bellman<距離の型>(重み付き辺の集合,頂点数,始点) template <typename T> vector<T> bellman_ford(Edges<T> &edges, int V, int s) { const auto INF = numeric_limits<T>::max(); vector<T> dist(V, INF); dist[s] = 0; for (int i = 0; i < V - 1; i++) { for (auto &e : edges) { if (dist[e.from] != INF) // 遷移できるなら dist[e.to] = min(dist[e.to], dist[e.from] + e.cost); } } for (auto &e : edges) { // 離島、負の閉路について if (dist[e.from] == INF) continue; if (dist[e.from] + e.cost < dist[e.to]) return vector<T>(); } return dist; } // ==================================================================== int main() { int n, m; cin >> n >> m; Edges<ll> edges; for (int i = 0; i < m; i++) { int s, t; ll c; cin >> s >> t >> c; s--;t--; edges.push_back(edge<ll>{s, t, -c}); } vector<ll> ans = bellman_ford(edges, n, 0); if (ans.size()) cout<<-ans[N-1]<<endl; else cout << "inf" << endl; }
a.cc:23:15: error: 'vector' does not name a type 23 | using Edges = vector<edge<T>>; | ^~~~~~ a.cc:26:23: error: 'vector' does not name a type 26 | using WeightedGraph = vector<Edges<T>>; | ^~~~~~ a.cc:29:16: error: 'vector' does not name a type 29 | using Matrix = vector<vector<T>>; | ^~~~~~ a.cc:31:25: error: 'vector' does not name a type 31 | using UnWeightedGraph = vector<vector<int>>; | ^~~~~~ a.cc:38:1: error: 'vector' does not name a type 38 | vector<T> bellman_ford(Edges<T> &edges, int V, int s) { | ^~~~~~ a.cc: In function 'int main()': a.cc:60:3: error: 'cin' was not declared in this scope 60 | cin >> n >> m; | ^~~ a.cc:62:3: error: 'Edges' was not declared in this scope 62 | Edges<ll> edges; | ^~~~~ a.cc:62:9: error: 'll' was not declared in this scope 62 | Edges<ll> edges; | ^~ a.cc:62:13: error: 'edges' was not declared in this scope; did you mean 'edge'? 62 | Edges<ll> edges; | ^~~~~ | edge a.cc:65:7: error: expected ';' before 'c' 65 | ll c; | ^~ | ; a.cc:66:22: error: 'c' was not declared in this scope 66 | cin >> s >> t >> c; | ^ a.cc:71:3: error: 'vector' was not declared in this scope 71 | vector<ll> ans = bellman_ford(edges, n, 0); | ^~~~~~ a.cc:71:14: error: 'ans' was not declared in this scope 71 | vector<ll> ans = bellman_ford(edges, n, 0); | ^~~ a.cc:71:20: error: 'bellman_ford' was not declared in this scope 71 | vector<ll> ans = bellman_ford(edges, n, 0); | ^~~~~~~~~~~~ a.cc:74:5: error: 'cout' was not declared in this scope 74 | cout<<-ans[N-1]<<endl; | ^~~~ a.cc:74:16: error: 'N' was not declared in this scope 74 | cout<<-ans[N-1]<<endl; | ^ a.cc:74:22: error: 'endl' was not declared in this scope 74 | cout<<-ans[N-1]<<endl; | ^~~~ a.cc:76:5: error: 'cout' was not declared in this scope 76 | cout << "inf" << endl; | ^~~~ a.cc:76:22: error: 'endl' was not declared in this scope 76 | cout << "inf" << endl; | ^~~~
s907332121
p03722
C++
// =================グラフテンプレート================== // costの部分の型は指定できます template <typename T> struct edge { int from, to; T cost; edge(int to, T cost) : from(-1), to(to), cost(cost) {} edge(int from, int to, T cost) : from(from), to(to), cost(cost) {} // 行き先を代入できる edge &operator=(const int &x) { to = x; return *this; } // intにキャスト(?)するとかなんとか operator int() const { return to; } }; template <typename T> using Edges = vector<edge<T>>; template <typename T> using WeightedGraph = vector<Edges<T>>; template <typename T> using Matrix = vector<vector<T>>; using UnWeightedGraph = vector<vector<int>>; // =============ベルマン・フォード法============= // 負の閉路を検出できます(空のvectorを返します) // bellman<距離の型>(重み付き辺の集合,頂点数,始点) template <typename T> vector<T> bellman_ford(Edges<T> &edges, int V, int s) { const auto INF = numeric_limits<T>::max(); vector<T> dist(V, INF); dist[s] = 0; for (int i = 0; i < V - 1; i++) { for (auto &e : edges) { if (dist[e.from] != INF) // 遷移できるなら dist[e.to] = min(dist[e.to], dist[e.from] + e.cost); } } for (auto &e : edges) { // 離島、負の閉路について if (dist[e.from] == INF) continue; if (dist[e.from] + e.cost < dist[e.to]) return vector<T>(); } return dist; } // ==================================================================== int main() { int n, m, r; cin >> n >> m; r=0; Edges<ll> edges; for (int i = 0; i < m; i++) { int s, t; ll c; cin >> s >> t >> c; s--;t--; edges.push_back(edge<ll>{s, t, -c}); } vector<ll> ans = bellman_ford(edges, n, r); if (ans.size()) cout<<-ans[ans.size()-1]<<endl; else cout << "inf" << endl; }
a.cc:23:15: error: 'vector' does not name a type 23 | using Edges = vector<edge<T>>; | ^~~~~~ a.cc:26:23: error: 'vector' does not name a type 26 | using WeightedGraph = vector<Edges<T>>; | ^~~~~~ a.cc:29:16: error: 'vector' does not name a type 29 | using Matrix = vector<vector<T>>; | ^~~~~~ a.cc:31:25: error: 'vector' does not name a type 31 | using UnWeightedGraph = vector<vector<int>>; | ^~~~~~ a.cc:38:1: error: 'vector' does not name a type 38 | vector<T> bellman_ford(Edges<T> &edges, int V, int s) { | ^~~~~~ a.cc: In function 'int main()': a.cc:60:3: error: 'cin' was not declared in this scope 60 | cin >> n >> m; | ^~~ a.cc:62:3: error: 'Edges' was not declared in this scope 62 | Edges<ll> edges; | ^~~~~ a.cc:62:9: error: 'll' was not declared in this scope 62 | Edges<ll> edges; | ^~ a.cc:62:13: error: 'edges' was not declared in this scope; did you mean 'edge'? 62 | Edges<ll> edges; | ^~~~~ | edge a.cc:65:7: error: expected ';' before 'c' 65 | ll c; | ^~ | ; a.cc:66:22: error: 'c' was not declared in this scope 66 | cin >> s >> t >> c; | ^ a.cc:71:3: error: 'vector' was not declared in this scope 71 | vector<ll> ans = bellman_ford(edges, n, r); | ^~~~~~ a.cc:71:14: error: 'ans' was not declared in this scope 71 | vector<ll> ans = bellman_ford(edges, n, r); | ^~~ a.cc:71:20: error: 'bellman_ford' was not declared in this scope 71 | vector<ll> ans = bellman_ford(edges, n, r); | ^~~~~~~~~~~~ a.cc:74:5: error: 'cout' was not declared in this scope 74 | cout<<-ans[ans.size()-1]<<endl; | ^~~~ a.cc:74:31: error: 'endl' was not declared in this scope 74 | cout<<-ans[ans.size()-1]<<endl; | ^~~~ a.cc:76:5: error: 'cout' was not declared in this scope 76 | cout << "inf" << endl; | ^~~~ a.cc:76:22: error: 'endl' was not declared in this scope 76 | cout << "inf" << endl; | ^~~~
s685925690
p03722
C++
#include <bits/stdc++.h> #define REP(i, n) for(int i = 0; (i) < (n); (i)++) using namespace std; long modpow(long a, long n, long mod) { long res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } // a^{-1} mod を計算する long modinv(long a, long mod) { return modpow(a, mod - 2, mod); } struct compare1 { bool operator()(const pair<long, long>& value, const long& key) { return (value.first < key); } bool operator()(const long& key, const pair<long, long>& value) { return (key < value.first); } }; struct RMQ { vector<int> a; int inf = 2000000000; // 2*10^9 int n = 1; RMQ(int n_ = 1){ init(n_); } void init(int n_ = 1){ while(n < n_) n *= 2; a.resize(2*n-1); REP(i, 2*n-1) a[i] = inf; } //k番目の値(0-indexed)をbに変更 void update(int k, int b){ k += n-1; a[k] = b; while(k > 0){ k = (k-1)/2; a[k] = min(a[2*k+1], a[2*k+2]); } } //[c,b)の最小値を返す際に呼ぶ関数 int query_first(int c, int b){ return query(c, b, 0, 0, n); } //k : 節点番号, l, rはその接点が[l, r)に対応することを示す int query(int c, int b, int k, int l, int r){ if(r <= c || b <= l) return inf; if(c <= l && r <= b) return a[k]; else{ int vl = query(c, b, k*2+1, l, (l+r)/2); int vr = query(c, b, k*2+2, (l+r)/2, r); return min(vl, vr); } } }; struct UnionFind { vector<int> par; vector<int> rank; UnionFind(int n = 1){ init(n); } void init(int n = 1){ par.resize(n); rank.resize(n); REP(i, n) par[i] = i, rank[i] = 0; } int root(int x){ if(par[x] == x) return x; else return par[x] = root(par[x]); } bool issame(int x, int y){ return root(x) == root(y); } bool merge(int x, int y){ x = root(x); y = root(y); if(x == y) return false; if(rank[x] < rank[y]) swap(x, y); if(rank[x] == rank[y]) rank[x]++; par[y] = x; return true; } }; template<class Abel> struct weightedUnionFind{ vector<int> par; vector<int> rank; vector<Abel> diff_weight; weightedUnionFind(int n = 1, Abel SUM_UNITY = 0){ init(n, SUM_UNITY); } void init(int n = 1, Abel SUM_UNITY = 0){ par.resize(n); rank.resize(n); diff_weight.resize(n); REP(i, n) par[i] = i, rank[i] = 0, diff_weight[i] = SUM_UNITY; } int root(int x){ if(par[x] == x) return x; else{ int r = root(par[x]); diff_weight[x] += diff_weight[par[x]]; return par[x] = r; } } Abel weight(int x){ root(x); return diff_weight[x]; } bool issame(int x, int y){ return root(x) == root(y); } bool merge(int x, int y, Abel w){ w += weight(x); w -= weight(y); x = root(x); y = root(y); if(x == y) return false; if(rank[x] < rank[y]) swap(x, y), w = -w; if(rank[x] == rank[y]) rank[x]++; par[y] = x; diff_weight[y] = w; return true; } Abel diff(int x, int y){ return weight(y) - weight(x); } }; using Graph = vector<vector<int>>; using P = pair<int, int>; /* void dijkstra(int s, int V, Graph &G, long* d){ priority_queue<P, vector<P>, greater<P>> pque; fill(d, d + V, INF); d[s] = 0; pque.push(P(0, s)); while(!pque.empty()){ P p = pque.top(); pque.pop(); int now = p.second; if(d[now] < p.first) continue; REP(i, G[now].size()){ Edge e = G[now][i]; if(d[e.to] > d[now] + e.weight){ d[e.to] = d[now] + e.weight; pque.push(P(d[e.to], e.to)); } } } } */ int GCD(int a, int b){ if(b == 0) return a; if(a < b) return GCD(b, a); else return GCD(b, a%b); } struct BIT{ vector<long> dat; int n = 1; BIT(int nn = 1){ init(nn); } void init(int nn = 1){ while(n < nn) n *= 2; dat.resize(n+1); REP(i, n+1) dat[i] = 0l; } //1-indexed!!!! //index iにx加える void add(int i, long x){ while(i <= n){ dat[i] += x; i += (i&(-i)); } } //1-indexed!!!!! //index 1-iまでの和を求める long get_sum(int i){ long ans = 0l; while(i > 0){ ans += dat[i]; i -= (i & (-i)); } return ans; } }; //{0, 1, 2, ..., n-1}までの中からk個の要素を持つ部分集合についての処理を行う int next_combination(int sub){ int x = sub & -sub, y = sub + x; return (((sub & ~y) / x) >> 1) | y; } //main関数内で //bit = (1<<k)-1; //for(; bit < (1<<n); bit = next_combination(bit)) // REP(i, n) if(bit & (1<<i)) でbitの中で選ばれている要素iを全部取得できる //bitset<8>(bit)でbitを8桁の2進数で表示できる //BellmanFord struct Edge{ int from, to; long cost; Edge(int f, int t, long c){ from = f; to = t; cost = c; } }; struct BellmanFord{ vector<Edge> es; vector<long> d; int E, V; // E 辺 V 頂点 long inf = 1000000000000000000; BellmanFord(int ee=1, int vv=1){ E = ee; V = vv; d.resize(vv); } void update(int from, int to, long cost){ es.push_back(Edge(from, to, cost)); } void shortest_path(int start){ REP(i, V) d[i] = inf; d[start] = 0l; while(true){ bool upd = false; REP(i, E){ Edge e = es[i]; if(d[e.from] != inf && d[e.to] > d[e.from] + e.cost){ d[e.to] = d[e.from] + e.cost; upd = true; } } if(!upd) break; } cout << -d[N-1] << endl; } //true : there is a negative loop. //false : there is NOT a negative loop. bool find_negative_loop(){ REP(i, V) d[i] = 0l; REP(i, V){ REP(j, E){ Edge e = es[j]; if(d[e.to] > d[e.from] + e.cost){ d[e.to] = d[e.from] + e.cost; if(i==V-1) return true; } } } return false; } //true : there is a negative loop including start. //false : there is NOT a negative loop including start. bool find_negative_loop_from_start(int start){ REP(i, V) d[i] = inf; d[start] = 0l; int itr = 0; while(true){ bool upd = false; REP(i, E){ Edge e = es[i]; if(d[e.from] != inf && d[e.to] > d[e.from] + e.cost){ d[e.to] = d[e.from] + e.cost; upd = true; } } if(!upd) break; itr++; if(itr == V) break; } if(itr == V) return true; else return false; } }; int main() { int N, M; cin >> N >> M; BellmanFord bf(M, N); REP(i, M){ int a, b; cin >> a >> b; long c; cin >> c; bf.update(a-1, b-1, -c); } if(bf.find_negative_loop_from_start(0)) cout << "inf" << endl; else bf.shortest_path(0); return 0; }
a.cc: In member function 'void BellmanFord::shortest_path(int)': a.cc:269:20: error: 'N' was not declared in this scope 269 | cout << -d[N-1] << endl; | ^
s181888799
p03722
C++
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i,n) for (ll i = 0; i < (n); i++) typedef pair<int, int> P; ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;} ll lcm(ll a, ll b) { return a/gcd(a,b)*b;} const ll INF = -1e10+7; struct edge{ int from; int to; int c; }; bool bellman_ford(const ll &s,const ll &V,const ll &E,const vector<edge> &ed, vector<ll> &d){ // s=スタート, Vが頂点数,Eが辺の数, ed=どのようなパスを持つか, //d=答えを保持するvector.今は1つの経路が欲しいので参照して書き換えているが全ての経路について必要になった場合にはdをreturnするように改造する // 初期化 for(ll i = 0; i < V+1; i++){ d[i] = INF; } d[s] = 0; while(true){ //updateが更新されなくなるまでこの操作を繰り返す bool update = false; for(ll i = 0; i < E; i ++){ edge e = ed[i]; if(d[e.from]!=INF && d[e.to]<d[e.from]+ e.c){ // 更新条件を変更 if(d[e.to]!=INF){ // loopの検出 return true; } d[e.to] = d[e.from]+ e.c; update = true; } } if(!update){ break; } } return false; } int main(){ ll V,E; cin >> V >> E; vector<edge> ed(E); rep(i,E){ cin >> ed[i].from >> ed[i].to >> ed[i].c; } vector<ll> d(V+5); // スタートの頂点番号を0ではなく1としたいので余分に作ってd[0]は使わない bool loop = bellman_ford(1, V, E, ed, d); if(loop){ cout << "inf" << endl; }else{ cout << d[V] << endl; } _ return 0; }
a.cc: In function 'int main()': a.cc:65:1: error: '_' was not declared in this scope 65 | _ | ^
s301287243
p03722
C++
#include<bits/stdc++.h> #define rep(i, n) for(int i = 0; i < (int)(n); i++) #define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++) #define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--) using namespace std; using ll = long long; using vl = vector<ll>; using vc = vector<char>; using vvl = vector<vl>; using vvc = vector<vc>; using pll = pair<ll, ll>; using vpll = vector<pll>; ll INF = (ll)pow(10, 16); int main(){ ll N, M; cin >> N >> M; vvl abc(M, vl(3)); rep(i, M){ cin >> abc[i][0] >> abc[i][1] >> abc[i][2]; abc[i][2] = -abc[i][2]; } vl dist(N + 1, INF); dist[0] = dist[1] = 0; bool neg(N + 1, false); rep(i, N - 1){ rep(j, M){ if(dist[abc[j][0]] == INF) continue; if(dist[abc[j][1]] > dist[abc[j][0]] + abc[j][2]){ dist[abc[j][1]] = dist[abc[j][0]] + abc[j][2]; } } } ll ans = -dist[N]; vector<bool> neg(N + 1, false); rep(i, N){ rep(j, M){ if(dist[abc[j][0]] == INF) continue; if(dist[abc[j][1]] > dist[abc[j][0]] + abc[j][2]){ dist[abc[j][1]] = dist[abc[j][0]] + abc[j][2]; neg[abc[j][1]] = true; } if(neg[abc[j][0]] == true){ neg[abc[j][1]] = true; } } } if(neg[N]) cout << "inf" << endl; else cout << ans << endl; return 0; }
a.cc: In function 'int main()': a.cc:27:24: error: expression list treated as compound expression in initializer [-fpermissive] 27 | bool neg(N + 1, false); | ^ a.cc:41:16: error: conflicting declaration 'std::vector<bool> neg' 41 | vector<bool> neg(N + 1, false); | ^~~ a.cc:27:8: note: previous declaration as 'bool neg' 27 | bool neg(N + 1, false); | ^~~ a.cc:49:12: error: invalid types 'bool[__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type {aka long long int}]' for array subscript 49 | neg[abc[j][1]] = true; | ^ a.cc:52:13: error: invalid types 'bool[__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type {aka long long int}]' for array subscript 52 | if(neg[abc[j][0]] == true){ | ^ a.cc:53:20: error: invalid types 'bool[__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type {aka long long int}]' for array subscript 53 | neg[abc[j][1]] = true; | ^ a.cc:58:9: error: invalid types 'bool[ll {aka long long int}]' for array subscript 58 | if(neg[N]) | ^
s567213168
p03722
C++
#include <bits/stdc++.h> using namespace std; struct edge { int from; int to; long long cost; }; long long INF = 1e12; vector<long long> bellman_ford(vector<edge> es, int start_point, int vertex_num) { vector<long long> shortest_path(vertex_num, INF); shortest_path[start_point] = 0; for (int i = 0; i < vertex_num-1; i++) { for (int j = 0; j < es.size(); j++) { shortest_path[es[j].to] = min(shortest_path[es[j].to], shortest_path[es[j].from]+es[j].cost); } } return shortest_path; } bool find_negative_loop(vector<edge> es, int start_point, int vertex_num) { vector<long long> shortest_path(vertex_num, INF); shortest_path[start_point] = 0; for (int i = 0; i < vertex_num; i++) { for (int j = 0; j < es.size(); j++) { if (shortest_path[es[j].to] > shortest_path[es[j].from]+es[j].cost) { shortest_path[es[j].to] = shortest_path[es[j].from]+es[j].cost; if (i == vertex_num-1 && es[j].to == vertex_num-1) return true; } } } return false; } int main(void){ int N, M; cin >> N >> M; vector<edge> es(M); for (int i = 0; i < M; i++) { cin >> es[i].from >> es[i].to >> es[i].cost; es[i].from--; es[i].to--; es[i].cost = -es[i].cost; } if (find_negative_loop(es, 0, N)) cout << "inf"; else { vector<long long> shortest_path = bellman_ford(es, 0, N); cout << -shortest_path[N-1] } }
a.cc: In function 'int main()': a.cc:51:36: error: expected ';' before '}' token 51 | cout << -shortest_path[N-1] | ^ | ; 52 | } | ~
s826238346
p03722
C++
//#define _GLIBCXX_DEBUG #include<bits/stdc++.h> #define PI 3.14159265359 using namespace std; #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) const long long INF= 1e+18+1;; typedef long long ll; typedef vector<ll> vl; typedef vector<vector<ll> >vvl; typedef pair<ll,ll> P; typedef tuple<ll,ll,ll> T; const ll MOD=1000000007LL; string abc="abcdefghijklmnopqrstuvwxyz"; string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ"; struct edge { ll from; ll to; ll cost; }; ll V, E, d[1010]; edge es[2010]; bool find_negative_loop() { memset(d,0,sizeof(d)); for (ll i = 0; i < V; i++) { for (ll j = 0; j < E; j++) { edge e = es[j]; if (d[e.from]!=INF&&d[e.to] > d[e.from] + e.cost) { d[e.to] = d[e.from] + e.cost; if (e.to== V - 1) { return true; } } } } return false; } void shortest_path(ll s){ rep(i,V)d[i]=INF; d[s]=0; rep(j,V){ bool update=false; rep(i,E){ edge e=es[i]; if(d[e.from]!=INF&&d[e.to]>d[e.from]+e.cost){ d[e.to]=d[e.from]+e.cost; update=true; } } if(!update)break; return; } } int main(){ cin>>V>>E; rep(i,E){ ll f,t,c; cin>>f>>t>>c; es[i].from=f-1; es[i].to=t-1; es[i].cost=-c; } shortest_path(); if(find_negative_loop()){ cout<<"inf"<<endl; return 0; } rep(j,V){ rep(i,E){ edge e=es[i]; if(d[e.from]!=INF&&d[e.to]>d[e.from]+e.cost){ d[e.to]=d[e.from]+e.cost; if(e.to==V-1){ cout<<"inf"<<endl; return 0; } } } } //shortest_path(0); cout<<-d[V-1]<<endl; }
a.cc: In function 'int main()': a.cc:66:16: error: too few arguments to function 'void shortest_path(ll)' 66 | shortest_path(); | ~~~~~~~~~~~~~^~ a.cc:41:6: note: declared here 41 | void shortest_path(ll s){ | ^~~~~~~~~~~~~
s480094962
p03722
C++
//#define _GLIBCXX_DEBUG #include<bits/stdc++.h> #define PI 3.14159265359 using namespace std; #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) const long long INF= 1e+18+1;; typedef long long ll; typedef vector<ll> vl; typedef vector<vector<ll> >vvl; typedef pair<ll,ll> P; typedef tuple<ll,ll,ll> T; const ll MOD=1000000007LL; string abc="abcdefghijklmnopqrstuvwxyz"; string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ"; struct edge { ll from; ll to; ll cost; }; ll V, E, d[1010]; edge es[2010]; bool find_negative_loop() { memset(d,0,sizeof(d)); for (ll i = 0; i < V; i++) { for (ll j = 0; j < E; j++) { edge e = es[j]; if (d[e.from]!=INF&&d[e.to] > d[e.from] + e.cost) { d[e.to] = d[e.from] + e.cost; if (e.to== V - 1) { return true; } } } } return false; } void shortest_path(ll s){ rep(i,V)d[i]=INF; d[s]=0; rep(j,V){ bool update=false; rep(i,E){ edge e=es[i]; if(d[e.from]!=INF&&d[e.to]>d[e.from]+e.cost){ d[e.to]=d[e.from]+e.cost; update=true; } } if(!update)break; return; } } int main(){ cin>>V>>E; rep(i,E){ ll f,t,c; cin>>f>>t>>c; es[i].from=f-1; es[i].to=t-1; es[i].cost=-c; } //if(find_negative_loop()){ //cout<<"inf"<<endl; //return 0; //} rep(j,V){ rep(i,E){ edge e=es[i]; if(d[e.from]!=inf&&d[e.to]>d[e.from]+e.cost){ d[e.to]=d[e.from]+e.cost; if(e.to==V-1){ cout<<"inf"<<endl; return; } } } } shortest_path(0); cout<<-d[V-1]<<endl; }
a.cc: In function 'int main()': a.cc:73:27: error: 'inf' was not declared in this scope; did you mean 'ynf'? 73 | if(d[e.from]!=inf&&d[e.to]>d[e.from]+e.cost){ | ^~~ | ynf a.cc:77:21: error: return-statement with no value, in function returning 'int' [-fpermissive] 77 | return; | ^~~~~~
s002153455
p03722
C++
#define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;} template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;} #define rep(i,n) for(int i=0;i<(int)(n);i++) #define all(vec) vec.begin(),vec.end() typedef long long ll; typedef pair<ll,ll> pll; typedef pair<int,int> pii; typedef tuple<ll,ll,ll> tlll; typedef tuple<int,int,int> tiii; const ll mod=1e9+7; const ll inf=1ll<<60; typedef int ll; int main(){ int n,m; cin >> n >> m; vector<tiii> edges; rep(i,m){ int a,b,c; cin >> a >> b >> c; a--; b--; edges.emplace_back(a,b,-c); } vector<ll> dist(n,inf); dist[0]=0; bool update=true; int step=0; while(update){ update=false; rep(i,m){ int a,b; ll c; tie(a,b,c)=edges[i]; if(dist[a]+c<dist[b]){ update=true; dist[b]=dist[a]+c; } } step++; if(step>n){ cout << "inf" << endl; return 0; } } cout << -dist[n-1] << endl; }
a.cc:15:13: error: conflicting declaration 'typedef int ll' 15 | typedef int ll; | ^~ a.cc:8:19: note: previous declaration as 'typedef long long int ll' 8 | typedef long long ll; | ^~
s982955994
p03722
C++
#include<bits/stdc++.h> #define rep(i, n) for(int i=0; i<n; i++) #define repo(i, n) for(int i=1; i<=n; i++) #define INF 100100100100100 using namespace std; using ull = unsigned long long; using ll = long long; using P = pair<int, int>; const int mod = 1000000007; // 隣接リストで使う辺を表す型 struct Edge { int to; ll cost; // 辺の接続先頂点, 辺の重み Edge(int to, ll cost) : to(to), cost(cost) {} // コンストラクタ }; typedef vector<vector<Edge> > AdjList; // 隣接リストの型 AdjList graph; // グラフの辺を格納した構造体 // graph[v][i]は頂点vから出るi番目の辺Edge vector<ll> dist; // 最短距離 // 戻り値がtrueなら負の閉路を含む void bellman_ford(int n, int s) { // nは頂点数、sは開始頂点 dist = vector<ll>(n, INF); dist[s] = 0; // 開始点の距離は0 bool loop=false; for (int i = 0; i < n; i++) { for (int v = 0; v < n; v++) { for (int k = 0; k < graph[v].size(); k++) { Edge e = graph[v][k]; if (dist[v] != INF && dist[e.to] > dist[v] + e.cost) { dist[e.to] = dist[v] + e.cost; if (i == n - 1){ dist[e.to]=-INF; loop=true } // n回目にも更新があるなら負の閉路が存在 } } } } if(loop){ for (int i = 0; i < n; i++) { for (int v = 0; v < n; v++) { for (int k = 0; k < graph[v].size(); k++) { Edge e = graph[v][k]; if (dist[v] ==-INF) { dist[e.to] = -INF; } } } } } int main() { int n, m; cin >> n >> m; graph = AdjList(n); for (int i = 0; i < m; i++) { int from, to; ll cost; cin >> from >> to >> cost; --from; --to; cost*=-1; graph[from].push_back(Edge(to, cost)); } bellman_ford(n, 0); if(d[n-1]=-INF){ cout << "inf" << endl; } else { cout << -dist[n-1] << endl; } return 0; }
a.cc: In function 'void bellman_ford(int, int)': a.cc:39:22: error: expected ';' before '}' token 39 | loop=true | ^ | ; 40 | } // n回目にも更新があるなら負の閉路が存在 | ~ a.cc:58:9: warning: empty parentheses were disambiguated as a function declaration [-Wvexing-parse] 58 | int main() { | ^~ a.cc:58:9: note: remove parentheses to default-initialize a variable 58 | int main() { | ^~ | -- a.cc:58:9: note: or replace parentheses with braces to value-initialize a variable a.cc:58:12: error: a function-definition is not allowed here before '{' token 58 | int main() { | ^ a.cc:79:2: error: expected '}' at end of input 79 | } | ^ a.cc:27:33: note: to match this '{' 27 | void bellman_ford(int n, int s) { // nは頂点数、sは開始頂点 | ^
s430398178
p03722
C++
#pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #pragma GCC optimize("unroll-loops") #include <bits/stdc++.h> #define pb push_back #define sz(x) ((int)(x).size()) #define all(x) (x).begin(),(x).end() #define ll long long using namespace std; void file(){ #ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); #endif } int tc; const int N=5e5+5,M=2e6+5,MOD=1e9+7,OO=1e9; int main(){ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); //file(); int n,m; scanf("%d %d",&n,&m); std::vector<tuple<int,int,int>> edges(m); for(int i=0,a,b,c;i<m;i++)scanf("%d %d %d",&a,&b,&c),edges[i]={a,b,c}; std::vector<ll> dist(n+1,-1e18); dist[1]=0; for(int i=1;i<n;i++){ for(auto e : edges){ int a,b,c; tie(a,b,c) = e; if(dist[b]<dist[a]+c){ dist[b]=dist[a]+c; } } } for(auto e : edges){ int a,b,c; tie(a,b,c) = e; if(b==n && dist[n]<dist[a]+c){ return !printf("inf\n"); } } printf("%lld\n",dist[n] ); }
In file included from /usr/include/c++/14/string:43, from /usr/include/c++/14/bitset:52, from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52, from a.cc:4: /usr/include/c++/14/bits/allocator.h: In destructor 'std::_Vector_base<std::tuple<int, int, int>, std::allocator<std::tuple<int, int, int> > >::_Vector_impl::~_Vector_impl()': /usr/include/c++/14/bits/allocator.h:182:7: error: inlining failed in call to 'always_inline' 'std::allocator< <template-parameter-1-1> >::~allocator() noexcept [with _Tp = std::tuple<int, int, int>]': target specific option mismatch 182 | ~allocator() _GLIBCXX_NOTHROW { } | ^ In file included from /usr/include/c++/14/vector:66, from /usr/include/c++/14/functional:64, from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:53: /usr/include/c++/14/bits/stl_vector.h:132:14: note: called from here 132 | struct _Vector_impl | ^~~~~~~~~~~~
s558104613
p03722
C++
#pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #pragma GCC optimize("unroll-loops") #include <bits/stdc++.h> #define pb push_back #define sz(x) ((int)(x).size()) #define all(x) (x).begin(),(x).end() #define ll long long using namespace std; void file(){ #ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); #endif } int tc; const int N=5e5+5,M=2e6+5,MOD=1e9+7,OO=1e9; int main(){ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); //file(); int n,m; scanf("%d %d",&n,&m); std::vector<tuple<ll,ll,ll>> edges(m); for(int i=0,a,b,c;i<m;i++)scanf("%lld %lld %lld",&a,&b,&c),edges[i]={a,b,c}; std::vector<ll> dist(n+1,-1e18); dist[1]=0; for(int i=1;i<n;i++){ for(auto e : edges){ ll a,b,c; tie(a,b,c) = e; if(dist[b]<dist[a]+c){ dist[b]=dist[a]+c; } } } for(auto e : edges){ int a,b,c; tie(a,b,c) = e; if(b==n && dist[n]<dist[a]+c){ return !printf("inf\n"); } } printf("%lld\n",dist[n] ); }
In file included from /usr/include/c++/14/string:43, from /usr/include/c++/14/bitset:52, from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52, from a.cc:4: /usr/include/c++/14/bits/allocator.h: In destructor 'std::_Vector_base<std::tuple<long long int, long long int, long long int>, std::allocator<std::tuple<long long int, long long int, long long int> > >::_Vector_impl::~_Vector_impl()': /usr/include/c++/14/bits/allocator.h:182:7: error: inlining failed in call to 'always_inline' 'std::allocator< <template-parameter-1-1> >::~allocator() noexcept [with _Tp = std::tuple<long long int, long long int, long long int>]': target specific option mismatch 182 | ~allocator() _GLIBCXX_NOTHROW { } | ^ In file included from /usr/include/c++/14/vector:66, from /usr/include/c++/14/functional:64, from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:53: /usr/include/c++/14/bits/stl_vector.h:132:14: note: called from here 132 | struct _Vector_impl | ^~~~~~~~~~~~
s836583966
p03722
Java
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.List; import java.util.StringTokenizer; import contest061.BellmanFord.Response; //System.out.println(); public class Main implements Runnable { //クラス名はScoreAttack public static void main(String[] args) { Thread.setDefaultUncaughtExceptionHandler((t, e) -> System.exit(1)); new Thread(null, new Main(), "", 16 * 1024 * 1024).start(); //16MBスタックを確保して実行 } public void run() { FastScannerScoreAttack sc = new FastScannerScoreAttack(System.in); try { int N = sc.nextInt(); int M = sc.nextInt(); int[][] adj = new int[M][3]; for (int i = 0; i < M; i++) { adj[i][0] = sc.nextInt() - 1; adj[i][1] = sc.nextInt() - 1; int cost = sc.nextInt(); // 最長を求める問題なので、マイナスに変換すると、最小のマイナス値が返却される。なので、マイナスをつける。 // ベルマンフォード法は最小経路を求めるアルゴリズムであるため。 adj[i][2] = -cost; } BellmanFord bel = new BellmanFord(N, adj); Response res = bel.bellmanford(0, N - 1); if (res.result) { System.out.println(-res.costs);//マイナスをつけて符号を逆転 } else { System.out.println("inf"); } } catch (Exception e) { e.printStackTrace(); } } } //有効グラムのみ対応 class BellmanFord { private Edge[] edges; private int n; /* * n 頂点数 * adj 有効グラフの配列 */ public BellmanFord(int v, int[][] adj) { this.n = v; //辺情報の配列を作る List<Edge> list = new ArrayList<Edge>(); for (int i = 0; i < adj.length; i++) { list.add(new Edge(adj[i][0], adj[i][1], adj[i][2])); } //Source > Targetの順に並べなおす。 Collections.sort(list, new Comparator<Edge>() { @Override public int compare(Edge a, Edge b) { if (a.source < b.source) { return -1; } else if (a.source > b.source) { return 1; } else { //ここに来るということは、sourceが同じだということなので、次の条件で比較する。 return a.target - b.target; } } }); //for (Edge e : list) { // System.out.println((e.source + 1) + " " + (e.target + 1) + " " + e.cost); //} this.edges = list.toArray(new Edge[0]); //配列に変換 } /* * ベルマン-フォード法[単一始点最短経路(Single Source Shortest Path)] * s : start地点 * g : goal地点 */ Response bellmanford(int s, int g) { long[] distance = new long[n]; //始点からの最短距離 int[] count = new int[n]; //更新カウント(負の閉路チェック用) Arrays.fill(distance, Long.MAX_VALUE); //各頂点までの距離を初期化(INF 値) distance[s] = 0; //始点の距離は0 boolean negative = false; //負の閉路フラグ boolean update = true; //更新フラグ System.out.println(edges); while (update && !negative) { update = false; for (Edge e : edges) { //System.out.println((e.source + 1) + " " + (e.target + 1) + " " + e.cost); //接続元+接続先までの距離 if (distance[e.source] != Integer.MAX_VALUE && distance[e.source] + e.cost < distance[e.target]) { // System.out.println(" Pass1 " + distance[e.source] + " " + e.cost + " " + distance[e.target]); distance[e.target] = distance[e.source] + e.cost; //現在記録されている距離より小さければ更新 update = true; if (++count[e.target] >= n) { //負の閉路チェック // System.out.println(" Pass2"); negative = true; break; } } } } Response res = new Response(); if (negative) { res.result = false; res.costs = Long.MIN_VALUE; return res; //負の閉路があったときは、-INF(Integer.MIN_VALUE)を返す } res.result = true; res.costs = distance[g]; return res; //到達できなかったときは、INF(Integer.MAX_VALUE)になる } //辺情報の構造体 class Edge { public int source = 0; //接続元ノード public int target = 0; //接続先ノード public int cost = 0; //重み public Edge(int source, int target, int cost) { this.source = source; this.target = target; this.cost = cost; } public int compareTo(Edge o) { return this.cost - o.cost; } } //Response class Response { public boolean result; public long costs; } } //高速なScanner class FastScannerScoreAttack { private BufferedReader reader = null; private StringTokenizer tokenizer = null; public FastScannerScoreAttack(InputStream in) { reader = new BufferedReader(new InputStreamReader(in)); tokenizer = null; } public String next() { if (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public String nextLine() { if (tokenizer == null || !tokenizer.hasMoreTokens()) { try { return reader.readLine(); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken("\n"); } public long nextLong() { return Long.parseLong(next()); } public int nextInt() { return Integer.parseInt(next()); } public double nextDouble() { return Double.parseDouble(next()); } public int[] nextIntArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } public long[] nextLongArray(int n) { long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } }
Main.java:12: error: package contest061.BellmanFord does not exist import contest061.BellmanFord.Response; ^ Main.java:41: error: cannot find symbol Response res = bel.bellmanford(0, N - 1); ^ symbol: class Response location: class Main 2 errors
s259177766
p03722
C++
#include<bits/stdc++.h> using namespace std; #define MAX_V 1000 #define MAX_E 2000 #define INF 1e9 struct edge { int from, to, cost; }; int V, E, d[MAX_V]; edge es[MAX_E]; bool find_negative_loop(int s) { int cnt = 0; for (int i = 0; i < V; i++) { d[i] = INF; } d[s] = 0; while (true) { bool update = false; cnt++; for (int i = 0; i < E; i++) { edge e = es[i]; if (d[e.from] != INF && d[e.to] > d[e.from] + e.cost) { d[e.to] = d[e.from] + e.cost; if (cnt == V) { return true; } update = true; } } if (!update) { break; } } return false; } int main() { int r=0; cin >> V >> E; for (int i = 0; i < E; i++) { cin >> es[i].from >> es[i].to >> es[i].cost; es[i].from--; es[i].to--; es[i].cost=-es[i].cost; } if (find_negative_loop(r)) { cout << "inf" << endl; } else { cout << d[V-1] << endl; } } return 0; }
a.cc:53:5: error: expected unqualified-id before 'return' 53 | return 0; | ^~~~~~ a.cc:54:1: error: expected declaration before '}' token 54 | } | ^
s785691322
p03722
C++
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int maxn = 2000 + 5; const ll oo = 0x3f3f3f3f3f3f3f3f; int N, M; ll d1, d2; int main(){ while (cin >> N >> M){ vector<int>a(M); vector<int>b(M); vector<ll>c(M); for (int i = 0; i < M; i++){ cin >> a[i] >> b[i] >> c[i]; a[i]--, b[i]--; } vector<ll>d(N, -oo); d[0] = 0LL; for (int i = 0; i < 2 * N; i++){ for (int j = 0; j < M; j++){ d[b[j]] = max(d[b[j]], d[a[j]] + c[j]); } if (i == N - 1)d1 = d[N - 1]; if (i == 2 * N - 1)d2 = d[N - 1]; } if (d1 == d2)cout << d1 << endl; else cout << "inf" << endl; }
a.cc: In function 'int main()': a.cc:28:10: error: expected '}' at end of input 28 | } | ^ a.cc:8:11: note: to match this '{' 8 | int main(){ | ^
s126882413
p03722
C++
#include "pch.h" #include <iostream> #include <string> #include <vector> #include <cmath> #include <queue> #include <map> #include <set> #include <stack> #include<algorithm> #include<sstream> #include<iomanip> #include<deque> #include<list> using namespace std; typedef long long ll; typedef pair<int, int> pii; const ll MOD_CONST = 1000000007; const ll BIG_NUM = 1000000000000000000; const int BIG_INT = 1000000000; int main() { int n, m; cin >> n >> m; vector<vector<pii>> g(n); for (int i = 0; i < m; i++) { int a, b, c; cin >> a >> b >> c; a--; b--; g[a].emplace_back(make_pair(b, -c)); } vector<ll> d(n, BIG_NUM); d[0] = 0; bool isInf = false; for (int i = 0; i < n; i++) { for (int j = 0; j < n;j++) { for (pii e : g[j]) { if (d[e.first] > d[j] + e.second) { d[e.first] = d[j] + e.second; if (i == n - 1) { isInf = true; } } } } } if (isInf) { cout << "inf"<< endl; } else { cout << -d[n - 1] << endl; } }
a.cc:1:10: fatal error: pch.h: No such file or directory 1 | #include "pch.h" | ^~~~~~~ compilation terminated.
s923145021
p03722
C++
#pragma GCC optimize("Ofast") #include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<n;i++) #define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i]; #define max3(a,b,c) max(max(a,b),c) #define min3(a,b,c) min(min(a,b),c) #define ft first #define sc second #define pb push_back #define lb lower_bound #define ub upper_bound #define all(v) (v).begin(),(v).end() #define mod 1000000007 using namespace std; typedef long long ll; template<class T> using V=vector<T>; using Graph = vector<vector<int>>; using P=pair<ll,ll>; typedef unsigned long long ull; typedef long double ldouble; template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } const ll max_E=100000; const ll max_V=100000; ll INF=9000000000000000000; struct edge{ll from,to,cost;}; edge es[max_E]; ll dist[max_V]; ll N,M; bool negative[max_V]; void shortest_path(ll s){ fill(negative,negative+N,0); for(int i=0;i<N;i++) dist[i]=INF;//INFを作る dist[s]=0; for(int loop=0;loop<N-1;loop++){ for(int i=0;i<M;i++){ edge e=es[i]; if(dist[e.from]==INF) continue; if(dist[e.from]!=INF&&dist[e.to]>dist[e.from]+e.cost){ dist[e.to]=dist[e.from]+e.cost; } } } } void find_negative_loop(){ for(int i=0;i<N;i++){ for(int j=0;j<M;j++){ if(dist[e.from]==INF) continue; edge e=es[j]; if(dist[e.to]>dist[e.from]+e.cost){ dist[e.to]=dist[e.from]+e.cost; negative[e.to]=1; } if(negative[e.from]) negative[e.to]=1; } } } int main(){ cin>>N>>M; for(ll i=0;i<M;i++){ ll a,b,c; cin>>a>>b>>c; a--;b--; es[i].from=a; es[i].to=b; es[i].cost=-c; } shortest_path(0); find_negative_loop(); if(negative[N-1]) cout<<"inf"<<endl; else{ cout<<-dist[N-1]<<endl; } }
a.cc: In function 'void find_negative_loop()': a.cc:53:21: error: 'e' was not declared in this scope 53 | if(dist[e.from]==INF) continue; | ^
s026712923
p03722
C++
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++) #define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++) #define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--) #define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--) #define all(x) (x).begin(), (x).end() #define sz(x) ((ll)(x).size()) #define len(x) ((ll)(x).length()) template<class T> struct BellmanFord { private: struct Edge { int from, to, cost; }; vector<Edge> edges; int n; public: const T inf = numeric_limits<T>::max() / 2 - 1; vector<T> dist; vector<bool> negative; BellmanFord() {} BellmanFord(int _n) { n = _n; dist.resize(n); negative.resize(n); } void add_edge(int from, int to, int cost) { edges.push_back((Edge){from, to, cost}); } void get_distance(int from) { for (int i = 0; i < n; i++) { dist[i] = inf; negative[i] = false; } dist[from] = 0; for (int i = 0; i < (n - 1); i++) { for (auto e : edges) { if ((dist[e.from] != inf) && (dist[e.to] > (dist[e.from] + e.cost))) { dist[e.to] = dist[e.from] + e.cost; update = true; } } } for (int i = 0; i < n; i++) { for (auto e : edges) { if ((dist[e.from] != inf) && (dist[e.to] > (dist[e.from] + e.cost))) { dist[e.to] = dist[e.from] + e.cost; negative[e.from] = negative[e.to] = true; } } } } }; int main() { cin.tie(0); ios::sync_with_stdio(false); // ifstream in("input.txt"); // cin.rdbuf(in.rdbuf()); ll n, m; cin >> n >> m; BellmanFord<ll> bf(n); rep(i, m) { ll a, b, c; cin >> a >> b >> c; a--; b--; bf.add_edge(a, b, -c); } bf.get_distance(0); if (bf.negative[n - 1]) { cout << "inf" << endl; } else { cout << (-bf.dist[n - 1]) << endl; } return 0; }
a.cc: In member function 'void BellmanFord<T>::get_distance(int)': a.cc:45:21: error: 'update' was not declared in this scope 45 | update = true; | ^~~~~~
s549535462
p03722
C++
#include <bits/stdc++.h> using namespace std; typedef long long ll; //Number unexplored line, INF = infinity const ll INF = 1LL << 50; int main(void){ //문제에서 주어진 노드와 간선의 최대수 const int NMAX = 1005; const int MMAX = 2005; //Number of Node, N and Roads, M int N, M; cin >> N >> M; //각각의 노드 사이의 비중과 경로 dist vector< pair<int, int> > Node[MMAX]; ll dist[NMAX]; fill_n(dist, sizeof(dist), INF); //노드와 노드사이를 연결하는 입력이 주어진다 for(int i = 0; i < M; i++){ int node1, node2, weight; cin >> node1 >> node2 >> weight; Node[node1].emplace_back(node2, weight); } //최단경로는 순환을 포함해서는 안되므로 //최단경로의 최대 길이는 N-1 //즉, N 이상이 된다면 음수사이클이 생기므로 멈춰야함 //간선의 최대수는 M^2까지 생기므로 시간복잡도는 N^3 int Start_Point = 1; int End_Point = N-1; //자기자신까지의 최단경로는 0 dist[Start_Point] = 0; bool Cycle = 0; //N-1번 루프. N번째는 사이클 확인 for(int i = 1; i <= N; i++){ //N-1번 루프에 걸쳐서 각 노드가 i개의 정점을 거쳐오는 최단경로 갱신 for(int j = 1; j <= N; j++){ for(auto &fd : Node[j]){ //아직 if(dist[j] == INF) continue; if(dist[j] + fd.second < dist[fd.first]){ dist[fd.first] = fd.second + dist[j]; if (i == N) Cycle = TRUE; } } } } if(Cycle == TRUE) cout << "inf" << endl; else cout << dist[End_Point]; }
a.cc: In function 'int main()': a.cc:51:41: error: 'TRUE' was not declared in this scope 51 | if (i == N) Cycle = TRUE; | ^~~~ a.cc:58:17: error: 'TRUE' was not declared in this scope 58 | if(Cycle == TRUE) cout << "inf" << endl; | ^~~~
s504717219
p03722
C++
#include <bits/stdc++.h> using namespace std; typedef long long ll; //Number unexplored line, INF = infinity const ll INF = 1LL << 50; int main(void){ //문제에서 주어진 노드와 간선의 최대수 const int NMAX = 1005; const int MMAX = 2005; //Number of Node, N and Roads, M int N, M; cin >> N >> M; //각각의 노드 사이의 비중과 경로 dist vector< pair<int, int> > Node[MMAX]; ll dist[NMAX]; fill_n(dist, sizeof(dist), INF); //노드와 노드사이를 연결하는 입력이 주어진다 for(int i = 0; i < M; i++){ int node1, node2, weight; cin >> node1 >> node2 >> weight; Node[node1].emplace_back(node2, weight); } //최단경로는 순환을 포함해서는 안되므로 //최단경로의 최대 길이는 N-1 //즉, N 이상이 된다면 음수사이클이 생기므로 멈춰야함 //간선의 최대수는 M^2까지 생기므로 시간복잡도는 N^3 int Start_Point = 1; int End_Point = N-1; //자기자신까지의 최단경로는 0 dist[Start_Point] = 0; bool Cycle = 0; //N-1번 루프. N번째는 사이클 확인 for(int i = 1; i <= N; i++){ //N-1번 루프에 걸쳐서 각 노드가 i개의 정점을 거쳐오는 최단경로 갱신 for(int j = 1; j <= N; j++){ for(auto &fd : Node[j]){ //아직 if(dist[j] == INF) continue; if(dist[j] + fd.second < dist[fd.first]){ dist[fd.first] = fd.second + dist[j]; if (i == N) Cycle = True; } } } } if(Cycle == True) cout << "Cycle" << endl; else cout << dist[End_Point]; }
a.cc: In function 'int main()': a.cc:50:41: error: 'True' was not declared in this scope 50 | if (i == N) Cycle = True; | ^~~~ a.cc:57:17: error: 'True' was not declared in this scope 57 | if(Cycle == True) cout << "Cycle" << endl; | ^~~~
s556481686
p03722
C++
#include<iostream> #include<algorithm> #include<utility> #include<vector> using namespace std; typedef long long ll;//ベルマンとかはllにしよ //ここ十分にしないとだめ #define INF 1000000000000 struct Edge{ ll to_Node; ll cost; Edge(ll t,ll c){to_Node=t;cost=c;} }; //関係ないループを外す bool bellmanford(vector< vector<Edge> >& Edges,vector<ll>& mincost,ll n){ //(l1-1)(普通のbellman)+1(検出) for(ll i=0;i<n;i++){ f=false; for(ll j=0;j<n;j++){ if(mincost[j]!=INF){ ll e=Edges[j].size(); for(ll k=0;k<e;k++){ ll new_mincost=mincost[j]+Edges[j][k].cost; if(mincost[Edges[j][k].to_Node]>new_mincost){ mincost[Edges[j][k].to_Node]=new_mincost; if(i==n-1 and Edges[j][k].to_Node==n-1)return true; } } } } } return false;//負の閉路があればtrue } int main(){ ll n,m;cin >> n >> m; vector<ll> mincost(n,INF); vector< vector<Edge> > Edges(n); //mincost0の更新だけしっかりやる mincost[0]=0; for(ll i=0;i<m;i++){ ll a,b,c;cin >> a >> b >> c; Edges[a-1].push_back(Edge(b-1,-c)); } //Nodesを更新 if(bellmanford(Edges,mincost,n)){ cout << "inf" << endl; }else{ cout << -mincost[n-1] << endl; } }
a.cc: In function 'bool bellmanford(std::vector<std::vector<Edge> >&, std::vector<long long int>&, ll)': a.cc:20:5: error: 'f' was not declared in this scope 20 | f=false; | ^
s767741025
p03722
C++
#include<iostream> #include<algorithm> #include<utility> #include<vector> using namespace std; typedef long long ll;//ベルマンとかはllにしよ //ここ十分にしないとだめ #define INF 1000000000000 struct Node{ //ノードの情報 vector<pair<ll,ll>> edge;//各エッジの接続先のノード番号とコスト //ベルマンフォード法用のデータ ll mincost=INF;//そのノードへの最小コスト }; //関係ないループを外す bool bellmanford(vector<Node>& nodes,ll l1){ //(l1-1)(普通のbellman)+1(検出) for(ll i=0;i<l1;i++){ for(ll j=0;j<l1;j++){ Node x=nodes[j]; if(x.mincost!=INF){ ll l2=x.edge.size(); for(ll k=0;k<l2;k++){ ll a=x.mincost+x.edge[k].second; if(nodes[x.edge[k].first].mincost>a){ nodes[x.edge[k].first].mincost=a; if(i==l-1 and x.edge[k].first==l-1) return true; } } } } } return false;//負の閉路があればtrue } int main(){ ll n,m;cin >> n >> m; vector<Node> Nodes(n); //mincost0の更新だけしっかりやる Nodes[0].mincost=0; for(ll i=0;i<m;i++){ ll a,b,c;cin >> a >> b >> c; Nodes[a-1].edge.push_back(make_pair(b-1,-c)); } //Nodesを更新 if(bellmanford(Nodes,n)){ cout << "inf" << endl; }else{ cout << -Nodes[n-1].mincost << endl; } }
a.cc: In function 'bool bellmanford(std::vector<Node>&, ll)': a.cc:29:19: error: 'l' was not declared in this scope 29 | if(i==l-1 and x.edge[k].first==l-1) return true; | ^
s054479448
p03722
C++
#include <bits/stdc++.h> using namespace std; #define REP(i,a) for(int i = 0; i < (a); i++) #define ALL(a) (a).begin(),(a).end() typedef long long ll; typedef pair<int, int> P; const int INF = 1e9; const long long LINF = 1e18; const long long MOD = 1e9 + 7; template <typename T> struct edge{ int from, to; T cost; edge(int from, int to, T cost = 1) : from(from), to(to), cost(cost){} bool operator < (const edge & e) const{ return cost < e.cost; } }; /* sからたどりつける負の閉路を検出したとき、空の vector を返す 頂点数 V, 始点 s, 辺の集合 es, INF として LINF を使うとき : vector<ll> dist = BellmanFord(V, s, es, LINF); */ template <typename T> vector<T> BellmanFord(int V, int s, vector<edge<T>> & es, const T INF = 1e9){ int E = es.size(); vector<T> dist(V, INF); dist[s] = 0; for(int i = 0; i < V - 1; i++){ for(edge<T> & e : es){ if(dist[e.from] == INF) continue; dist[e.to] = min(dist[e.to], dist[e.from] + e.cost); } } for(edge<T> & e : es){ if(dist[e.from] == INF) continue; if(dist[e.from] + e.cost < dist[e.to] && e.to == n - 1) return vector<T>(); } return dist; } //グラフ全体をみて、負の閉路が存在するとき true を返す template <typename T> bool FindNegativeLoop(int V, vector<edge<T>> & es){ vector<T> dist(V, 0); for(int i = 0; i < V; i++){ for(edge<T> & e : es){ if(dist[e.to] > dist[e.from] + e.cost){ dist[e.to] = dist[e.from] + e.cost; if(i == V - 1) return true; } } } return false; } signed main(){ int n,m; cin >> n >> m; int a,b; ll c; vector<edge<ll>> es; REP(i,m){ cin >> a >> b >> c; a--; b--; es.emplace_back(a, b, -c); } vector<ll> dist = BellmanFord(n, 0, es, LINF); if(dist.size() > 0) cout << -dist[n - 1] << endl; else cout << "inf" << endl; return 0; }
a.cc: In function 'std::vector<_Tp> BellmanFord(int, int, std::vector<edge<T> >&, T)': a.cc:39:58: error: 'n' was not declared in this scope 39 | if(dist[e.from] + e.cost < dist[e.to] && e.to == n - 1) return vector<T>(); | ^
s240497273
p03722
C++
#include <bits/stdc++.h> using namespace std; #define REP(i,a) for(int i = 0; i < (a); i++) #define ALL(a) (a).begin(),(a).end() typedef long long ll; typedef pair<int, int> P; const int INF = 1e9; const long long LINF = 1e18; const long long MOD = 1e9 + 7; template <typename T> struct edge{ int from, to; T cost; edge(int from, int to, T cost = 1) : from(from), to(to), cost(cost){} bool operator < (const edge & e) const{ return cost < e.cost; } }; /* sからたどりつける負の閉路を検出したとき、空の vector を返す 頂点数 V, 始点 s, 辺の集合 es, INF として LINF を使うとき : vector<ll> dist = BellmanFord(V, s, es, LINF); */ template <typename T> vector<T> BellmanFord(int V, int s, vector<edge<T>> & es, const T INF = 1e9){ int E = es.size(); vector<T> dist(V, INF); dist[s] = 0; for(int i = 0; i < V - 1; i++){ for(edge<T> & e : es){ if(dist[e.from] == INF) continue; dist[e.to] = min(dist[e.to], dist[e.from] + e.cost); } } for(edge<T> & e : es){ if(dist[e.from] == INF) continue; if(dist[e.from] + e.cost < dist[e.to]) return vector<T>(); } return dist; } //グラフ全体をみて、負の閉路が存在するとき true を返す template <typename T> bool FindNegativeLoop(int V, vector<edge<T>> & es){ vector<T> dist(V, 0); for(int i = 0; i < V; i++){ for(edge<T> & e : es){ if(dist[e.to] > dist[e.from] + e.cost){ dist[e.to] = dist[e.from] + e.cost; if(i == V - 1) return true; } } } return false; } signed main(){ int n,m; cin >> n >> m; int a,b; ll c; vector<edge<ll>> es; REP(i,m){ cin >> a >> b >> c; a--; b--; es.emplace_back(a, b, -c); } vector<ll> dist = BellmanFord(n, 0, es, 1e15); if(dist.size()) cout << -dist[n - 1] << endl; else cout << "inf" << endl; return 0; }
a.cc: In function 'int main()': a.cc:71:34: error: no matching function for call to 'BellmanFord(int&, int, std::vector<edge<long long int> >&, double)' 71 | vector<ll> dist = BellmanFord(n, 0, es, 1e15); | ~~~~~~~~~~~^~~~~~~~~~~~~~~~ a.cc:27:11: note: candidate: 'template<class T> std::vector<_Tp> BellmanFord(int, int, std::vector<edge<T> >&, T)' 27 | vector<T> BellmanFord(int V, int s, vector<edge<T>> & es, const T INF = 1e9){ | ^~~~~~~~~~~ a.cc:27:11: note: template argument deduction/substitution failed: a.cc:71:34: note: deduced conflicting types for parameter 'T' ('long long int' and 'double') 71 | vector<ll> dist = BellmanFord(n, 0, es, 1e15); | ~~~~~~~~~~~^~~~~~~~~~~~~~~~
s779607361
p03722
C++
#include <bits/stdc++.h> using namespace std; #define REP(i,a) for(int i = 0; i < (a); i++) #define ALL(a) (a).begin(),(a).end() typedef long long ll; typedef pair<int, int> P; const int INF = 1e9; const long long LINF = 1e18; const long long MOD = 1e9 + 7; /* MODint依存 */ template <typename T> struct Comb{ vector<T> fac, fin; Comb(int sz) : fac(sz + 1), fin(sz + 1){ fac[0] = fin[sz] = T(1); for(int i = 1; i <= sz; i++){ fac[i] = fac[i - 1] * T(i); } fin[sz] /= fac[sz]; for(int i = sz - 1; i >= 0; i--){ fin[i] = fin[i + 1] * T(i + 1); } } /* 階乗 */ inline T fact(int k) const { return fac[k]; } inline T finv(int k) const { return fin[k]; } /* 順列 */ T P(int n, int k) const { if(k < 0 || n < k) return T(0); return fac[n] * fin[n - k]; } /* 組み合わせ */ T C(int n, int k) const { if(k < 0 || n < k) return T(0); return fac[n] * fin[n - k] * fin[k]; } /* 重複組み合わせ */ T H(int n, int k) const { if(n < 0 || k < 0) return T(0); return k == 0 ? T(1) : C(n + k - 1, k); } /* ベル数 */ T B(int n, int k) const { if(n == 0) return T(1); k = min(k, n); vector<T> dp(k + 1); dp[0] = T(1); for(int i = 1; i <= k; i++){ if(i & 1) dp[i] = dp[i - 1] - fin[i]; else dp[i] = dp[i - 1] + fin[i]; } T res(0); for(int i = 1; i <= k; i++){ /* MODint依存 */ res += T(i).pow(n) * fin[i] * dp[k - i]; } return res; } /* スターリング数 */ T S(int n, int k) const { T res(0); for(int i = 1; i <= k; i++){ /* MODint依存 */ T t = C(k, i) * T(i).pow(n); if((k - i) & 1) res -= t; else res += t; } return res * fin[k]; } }; /* P(5, 3)の場合 : 0 + 0 + 5 = 0 + 1 + 4 = 0 + 2 + 3 = 1 + 1 + 3 = 1 + 2 + 2 よって、P(5, 3) = 5 */ template <typename T> struct Partition{ vector<vector<T>> dp; Partition(int sz) : dp(sz + 1, vector<T>(sz + 1)){ dp[0][0] = T(1); for(int i = 0; i <= sz; i++){ for(int j = 1; j <= sz; j++){ if(i - j >= 0) dp[i][j] = dp[i][j - 1] + dp[i - j][j]; else dp[i][j] = dp[i][j - 1]; } } } /* 分割数 */ T P(int n, int k){ if(n < 0 || k < 0) return T(0); return dp[n][k]; } }; signed main(){ int n; cin >> n; int a; int cnt[n + 1]; REP(i,n + 1){ cin >> a; cnt[a]++; } Comb<Mint<>> C(1000); return 0; }
a.cc: In function 'int main()': a.cc:118:10: error: 'Mint' was not declared in this scope; did you mean 'uint'? 118 | Comb<Mint<>> C(1000); | ^~~~ | uint a.cc:118:14: error: template argument 1 is invalid 118 | Comb<Mint<>> C(1000); | ^ a.cc:118:15: error: expected unqualified-id before '>' token 118 | Comb<Mint<>> C(1000); | ^~
s922870304
p03722
C++
//#define _CRT_SECURE_NO_WARNINGS #include "bits/stdc++.h" #define rep(i,n) for(ll (i)=0;(i)<(n);(i)++) #define all(x) (x).begin(),(x).end() #define MOD 1000000007 #define INF (1LL<<60LL) typedef long long ll; using namespace std; ll n, m; vector<vector<ll>> g(1001, vector<ll>()); map<pair<ll, ll>, ll> m1; vector<ll> vec(1001, 0); ll ans = -INF; ll ret(ll a, ll s,vector<ll> svec, ll k) { k++; if (k > 1000) return 0; if (svec[a]==1) { if (vec[a] < s) { cout << "inf" << endl; exit(0); } else { return 0; } } svec[a] = 1; vec[a] = s; for (auto b : g[a]) { if (b == n) { ans = max(ans, s + m1[{a, b}]); } ret(b, s+ m1[{a, b}],svec); } } int main() { cin >> n >> m; rep(i, m) { ll a, b, c; cin >> a >> b >> c; g[a].emplace_back(b); m1[{a, b}] = c; } vector<ll> svec(n+1, 0); ret(1, 0, svec,0); cout << ans << endl; }
a.cc: In function 'll ret(ll, ll, std::vector<long long int>, ll)': a.cc:37:20: error: too few arguments to function 'll ret(ll, ll, std::vector<long long int>, ll)' 37 | ret(b, s+ m1[{a, b}],svec); | ~~~^~~~~~~~~~~~~~~~~~~~~~~ a.cc:18:4: note: declared here 18 | ll ret(ll a, ll s,vector<ll> svec, ll k) { | ^~~ a.cc:39:1: warning: control reaches end of non-void function [-Wreturn-type] 39 | } | ^
s235695271
p03722
C++
//#include "stdafx.h" #include <iostream> #include <set> #include <queue> #include <vector> #include <algorithm> #include <math.h> #include <cmath> #include <string> #include <cstring> #include <climits> #include <sstream> #include <iomanip> #include <map> #include <stack> #include <tuple> #include <numeric> #include <assert.h> #include <functional> #include <unordered_map> using namespace std; /*-----------------------------------------------------------------------------  定義 -------------------------------------------------------------------------------*/ #define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i)) #define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i)) #define INF 2e9 #define MOD (1000 * 1000 * 1000 + 7) #define Ceil(x, n) (((((x))+((n)-1))/n)) /* Nの倍数に切り上げ割り算 */ #define CeilN(x, n) (((((x))+((n)-1))/n)*n) /* Nの倍数に切り上げ */ #define FloorN(x, n) ((x)-(x)%(n)) /* Nの倍数に切り下げ */ #define IsOdd(x) (((x)&0x01UL) == 0x01UL) #define IsEven(x) (!IsOdd((x))) #define BitSetV(Val,Bit) ((Val) |= (Bit)) #define BitTstV(Val,Bit) ((Val) & (Bit)) #define ArrayLength(x) (sizeof( x ) / sizeof( x[ 0 ])) #define MAX_QWORD ((QWORD)0xFFFFFFFFFFFFFFFF) #define M_PI 3.14159265358979323846 typedef long long ll; typedef unsigned long long int QWORD; typedef pair<ll, ll> P; /*-----------------------------------------------------------------------------  処理 -------------------------------------------------------------------------------*/ // 枝定義 struct Edge { int from; int to; ll dist; Edge(){} Edge(int from, int to, ll dist): from(from), to(to), dist(dist){} }; // ベルマンフォード template<class D, D intDist, class E> struct BellmanFord { // res[i] = sからiまでの最短距離 vector<D> dist; vector<E> edgeList; bool update; int nodeMax; // 各節の最短経路を算出 BellmanFord(int argNodeMax, const vector<E> &argEdgeList, int startPos) { edgeList = argEdgeList; nodeMax = argNodeMax; dist = vector<D>(nodeMax, intDist); dist[startPos] = 0; for (int i = 0; i < nodeMax * 2; i++) { update = false; for (E edge : edgeList) { D nextDist = dist[edge.from] + edge.dist; if (dist[edge.to] < nextDist) { dist[edge.to] = nextDist; update = true; } } if (!update) { break; } } } // まだ更新が可能かどうか bool isNegative(int nodeNo) { vector<D> distTmp(nodeMax, intDist); distTmp = dist; vector<bool> negativeList(nodeMax, false); for (int i = 0; i < nodeMax; i++) { update = false; for (E edge : edgeList) { if (distTmp[edge.from] != intDist) { D nextDist = distTmp[edge.from] + edge.dist; if (distTmp[edge.to] < nextDist) { distTmp[edge.to] = nextDist; negativeList[edge.to] = true; update = true; } } } if (!update) { break; } } return negativeList[nodeNo]; } }; int main() { int N, M; cin >> N >> M; vector<Edge> edgeList; REP(i, M) { int a, b, c; cin >> a >> b >> c; a--, b--; edgeList.emplace_back(Edge(a, b, c)); } BellmanFord<ll, (ll)-10e15, Edge> res(N, edgeList, 0); if (!res.update)) { //if (!res.isNegative(N - 1)) { cout << res.dist[N - 1] << endl; } else { cout << "inf" << endl; } return 0; }
a.cc: In function 'int main()': a.cc:134:25: error: expected primary-expression before ')' token 134 | if (!res.update)) { | ^
s610393173
p03722
C++
// ベルマンフォード法(O(V*E))V:頂点、E:辺の数 // 単一始点最短路問題 // 負の辺を含む時はこっち // 含まない時はdijkstraダイクストラ(O(ElogV))が良い。 #include <bits/stdc++.h> #define SORT(v, n) sort(v, v+n); #define VSORT(v) sort(v.begin(), v.end()); #define size_t unsigned long long #define ll long long #define rep(i,a) for(int i=0;i<(a);i++) #define repr(i,a) for(int i=(int)(a)-1;i>=0;i--) #define FOR(i,a,b) for(int i=(a);i<(b);i++) #define FORR(i,a,b) for(int i=(int)(b)-1;i>=a;i--) #define ALL(a) a.begin(), a.end() using namespace std; int si() { int x; scanf("%d", &x); return x; } long long sl() { long long x; scanf("%lld", &x); return x; } string ss() { string x; cin >> x; return x; } void pi(int x) { printf("%d ", x); } void pl(long long x) { printf("%lld ", x); } void pd(double x) { printf("%.15f ", x); } void ps(const string &s) { printf("%s ", s.c_str()); } void br() { putchar('\n'); } // 頂点fromから頂点toへのコストcostの辺 struct edge { ll from, to, cost; }; typedef pair<ll, ll> P; const int N = 1e3+5; const int M = 2e3+5; const ll INF = 1e17+5; edge es[M]; // 辺 ll d[N]; // 最短距離 ll V,E; // Vは頂点数, Eは辺数 // vector<P> G[N]; // s番目の頂点から各頂点への最短距離を求める void shortest_path(int s) { rep(i,V) d[i] = -INF; d[s] = 0; while (true) { bool update = false; rep(i,E) { edge e = es[i]; if(d[e.from] != -INF && d[e.to] < d[e.from] + e.cost) { d[e.to] = d[e.from] + e.cost; // cout << e.to << " : " << d[e.to] << endl; update = true; } } if(!update) break; } } // trueなら負の閉路が存在する bool find_negative_loop() { memset(d,0,sizeof(d)); rep(i,V) rep(j,E){ edge e = es[j]; if(d[e.to] < d[e.from] + e.cost) { d[e.to] = d[e.from] + e.cost; // n回目にも更新があるなら負の閉路が存在する if(i == V - 1) return true; } } return false; } ll n,m,a,b,c; int main () { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> V >> E// ベルマンフォード法(O(V*E))V:頂点、E:辺の数 // 単一始点最短路問題 // 負の辺を含む時はこっち // 含まない時はdijkstraダイクストラ(O(ElogV))が良い。 #include <bits/stdc++.h> #define SORT(v, n) sort(v, v+n); #define VSORT(v) sort(v.begin(), v.end()); #define size_t unsigned long long #define ll long long #define rep(i,a) for(int i=0;i<(a);i++) #define repr(i,a) for(int i=(int)(a)-1;i>=0;i--) #define FOR(i,a,b) for(int i=(a);i<(b);i++) #define FORR(i,a,b) for(int i=(int)(b)-1;i>=a;i--) #define ALL(a) a.begin(), a.end() using namespace std; int si() { int x; scanf("%d", &x); return x; } long long sl() { long long x; scanf("%lld", &x); return x; } string ss() { string x; cin >> x; return x; } void pi(int x) { printf("%d ", x); } void pl(long long x) { printf("%lld ", x); } void pd(double x) { printf("%.15f ", x); } void ps(const string &s) { printf("%s ", s.c_str()); } void br() { putchar('\n'); } // 頂点fromから頂点toへのコストcostの辺 struct edge { ll from, to, cost; }; typedef pair<ll, ll> P; const int N = 1e3+5; const int M = 2e3+5; const ll INF = 1e17+5; edge es[M]; // 辺 ll d[N]; // 最短距離 ll V,E; // Vは頂点数, Eは辺数 // vector<P> G[N]; // s番目の頂点から各頂点への最短距離を求める void shortest_path(int s) { rep(i,V) d[i] = -INF; d[s] = 0; rep(i,2*V) { // cout << i << endl; bool update = false; rep(i,E) { edge e = es[i]; if(d[e.from] != -INF && d[e.to] < d[e.from] + e.cost) { d[e.to] = d[e.from] + e.cost; // cout << e.to << " : " << d[e.to] << endl; update = true; } } if(!update) break; } } // trueなら負の閉路が存在する bool find_negative_loop() { rep(i,V) d[i] = -INF; rep(i,2 * V) rep(j,E){ edge e = es[j]; if(d[e.to] < d[e.from] + e.cost) { d[e.to] = d[e.from] + e.cost; // n回目にも更新があるなら負の閉路が存在する // cout << i << " : " << e.to << endl; if(i >= V - 1 && e.to == V-1) return true; } // cout << i << " : " << 2*V << endl; } // cout << "false " << endl; return false; } ll a,b,c; int main () { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> V >> E; rep(i,E) { cin >> a >> b >> c; a--;b--; es[i] = (edge) {a,b,c}; } if(find_negative_loop()) { cout << "inf" << endl; return 0; } shortest_path(0); cout << d[V-1] << endl; } ; rep(i,E) { cin >> a >> b >> c; a--;b--; es[i] = (edge) {a,b,c}; } if(find_negative_loop()) { cout << "inf" << endl; return 0; } shortest_path(0); cout << d[V-1] << endl; }
a.cc: In function 'int main()': a.cc:77:16: error: expected ';' before 'using' 77 | cin >> V >> E// ベルマンフォード法(O(V*E))V:頂点、E:辺の数 | ^ | ; ...... 93 | using namespace std; | ~~~~~ a.cc:94:7: warning: empty parentheses were disambiguated as a function declaration [-Wvexing-parse] 94 | int si() { int x; scanf("%d", &x); return x; } | ^~ a.cc:94:7: note: remove parentheses to default-initialize a variable 94 | int si() { int x; scanf("%d", &x); return x; } | ^~ | -- a.cc:94:7: note: or replace parentheses with braces to value-initialize a variable a.cc:94:10: error: a function-definition is not allowed here before '{' token 94 | int si() { int x; scanf("%d", &x); return x; } | ^ a.cc:95:13: warning: empty parentheses were disambiguated as a function declaration [-Wvexing-parse] 95 | long long sl() { long long x; scanf("%lld", &x); return x; } | ^~ a.cc:95:13: note: remove parentheses to default-initialize a variable 95 | long long sl() { long long x; scanf("%lld", &x); return x; } | ^~ | -- a.cc:95:13: note: or replace parentheses with braces to value-initialize a variable a.cc:95:16: error: a function-definition is not allowed here before '{' token 95 | long long sl() { long long x; scanf("%lld", &x); return x; } | ^ a.cc:96:10: warning: empty parentheses were disambiguated as a function declaration [-Wvexing-parse] 96 | string ss() { string x; cin >> x; return x; } | ^~ a.cc:96:10: note: remove parentheses to default-initialize a variable 96 | string ss() { string x; cin >> x; return x; } | ^~ | -- a.cc:96:13: error: a function-definition is not allowed here before '{' token 96 | string ss() { string x; cin >> x; return x; } | ^ a.cc:97:16: error: a function-definition is not allowed here before '{' token 97 | void pi(int x) { printf("%d ", x); } | ^ a.cc:98:22: error: a function-definition is not allowed here before '{' token 98 | void pl(long long x) { printf("%lld ", x); } | ^ a.cc:99:19: error: a function-definition is not allowed here before '{' token 99 | void pd(double x) { printf("%.15f ", x); } | ^ a.cc:100:26: error: a function-definition is not allowed here before '{' token 100 | void ps(const string &s) { printf("%s ", s.c_str()); } | ^ a.cc:101:11: error: a function-definition is not allowed here before '{' token 101 | void br() { putchar('\n'); } | ^ a.cc:116:27: error: a function-definition is not allowed here before '{' token 116 | void shortest_path(int s) { | ^ a.cc:135:24: warning: empty parentheses were disambiguated as a function declaration [-Wvexing-parse] 135 | bool find_negative_loop() { | ^~ a.cc:135:24: note: remove parentheses to default-initialize a variable 135 | bool find_negative_loop() { | ^~ | -- a.cc:135:24: note: or replace parentheses with braces to value-initialize a variable a.cc:135:27: error: a function-definition is not allowed here before '{' token 135 | bool find_negative_loop() { | ^ a.cc:154:10: warning: empty parentheses were disambiguated as a function declaration [-Wvexing-parse] 154 | int main () { | ^~ a.cc:154:10: note: remove parentheses to default-initialize a variable 154 | int main () { | ^~ | -- a.cc:154:10: note: or replace parentheses with braces to value-initialize a variable a.cc:154:13: error: a function-definition is not allowed here before '{' token 154 | int main () { | ^
s111948711
p03722
C++
#include <iostream> #include <algorithm> #include <set> using namespace std; int n, m; long long res[50000]; long long a[50000], b[50000], c[50000]; vector<int> g[50000], vg[50000]; int t[50000], f[50000]; int main() { cin >> n >> m; for (int i = 0; i < m; i++) {cin >> a[i] >> b[i] >> c[i]; g[a[i]].push_back(b[i]); vg[b[i]].push_back(a[i]);} vector<int> v(1); t[1] = 1; for (int i = 0; i < v.size(); i++) { for (int j = 0; j < g[v[i]].size(); j++) { if (t[g[v[i]][j]] == 0) {t[g[v[i]][j]] = 1; v.push_back(g[v[i]][j]);} } } v = {n}; f[n] = 1; for (int i = 0; i < v.size(); i++) { for (int j = 0; j < vg[v[i]].size(); j++) { if (f[vg[v[i]][j]] == 0) {f[vg[v[i]][j]] = 1; v.push_back(vg[v[i]][j]);} } } fill(res, res + n + 1, -1000000000000000000); res[1] = 0; for (int i = 0; i < n - 1; i++) for (int j = 0; j < m; j++) if (res[b[j]] < res[a[j]] + c[j]) res[b[j]] = res[a[j]] + c[j]; for (int j = 0; j < m; j++) if (t[a[j]] && res[b[j]] < res[a[j]] + c[j] && f[b[j]]) {cout << "inf"; return 0;} cout << res[n]; }
a.cc:10:1: error: 'vector' does not name a type 10 | vector<int> g[50000], vg[50000]; | ^~~~~~ a.cc: In function 'int main()': a.cc:16:63: error: 'g' was not declared in this scope 16 | for (int i = 0; i < m; i++) {cin >> a[i] >> b[i] >> c[i]; g[a[i]].push_back(b[i]); vg[b[i]].push_back(a[i]);} | ^ a.cc:16:88: error: 'vg' was not declared in this scope 16 | for (int i = 0; i < m; i++) {cin >> a[i] >> b[i] >> c[i]; g[a[i]].push_back(b[i]); vg[b[i]].push_back(a[i]);} | ^~ a.cc:17:5: error: 'vector' was not declared in this scope 17 | vector<int> v(1); t[1] = 1; | ^~~~~~ a.cc:4:1: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>' 3 | #include <set> +++ |+#include <vector> 4 | a.cc:17:12: error: expected primary-expression before 'int' 17 | vector<int> v(1); t[1] = 1; | ^~~ a.cc:18:25: error: 'v' was not declared in this scope 18 | for (int i = 0; i < v.size(); i++) | ^ a.cc:20:29: error: 'g' was not declared in this scope 20 | for (int j = 0; j < g[v[i]].size(); j++) | ^ a.cc:25:5: error: 'v' was not declared in this scope 25 | v = {n}; f[n] = 1; | ^ a.cc:28:29: error: 'vg' was not declared in this scope 28 | for (int j = 0; j < vg[v[i]].size(); j++) | ^~
s418810091
p03722
C++
#include <iostream> #include <algorithm> #include <set> using namespace std; int n, m; long long res[50000]; long long a[50000], b[50000], c[50000]; vector<int> g[50000], vg[50000]; int t[50000], f[50000]; int main() { cin >> n >> m; for (int i = 0; i < m; i++) {cin >> a[i] >> b[i] >> c[i]; g[a[i]].push_back(b[i]); vg[b[i]].push_back(a[i]);} vector<int> v(1); t[1] = 1; for (int i = 0; i < v.size(); i++) { for (int j = 0; j < g[v[i]].size(); j++) { if (t[g[v[i]][j]] == 0) {t[g[v[i]][j]] = 1; v.push_back(g[v[i]][j]);} } } v = {n}; f[n] = 1; for (int i = 0; i < v.size(); i++) { for (int j = 0; j < vg[v[i]].size(); j++) { if (f[vg[v[i]][j]] == 0) {f[vg[v[i]][j]] = 1; v.push_back(vg[v[i]][j]);} } } fill(res, res + n + 1, -1000000000000000000); res[1] = 0; for (int i = 0; i < n - 1; i++) for (int j = 0; j < m; j++) if (t[a[j]] && res[b[j]] < res[a[j]] + c[j] && f[b[j]]) res[b[j]] = res[a[j]] + c[j]; for (int j = 0; j < m; j++) if (res[b[j]] < res[a[j]] + c[j]) {cout << "inf"; return 0;} cout << res[n]; }
a.cc:10:1: error: 'vector' does not name a type 10 | vector<int> g[50000], vg[50000]; | ^~~~~~ a.cc: In function 'int main()': a.cc:16:63: error: 'g' was not declared in this scope 16 | for (int i = 0; i < m; i++) {cin >> a[i] >> b[i] >> c[i]; g[a[i]].push_back(b[i]); vg[b[i]].push_back(a[i]);} | ^ a.cc:16:88: error: 'vg' was not declared in this scope 16 | for (int i = 0; i < m; i++) {cin >> a[i] >> b[i] >> c[i]; g[a[i]].push_back(b[i]); vg[b[i]].push_back(a[i]);} | ^~ a.cc:17:5: error: 'vector' was not declared in this scope 17 | vector<int> v(1); t[1] = 1; | ^~~~~~ a.cc:4:1: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>' 3 | #include <set> +++ |+#include <vector> 4 | a.cc:17:12: error: expected primary-expression before 'int' 17 | vector<int> v(1); t[1] = 1; | ^~~ a.cc:18:25: error: 'v' was not declared in this scope 18 | for (int i = 0; i < v.size(); i++) | ^ a.cc:20:29: error: 'g' was not declared in this scope 20 | for (int j = 0; j < g[v[i]].size(); j++) | ^ a.cc:25:5: error: 'v' was not declared in this scope 25 | v = {n}; f[n] = 1; | ^ a.cc:28:29: error: 'vg' was not declared in this scope 28 | for (int j = 0; j < vg[v[i]].size(); j++) | ^~
s597258342
p03722
C++
#include<iostream> #include<stdio.h> #include<vector> #include<algorithm> #include<set> #include<string> #include<map> #include<string.h> #include<complex> #include<math.h> #include<queue> #include<time.h> using namespace std; typedef long long int llint; typedef pair<int, int> pint; typedef vector<bool> vbool; typedef vector<int> vint; typedef vector<vint> vvint; typedef vector<llint> vllint; typedef vector<vllint> vvllint; typedef vector<pair<int, int>> vpint; typedef vector<pair<llint, llint>> vpllint; #define rep(i,n) for(int i=0;i<n;i++) #define drep(i,n) for(int i=n-1;0<=i;i--) #define yes(ans) if(ans)cout<<"yes"<<endl;else cout<<"no"<<endl; #define Yes(ans) if(ans)cout<<"Yes"<<endl;else cout<<"No"<<endl; #define YES(ans) if(ans)cout<<"YES"<<endl;else cout<<"NO"<<endl; #define POSSIBLE(ans) if(ans)cout<<"POSSIBLE"<<endl;else cout<<"IMPOSSIBLE"<<endl; #define Pi 3.1415926535897932384626 #define coutans rep(i, ans.size())cout << ans[i] << endl; #define mod (llint)1000000007 class UnionFind { public: //親の番号を格納する。親だった場合は-(その集合のサイズ) vector<int> Parent; //作るときはParentの値を全て-1にする //こうすると全てバラバラになる UnionFind(int N) { Parent = vector<int>(N, -1); } //Aがどのグループに属しているか調べる int root(int A) { if (Parent[A] < 0) return A; return Parent[A] = root(Parent[A]); } //自分のいるグループの頂点数を調べる int size(int A) { return -Parent[root(A)];//親をとってきたい } //AとBをくっ付ける bool connect(int A, int B) { //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける A = root(A); B = root(B); if (A == B) { //すでにくっついてるからくっ付けない return false; } //大きい方(A)に小さいほう(B)をくっ付けたい //大小が逆だったらひっくり返しちゃう。 if (size(A) < size(B)) swap(A, B); //Aのサイズを更新する Parent[A] += Parent[B]; //Bの親をAに変更する Parent[B] = A; return true; } }; //aとbの最大公約数を求めるよ long long GCD(long long a, long long b) { if (b == 0) return a; else return GCD(b, a % b); } // 返り値: a と b の最大公約数 // ax + by = gcd(a, b) を満たす (x, y) が格納される long long extGCD(long long a, long long b, long long& x, long long& y) { if (b == 0) { x = 1; y = 0; return a; } long long d = extGCD(b, a % b, y, x); y -= a / b * x; return d; } bool check(llint a, llint b) { return a > b; } // mod. m での a の逆元 a^{-1} を計算する long long modinv(long long a, long long m) { long long b = m, u = 1, v = 0; while (b) { long long t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= m; if (u < 0) u += m; return u; } //aのb乗を求める(1000000007で割った余りやで) llint modpow(llint a, llint b) { if (b == 0)return 1; if (b == 1)return a; llint tmp = modpow(a, b / 2); tmp %= mod; tmp = tmp * tmp % mod; if (b % 2)return tmp * a % mod; else return tmp; } //aCbを1000000007で割った余りを求める llint convination(llint a, llint b) { llint ans = 1; for (llint i = 0; i < b; i++) { ans *= a - i; ans %= mod; } for (llint i = 1; i <= b; i++) { ans *= modinv(i, mod); ans %= mod; } return ans; } int main() { int n, m; cin >> n >> m; vector<vector<pair<int, llint>>>nodes(n); vllint costs(n, LLONG_MAX); costs[0] = 0; rep(i, m) { int a, b, c; cin >> a >> b >> c; nodes[a - 1].push_back({ b - 1, c }); } rep(i, n - 1) { rep(j, n) { if (costs[j] == LLONG_MAX)continue; for (auto k : nodes[j]) { if (costs[k.first] == LLONG_MAX) { costs[k.first] = costs[j] + k.second; } else { costs[k.first] = max(costs[j] + k.second, costs[k.first]); } } } } llint ans = costs[n - 1]; rep(j, n) { if (costs[j] == LLONG_MAX)continue; for (auto k : nodes[j]) { if (costs[k.first] == LLONG_MAX) { costs[k.first] = costs[j] + k.second; } else { costs[k.first] = max(costs[j] + k.second, costs[k.first]); } } } if (ans != costs[n - 1]) { cout << "inf" << endl; } else { cout << ans << endl; } return 0; }
a.cc: In function 'int main()': a.cc:144:25: error: 'LLONG_MAX' was not declared in this scope 144 | vllint costs(n, LLONG_MAX); | ^~~~~~~~~ a.cc:12:1: note: 'LLONG_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>' 11 | #include<queue> +++ |+#include <climits> 12 | #include<time.h>
s876963617
p03722
C++
//#pragma GCC optimize("Ofast") #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace std::chrono; #define int long long #define ll long long auto start_time = system_clock::now(); //@formatter:off #ifdef _DEBUG //区間削除は出来ない template<class T> struct my_pbds_tree { set<T> s; auto begin() { return s.begin(); } auto end() { return s.end(); } auto rbegin() { return s.rbegin(); } auto rend() { return s.rend(); } auto empty() { return s.empty(); } auto size() { return s.size(); } void clear() { s.clear(); } template<class U> void insert(U v) { s.insert(v); }template<class U> void operator+=(U v) { insert(v); } template<class F> auto erase(F v) { return s.erase(v); } template<class U> auto find(U v) { return s.find(v); } template<class U> auto lower_bound(U v) { return s.lower_bound(v); } template<class U> auto upper_bound(U v) { return s.upper_bound(v); } auto find_by_order(ll k) { auto it = s.begin(); for (ll i = 0; i < k; i++)it++; return it; } auto order_of_key(ll v) { auto it = s.begin(); ll i=0; for (;it != s.end() && *it <v ; i++)it++; return i; }}; #define pbds(T) my_pbds_tree<T> #else #define unordered_map __gnu_pbds::gp_hash_table //find_by_order(k) k番目のイテレーター //order_of_key(k) k以上が前から何番目か #define pbds(U) __gnu_pbds::tree<U, __gnu_pbds::null_type, less<U>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update> #endif struct xorshift { static uint64_t splitmix64(uint64_t x) { x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } size_t operator()(uint64_t x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM); } size_t operator()(std::pair<ll, ll> x) const { ll v=((x.first) << 32) | x.second; static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(v + FIXED_RANDOM); }}; template<class U, class L> void operator+=(__gnu_pbds::tree<U, __gnu_pbds::null_type, less<U>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update> &s, L v) { s.insert(v); } //衝突対策 #define ws wszzzz template<class A, class B, class C>struct T2 {A f;B s;C t;T2() { f = 0, s = 0, t = 0; }T2(A f, B s, C t) : f(f), s(s), t(t) {}bool operator<(const T2 &r) const { return f != r.f ? f < r.f : s != r.s ? s < r.s : t < r.t; /*return f != r.f ? f > r.f : s != r.s ?n s > r.s : t > r.t; 大きい順 */ } bool operator>(const T2 &r) const { return f != r.f ? f > r.f : s != r.s ? s > r.s : t > r.t; /*return f != r.f ? f > r.f : s != r.s ? s > r.s : t > r.t; 小さい順 */ } bool operator==(const T2 &r) const { return f == r.f && s == r.s && t == r.t; } bool operator!=(const T2 &r) const { return f != r.f || s != r.s || t != r.t; }}; template<class A, class B, class C, class D> struct F2 { A a; B b; C c; D d; F2() { a = 0, b = 0, c = 0, d = 0; } F2(A a, B b, C c, D d) : a(a), b(b), c(c), d(d) {} bool operator<(const F2 &r) const { return a != r.a ? a < r.a : b != r.b ? b < r.b : c != r.c ? c < r.c : d < r.d; /* return a != r.a ? a > r.a : b != r.b ? b > r.b : c != r.c ? c > r.c : d > r.d;*/ } bool operator>(const F2 &r) const { return a != r.a ? a > r.a : b != r.b ? b > r.b : c != r.c ? c > r.c : d > r.d;/* return a != r.a ? a < r.a : b != r.b ? b < r.b : c != r.c ? c < r.c : d < r.d;*/ } bool operator==(const F2 &r) const { return a == r.a && b == r.b && c == r.c && d == r.d; } bool operator!=(const F2 &r) const { return a != r.a || b != r.b || c != r.c || d != r.d; } ll operator[](ll i) { assert(i < 4); return i == 0 ? a : i == 1 ? b : i == 2 ? c : d; }}; typedef T2<ll, ll, ll> T; typedef F2<ll, ll, ll, ll> F; T mt(ll a, ll b, ll c) {return T(a, b, c);} //@マクロ省略系 型,構造 #define double long double #define ull unsigned long long using dou = double; using itn = int; using str = string; using bo= bool; #define au auto using P = pair<ll, ll>; using pd =pair<dou, dou>; #define fi first #define se second #define beg begin #define rbeg rbegin #define con continue #define bre break #define brk break #define is == #define el else #define elf else if #define wh while #define upd update #define maxq 1 #define minq -1 #define ZERO(a) memset(a,0,sizeof(a)) #define MINUS(a) memset(a,0xff,sizeof(a)) #define MALLOC(type, len) (type*)malloc((len) * sizeof(type)) #define lam(right) [&](ll& p){return p right;} //マクロ省略系 コンテナ using vi = vector<ll>; using vb = vector<bool>; using vs = vector<string>; using vd = vector<double>; using vc = vector<char>; using vp = vector<P>; using vt = vector<T>; #define V vector #define o_vvt(o1, o2, o3, o4, name, ...) name #define vvt0(t) V<V<t>> #define vvt1(t,a) V<V<t>>a #define vvt2(t,a, b) V<V<t>>a(b) #define vvt3(t,a, b, c) V<V<t>> a(b,V<t>(c)) #define vvt4(t,a, b, c, d) V<V<t>> a(b,V<t>(c,d)) #define vvi(...) o_vvt(__VA_ARGS__,vvt4,vvt3,vvt2 ,vvt1,vvt0)(ll,__VA_ARGS__) #define vvb(...) o_vvt(__VA_ARGS__,vvt4,vvt3,vvt2 ,vvt1,vvt0)(bool,__VA_ARGS__) #define vvs(...) o_vvt(__VA_ARGS__,vvt4,vvt3,vvt2 ,vvt1,vvt0)(string,__VA_ARGS__) #define vvd(...) o_vvt(__VA_ARGS__,vvt4,vvt3,vvt2 ,vvt1,vvt0)(double,__VA_ARGS__) #define vvc(...) o_vvt(__VA_ARGS__,vvt4,vvt3,vvt2 ,vvt1,vvt0)(char,__VA_ARGS__) #define vvp(...) o_vvt(__VA_ARGS__,vvt4,vvt3,vvt2 ,vvt1,vvt0)(P,__VA_ARGS__) #define vvt(...) o_vvt(__VA_ARGS__,vvt4,vvt3,vvt2 ,vvt1,vvt0)(T,__VA_ARGS__) template<typename T> vector<T> make_v(size_t a) { return vector<T>(a); } template<typename T, typename... Ts> auto make_v(size_t a, Ts... ts) {return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));} #define vni(name, ...) auto name = make_v<ll>(__VA_ARGS__) #define vnb(name, ...) auto name = make_v<bool>(__VA_ARGS__) #define vns(name, ...) auto name = make_v<string>(__VA_ARGS__) #define vnd(name, ...) auto name = make_v<double>(__VA_ARGS__) #define vnc(name, ...) auto name = make_v<char>(__VA_ARGS__) #define vnp(name, ...) auto name = make_v<P>(__VA_ARGS__) #define PQ priority_queue<ll, vector<ll>, greater<ll> > #define tos to_string using mapi = map<ll, ll>; using mapp = map<P, ll>; using mapd = map<dou, ll>; using mapc = map<char, ll>; using maps = map<str, ll>; using seti = set<ll>; using setd = set<dou>; using setc = set<char>; using sets = set<str>; using qui = queue<ll>; #define bset bitset #define uset unordered_set #define useti unordered_set<ll,ll,xorshift> #define mset multiset #define mseti multiset<ll> #define umap unordered_map #define umapi unordered_map<ll,ll,xorshift> #define umapp unordered_map<P,ll,xorshift> #define mmap multimap template<class T> struct pq { priority_queue<T, vector<T>, greater<T> > q;/*小さい順*/ T su = 0; void clear() {q = priority_queue<T, vector<T>, greater<T> >();su = 0;} void operator+=(T v) {su += v;q.push(v);} T sum() {return su;} T top() {return q.top();} void pop() {su -= q.top();q.pop();} T poll() {T ret = q.top();su -= ret;q.pop();return ret;} ll size() {return q.size();}}; template<class T> struct pqg { priority_queue<T> q;/*大きい順*/ T su = 0; void clear() {q = priority_queue<T>();su = 0;} void operator+=(T v) {su += v;q.push(v);} T sum() {return su;} T top() {return q.top();} void pop() {su -= q.top();q.pop();} T poll() {T ret = q.top();su -= ret;q.pop();return ret;} ll size() {return q.size();}}; #define pqi pq<ll> #define pqgi pqg<ll> //マクロ 繰り返し #define o_rep(o1, o2, o3, o4, name, ...) name # define rep1(n) for(ll rep1i = 0,rep1lim=n; rep1i < rep1lim ; ++rep1i) # define rep2(i, n) for(ll i = 0,rep2lim=n; i < rep2lim ; ++i) #define rep3(i, m, n) for(ll i = m,rep3lim=n; i < rep3lim ; ++i) #define rep4(i, m, n, ad) for(ll i = m,rep4lim=n; i < rep4lim ; i+= ad) #define rep(...) o_rep(__VA_ARGS__,rep4,rep3,rep2,rep1)(__VA_ARGS__) #define rer2(i, n) for(ll i = n; i >= 0 ; i--) #define rer3(i, m, n) for(ll i = m,rer3lim=n; i >= rer3lim ; i--) #define rer4(i, m, n, dec) for(ll i = m,rer4lim=n; i >= rer4lim ; i-=dec) #define rer(...) o_rep(__VA_ARGS__,rer4,rer3,rer2,)(__VA_ARGS__) #define reps2(i, j, n) for(ll i = 0,reps2lim=n; i < reps2lim ;++i)for(ll j = 0; j < reps2lim ; ++j) #define reps3(i, j, k, n) for(ll i = 0,reps3lim=n; i < reps3lim ; ++i)for(ll j = 0; j < reps3lim ; ++j)for(ll k = 0; k < reps3lim ; ++k) #define reps4(i, j, k, l, n) for(ll i = 0,reps4lim=n; i < reps4lim ; ++i)for(ll j = 0; j < reps4lim ; ++j)for(ll k = 0; k < reps4lim ; ++k)for(ll l = 0; l < reps4lim ; ++l) #define o_reps(o1, o2, o3, o4, o5, name, ...) name #define reps(...) o_reps(__VA_ARGS__,reps4,reps3,reps2,rep2,)(__VA_ARGS__) #define repss(i, j, k, a, b, c) for(ll i = 0; i < a ; ++i)for(ll j = 0; j < b ; ++j)for(ll k = 0; k < c ; ++k) #define fora(a, b) for(auto&& a : b) #define form(st, l, r) for (auto &&it = st.lower_bound(l); it != st.end() && (*it).fi < r; ++it) #define forit(st, l, r) for (auto &&it = st.lower_bound(l); it != st.end() && (*it) < r;) //マクロ 定数 #define k3 1010 #define k4 10101 #define k5 101010 #define k6 1010101 #define k7 10101010 const ll inf = (ll) 1e9 + 100; const ll linf = (ll) 1e18 + 100; const char infc = '{'; const string infs = "{"; const double eps = 1e-9; const double PI = 3.1415926535897932384626433832795029L; ll ma = numeric_limits<ll>::min(); ll mi = numeric_limits<ll>::max(); //マクロ省略形 関数等 #define arsz(a) (sizeof(a)/sizeof(a[0])) #define sz(a) ((ll)(a).size()) #define mp make_pair #define pb pop_back #define pf push_front #define eb emplace_back #define all(a) (a).begin(),(a).end() #define rall(a) (a).rbegin(),(a).rend() constexpr bool ev(ll a) { return !(a & 1); } constexpr bool od(ll a) { return (a & 1); } //@拡張系 こう出来るべきというもの //埋め込み 存在を意識せずに機能を増やされているもの //@formatter:on namespace std { template<> class hash<std::pair<signed, signed>> { public:size_t operator()(const std::pair<signed, signed> &x) const { return hash<ll>()(((ll) x.first << 32) | x.second); }}; template<> class hash<std::pair<ll, ll>> { public:/*大きいllが渡されると、<<32でオーバーフローするがとりあえず問題ないと判断*/size_t operator()(const std::pair<ll, ll> &x) const { return hash<ll>()(((ll) x.first << 32) | x.second); }}; } //@formatter:off //stream まとめ istream &operator>>(istream &iss, P &a) { iss >> a.first >> a.second; return iss;}template<typename T> istream &operator>>(istream &iss, vector<T> &vec) { for (T &x: vec) iss >> x; return iss;}template<class T, class U> ostream &operator<<(ostream &os, pair<T, U> p) { os << p.fi << " " << p.se << endl; return os;}ostream &operator<<(ostream &os, T p) { os << p.f << " " << p.s << " " << p.t; return os;}ostream &operator<<(ostream &os, F p) { os << p.a << " " << p.b << " " << p.c << " " << p.d; return os;}template<typename T> ostream &operator<<(ostream &os, vector<T> &vec) { for (ll i = 0; i < vec.size(); ++i)os << vec[i] << (i + 1 == vec.size() ? "" : " "); return os;}template<typename T> ostream &operator<<(ostream &os, vector<vector<T>> &vec) { for (ll i = 0; i < vec.size(); ++i) { for (ll j = 0; j < vec[i].size(); ++j) { os << vec[i][j] << " "; } os << endl; } return os;}template<typename T, typename U> ostream &operator<<(ostream &os, map<T, U> &m) { for (auto &&v:m) os << v; return os;}template<class T> ostream &operator<<(ostream &os, set<T>s) {fora(v,s){os<<v<<" ";}return os;}template<class T> ostream &operator<<(ostream &os, deque<T> a) {fora(v,a)os<<v<<" ";return os;} template<typename W, typename H> void resize(vector<W> &vec, const H head) { vec.resize(head); }template<typename W, typename H, typename ... T> void resize(vector<W> &vec, const H &head, const T ... tail) {vec.resize(head);for (auto &v: vec)resize(v, tail...);} template<typename T, typename F> bool all_of2(T &v, F f) { return f(v); } template<typename T, typename F> bool all_of2(vector<T> &v, F f) { rep(i, sz(v)) { if (!all_of2(v[i], f))return false; } return true;} template<typename T, typename F> bool any_of2(T &v, F f) { return f(v); } template<typename T, typename F> bool any_of2(vector<T> &v, F f) { rep(i, sz(v)) { if (any_of2(v[i], f))return true; } return false;} template<typename T, typename F> bool none_of2(T &v, F f) { return f(v); } template<typename T, typename F> bool none_of2(vector<T> &v, F f) { rep(i, sz(v)) { if (none_of2(v[i], f))return false; } return true;} template<typename T, typename F> bool find_if2(T &v, F f) { return f(v); } template<typename T, typename F> ll find_if2(vector<T> &v, F f) { rep(i, sz(v)) { if (find_if2(v[i], f))return i; } return sz(v);} template<typename T, typename F> bool rfind_if2(T &v, F f) { return f(v); } template<typename T, typename F> ll rfind_if2(vector<T> &v, F f) { rer(i, sz(v) - 1) { if (rfind_if2(v[i], f))return i; } return -1;} template<class T> bool contains(string &s, const T &v) { return s.find(v) != string::npos; } template<typename T> bool contains(vector<T> &v, const T &val) { return std::find(v.begin(), v.end(), val) != v.end(); } template<typename T, typename F> bool contains_if2(vector<T> &v, F f) { return find_if(v.begin(), v.end(), f) != v.end(); } template<typename T, typename F> ll count_if2(T &v, F f) { return f(v); } template<typename T, typename F> ll count_if2(vector<T> &vec, F f) { ll ret = 0; fora(v, vec)ret += count_if2(v, f); return ret;} template<typename T, typename F> void for_each2(T &v, F f) { f(v); } template<typename T, typename F> void for_each2(vector<T> &vec, F f) { fora(v, vec)for_each2(v, f); } template<typename W> ll count_od(vector<W> &a) {return count_if2(a,[](ll v){return v&1 ;});} template<typename W> ll count_ev(vector<W> &a) {return count_if2(a,[](ll v){return !(v&1) ;});} #define all_of(a,right) all_of2(a,lam(right)) #define any_of(a,right) any_of2(a,lam(right)) #define none_of(a,right) none_of2(a,lam(right)) #define find_if(a,right) find_if2(a,lam(right)) #define rfind_if(a,right) rfind_if2(a,lam(right)) #define contains_if(a,right) contains_if2(a,lam(right)) #define count_if(a, right) count_if2(a,lam(right)) #define for_each(a, right) do{fora(v,a){v right;}}while(0) template<class T, class U> void replace(vector<T> &a, T key, U v) { replace(a.begin(), a.end(), key, v); } void replace(str &a, char key, str v) { if (v == "")a.erase(remove(all(a), key), a.end()); } void replace(str &a, char key, char v) { replace(all(a), key, v); } //keyと同じかどうか01で置き換える template<class T, class U> void replace(vector<T> &a, U k) { rep(i, sz(a)) a[i] = a[i] == k; } template<class T, class U> void replace(vector<vector<T >> &a, U k) { rep(i, sz(a))rep(j, sz(a[0])) a[i][j] = a[i][j] == k; } template<class T> void replace(T &a) { replace(a, '#'); } void replace(str &a, str key, str v) {stringstream t;ll kn = sz(key);std::string::size_type Pos(a.find(key));ll l = 0;while (Pos != std::string::npos) {t << a.substr(l, Pos - l);t << v;l = Pos + kn;Pos = a.find(key, Pos + kn);}t << a.substr(l, sz(a) - l);a = t.str();} template<class T> bool includes(vector<T> &a, vector<T> &b) {vi c = a;vi d = b;sort(all(c));sort(all(d));return includes(all(c), all(d));} template<class T> bool is_permutation(vector<T> &a, vector<T> &b) { return is_permutation(all(a), all(b)); } template<class T> bool next_permutation(vector<T> &a) { return next_permutation(all(a)); } void iota(vector<ll> &ve, ll s, ll n) {ve.resize(n);iota(all(ve), s);} vi iota(ll s, ll len) {vi ve(len);iota(all(ve), s);return ve;} template<class A, class B> auto vtop(vector<A> &a, vector<B> &b) { assert(sz(a) == sz(b)); /*stringを0で初期化できない */ vector<pair<A, B>> res; rep(i, sz(a))res.eb(a[i], b[i]);return res;} template<class A, class B> void ptov(vector<pair<A, B>> &p, vector<A> &a, vector<B> &b) { a.resize(sz(p)), b.resize(sz(p)); rep(i, sz(p))a[i] = p[i].fi, b[i] = p[i].se;} template<class A, class B, class C> auto vtot(vector<A> &a, vector<B> &b, vector<C> &c) { assert(sz(a) == sz(b) && sz(b) == sz(c)); vector<T2<A, B, C>> res; rep(i, sz(a))res.eb(a[i], b[i], c[i]); return res;} template<class A, class B, class C, class D> auto vtof(vector<A> &a, vector<B> &b, vector<C> &c, vector<D> &d) { assert(sz(a) == sz(b) && sz(b) == sz(c) && sz(c) == sz(d)); vector<F2<A, B, C, D>> res; rep(i, sz(a))res.eb(a[i], b[i], c[i], d[i]); return res;} enum pcomparator { fisi, fisd, fdsi, fdsd, sifi, sifd, sdfi, sdfd }; enum tcomparator { fisiti, fisitd, fisdti, fisdtd, fdsiti, fdsitd, fdsdti, fdsdtd, fitisi, fitisd, fitdsi, fitdsd, fdtisi, fdtisd, fdtdsi, fdtdsd, sifiti, sifitd, sifdti, sifdtd, sdfiti, sdfitd, sdfdti, sdfdtd, sitifi, sitifd, sitdfi, sitdfd, sdtifi, sdtifd, sdtdfi, sdfdfd, tifisi, tifisd, tifdsi, tifdsd, tdfisi, tdfisd, tdfdsi, tdfdsd, tisifi, tisifd, tisdfi, tisdfd, tdsifi, tdsifd, tdsdfi, tdsdfd}; template<class A, class B> void sort(vector<pair<A, B>> &a, pcomparator type) { typedef pair<A, B> U; if (type == fisi) sort(all(a), [&](U l, U r) { return l.fi != r.fi ? l.fi < r.fi : l.se < r.se; }); else if (type == fisd) sort(all(a), [&](U l, U r) { return l.fi != r.fi ? l.fi < r.fi : l.se > r.se; }); else if (type == fdsi) sort(all(a), [&](U l, U r) { return l.fi != r.fi ? l.fi > r.fi : l.se < r.se; }); else if (type == fdsd) sort(all(a), [&](U l, U r) { return l.fi != r.fi ? l.fi > r.fi : l.se > r.se; }); else if (type == sifi) sort(all(a), [&](U l, U r) { return l.se != r.se ? l.se < r.se : l.fi < r.fi; }); else if (type == sifd) sort(all(a), [&](U l, U r) { return l.se != r.se ? l.se < r.se : l.fi > r.fi; }); else if (type == sdfi) sort(all(a), [&](U l, U r) { return l.se != r.se ? l.se > r.se : l.fi < r.fi; }); else if (type == sdfd) sort(all(a), [&](U l, U r) { return l.se != r.se ? l.se > r.se : l.fi > r.fi; });};template<class U> void sort(vector<U> &a, pcomparator type) { if (type == fisi) sort(all(a), [&](U l, U r) { return l.f != r.f ? l.f < r.f : l.s < r.s; }); else if (type == fisd) sort(all(a), [&](U l, U r) { return l.f != r.f ? l.f < r.f : l.s > r.s; }); else if (type == fdsi) sort(all(a), [&](U l, U r) { return l.f != r.f ? l.f > r.f : l.s < r.s; }); else if (type == fdsd) sort(all(a), [&](U l, U r) { return l.f != r.f ? l.f > r.f : l.s > r.s; }); else if (type == sifi) sort(all(a), [&](U l, U r) { return l.s != r.s ? l.s < r.s : l.f < r.f; }); else if (type == sifd) sort(all(a), [&](U l, U r) { return l.s != r.s ? l.s < r.s : l.f > r.f; }); else if (type == sdfi) sort(all(a), [&](U l, U r) { return l.s != r.s ? l.s > r.s : l.f < r.f; }); else if (type == sdfd) sort(all(a), [&](U l, U r) { return l.s != r.s ? l.s > r.s : l.f > r.f; });};template<class A, class B, class C, class D> void sort(vector<F2<A, B, C, D> > &a, pcomparator type) { typedef F2<A, B, C, D> U; if (type == fisi) sort(all(a), [&](U l, U r) { return l.a != r.a ? l.a < r.a : l.b < r.b; }); else if (type == fisd) sort(all(a), [&](U l, U r) { return l.a != r.a ? l.a < r.a : l.b > r.b; }); else if (type == fdsi) sort(all(a), [&](U l, U r) { return l.a != r.a ? l.a > r.a : l.b < r.b; }); else if (type == fdsd) sort(all(a), [&](U l, U r) { return l.a != r.a ? l.a > r.a : l.b > r.b; }); else if (type == sifi) sort(all(a), [&](U l, U r) { return l.b != r.b ? l.b < r.b : l.a < r.a; }); else if (type == sifd) sort(all(a), [&](U l, U r) { return l.b != r.b ? l.b < r.b : l.a > r.a; }); else if (type == sdfi) sort(all(a), [&](U l, U r) { return l.b != r.b ? l.b > r.b : l.a < r.a; }); else if (type == sdfd) sort(all(a), [&](U l, U r) { return l.b != r.b ? l.b > r.b : l.a > r.a; });};template<class U> void sort(vector<U> &a, tcomparator type) { if (type == 0) sort(all(a), [&](U l, U r) { return l.f != r.f ? l.f < r.f : l.s != r.s ? l.s < r.s : l.t < r.t; }); else if (type == 1) sort(all(a), [&](U l, U r) { return l.f != r.f ? l.f < r.f : l.s != r.s ? l.s < r.s : l.t > r.t; }); else if (type == 2) sort(all(a), [&](U l, U r) { return l.f != r.f ? l.f < r.f : l.s != r.s ? l.s > r.s : l.t < r.t; }); else if (type == 3) sort(all(a), [&](U l, U r) { return l.f != r.f ? l.f < r.f : l.s != r.s ? l.s > r.s : l.t > r.t; }); else if (type == 4) sort(all(a), [&](U l, U r) { return l.f != r.f ? l.f > r.f : l.s != r.s ? l.s < r.s : l.t < r.t; }); else if (type == 5) sort(all(a), [&](U l, U r) { return l.f != r.f ? l.f > r.f : l.s != r.s ? l.s < r.s : l.t > r.t; }); else if (type == 6) sort(all(a), [&](U l, U r) { return l.f != r.f ? l.f > r.f : l.s != r.s ? l.s > r.s : l.t < r.t; }); else if (type == 7) sort(all(a), [&](U l, U r) { return l.f != r.f ? l.f > r.f : l.s != r.s ? l.s > r.s : l.t > r.t; }); else if (type == 8) sort(all(a), [&](U l, U r) { return l.f != r.f ? l.f < r.f : l.t != r.t ? l.t < r.t : l.s < r.s; }); else if (type == 9) sort(all(a), [&](U l, U r) { return l.f != r.f ? l.f < r.f : l.t != r.t ? l.t < r.t : l.s > r.s; }); else if (type == 10) sort(all(a), [&](U l, U r) { return l.f != r.f ? l.f < r.f : l.t != r.t ? l.t > r.t : l.s < r.s; }); else if (type == 11) sort(all(a), [&](U l, U r) { return l.f != r.f ? l.f < r.f : l.t != r.t ? l.t > r.t : l.s > r.s; }); else if (type == 12) sort(all(a), [&](U l, U r) { return l.f != r.f ? l.f > r.f : l.t != r.t ? l.t < r.t : l.s < r.s; }); else if (type == 13) sort(all(a), [&](U l, U r) { return l.f != r.f ? l.f > r.f : l.t != r.t ? l.t < r.t : l.s > r.s; }); else if (type == 14) sort(all(a), [&](U l, U r) { return l.f != r.f ? l.f > r.f : l.t != r.t ? l.t > r.t : l.s < r.s; }); else if (type == 15) sort(all(a), [&](U l, U r) { return l.f != r.f ? l.f > r.f : l.t != r.t ? l.t > r.t : l.s > r.s; }); else if (type == 16) sort(all(a), [&](U l, U r) { return l.s != r.s ? l.s < r.s : l.f != r.f ? l.f < r.f : l.t < r.t; }); else if (type == 17) sort(all(a), [&](U l, U r) { return l.s != r.s ? l.s < r.s : l.f != r.f ? l.f < r.f : l.t > r.t; }); else if (type == 18) sort(all(a), [&](U l, U r) { return l.s != r.s ? l.s < r.s : l.f != r.f ? l.f > r.f : l.t < r.t; }); else if (type == 19) sort(all(a), [&](U l, U r) { return l.s != r.s ? l.s < r.s : l.f != r.f ? l.f > r.f : l.t > r.t; }); else if (type == 20) sort(all(a), [&](U l, U r) { return l.s != r.s ? l.s > r.s : l.f != r.f ? l.f < r.f : l.t < r.t; }); else if (type == 21) sort(all(a), [&](U l, U r) { return l.s != r.s ? l.s > r.s : l.f != r.f ? l.f < r.f : l.t > r.t; }); else if (type == 22) sort(all(a), [&](U l, U r) { return l.s != r.s ? l.s > r.s : l.f != r.f ? l.f > r.f : l.t < r.t; }); else if (type == 23) sort(all(a), [&](U l, U r) { return l.s != r.s ? l.s > r.s : l.f != r.f ? l.f > r.f : l.t > r.t; }); else if (type == 24) sort(all(a), [&](U l, U r) { return l.s != r.s ? l.s < r.s : l.t != r.t ? l.t < r.t : l.f < r.f; }); else if (type == 25) sort(all(a), [&](U l, U r) { return l.s != r.s ? l.s < r.s : l.t != r.t ? l.t < r.t : l.f > r.f; }); else if (type == 26) sort(all(a), [&](U l, U r) { return l.s != r.s ? l.s < r.s : l.t != r.t ? l.t > r.t : l.f < r.f; }); else if (type == 27) sort(all(a), [&](U l, U r) { return l.s != r.s ? l.s < r.s : l.t != r.t ? l.t > r.t : l.f > r.f; }); else if (type == 28) sort(all(a), [&](U l, U r) { return l.s != r.s ? l.s > r.s : l.t != r.t ? l.t < r.t : l.f < r.f; }); else if (type == 29) sort(all(a), [&](U l, U r) { return l.s != r.s ? l.s > r.s : l.t != r.t ? l.t < r.t : l.f > r.f; }); else if (type == 30) sort(all(a), [&](U l, U r) { return l.s != r.s ? l.s > r.s : l.t != r.t ? l.t > r.t : l.f < r.f; }); else if (type == 31) sort(all(a), [&](U l, U r) { return l.s != r.s ? l.s > r.s : l.t != r.t ? l.t > r.t : l.f > r.f; }); else if (type == 32) sort(all(a), [&](U l, U r) { return l.t != r.t ? l.t < r.t : l.f != r.f ? l.f < r.f : l.s < r.s; }); else if (type == 33) sort(all(a), [&](U l, U r) { return l.t != r.t ? l.t < r.t : l.f != r.f ? l.f < r.f : l.s > r.s; }); else if (type == 34) sort(all(a), [&](U l, U r) { return l.t != r.t ? l.t < r.t : l.f != r.f ? l.f > r.f : l.s < r.s; }); else if (type == 35) sort(all(a), [&](U l, U r) { return l.t != r.t ? l.t < r.t : l.f != r.f ? l.f > r.f : l.s > r.s; }); else if (type == 36) sort(all(a), [&](U l, U r) { return l.t != r.t ? l.t > r.t : l.f != r.f ? l.f < r.f : l.s < r.s; }); else if (type == 37) sort(all(a), [&](U l, U r) { return l.t != r.t ? l.t > r.t : l.f != r.f ? l.f < r.f : l.s > r.s; }); else if (type == 38) sort(all(a), [&](U l, U r) { return l.t != r.t ? l.t > r.t : l.f != r.f ? l.f > r.f : l.s < r.s; }); else if (type == 39) sort(all(a), [&](U l, U r) { return l.t != r.t ? l.t > r.t : l.f != r.f ? l.f > r.f : l.s > r.s; }); else if (type == 40) sort(all(a), [&](U l, U r) { return l.t != r.t ? l.t < r.t : l.s != r.s ? l.s < r.s : l.f < r.f; }); else if (type == 41) sort(all(a), [&](U l, U r) { return l.t != r.t ? l.t < r.t : l.s != r.s ? l.s < r.s : l.f > r.f; }); else if (type == 42) sort(all(a), [&](U l, U r) { return l.t != r.t ? l.t < r.t : l.s != r.s ? l.s > r.s : l.f < r.f; }); else if (type == 43) sort(all(a), [&](U l, U r) { return l.t != r.t ? l.t < r.t : l.s != r.s ? l.s > r.s : l.f > r.f; }); else if (type == 44) sort(all(a), [&](U l, U r) { return l.t != r.t ? l.t > r.t : l.s != r.s ? l.s < r.s : l.f < r.f; }); else if (type == 45) sort(all(a), [&](U l, U r) { return l.t != r.t ? l.t > r.t : l.s != r.s ? l.s < r.s : l.f > r.f; }); else if (type == 46) sort(all(a), [&](U l, U r) { return l.t != r.t ? l.t > r.t : l.s != r.s ? l.s > r.s : l.f < r.f; }); else if (type == 47) sort(all(a), [&](U l, U r) { return l.t != r.t ? l.t > r.t : l.s != r.s ? l.s > r.s : l.f > r.f; });}template<class A, class B, class C, class D> void sort(vector<F2<A, B, C, D>> &a, tcomparator type) { typedef F2<A, B, C, D> U; if (type == 0) sort(all(a), [&](U l, U r) { return l.a != r.a ? l.a < r.a : l.b != r.b ? l.b < r.b : l.c < r.c; }); else if (type == 1) sort(all(a), [&](U l, U r) { return l.a != r.a ? l.a < r.a : l.b != r.b ? l.b < r.b : l.c > r.c; }); else if (type == 2) sort(all(a), [&](U l, U r) { return l.a != r.a ? l.a < r.a : l.b != r.b ? l.b > r.b : l.c < r.c; }); else if (type == 3) sort(all(a), [&](U l, U r) { return l.a != r.a ? l.a < r.a : l.b != r.b ? l.b > r.b : l.c > r.c; }); else if (type == 4) sort(all(a), [&](U l, U r) { return l.a != r.a ? l.a > r.a : l.b != r.b ? l.b < r.b : l.c < r.c; }); else if (type == 5) sort(all(a), [&](U l, U r) { return l.a != r.a ? l.a > r.a : l.b != r.b ? l.b < r.b : l.c > r.c; }); else if (type == 6) sort(all(a), [&](U l, U r) { return l.a != r.a ? l.a > r.a : l.b != r.b ? l.b > r.b : l.c < r.c; }); else if (type == 7) sort(all(a), [&](U l, U r) { return l.a != r.a ? l.a > r.a : l.b != r.b ? l.b > r.b : l.c > r.c; }); else if (type == 8) sort(all(a), [&](U l, U r) { return l.a != r.a ? l.a < r.a : l.c != r.c ? l.c < r.c : l.b < r.b; }); else if (type == 9) sort(all(a), [&](U l, U r) { return l.a != r.a ? l.a < r.a : l.c != r.c ? l.c < r.c : l.b > r.b; }); else if (type == 10) sort(all(a), [&](U l, U r) { return l.a != r.a ? l.a < r.a : l.c != r.c ? l.c > r.c : l.b < r.b; }); else if (type == 11) sort(all(a), [&](U l, U r) { return l.a != r.a ? l.a < r.a : l.c != r.c ? l.c > r.c : l.b > r.b; }); else if (type == 12) sort(all(a), [&](U l, U r) { return l.a != r.a ? l.a > r.a : l.c != r.c ? l.c < r.c : l.b < r.b; }); else if (type == 13) sort(all(a), [&](U l, U r) { return l.a != r.a ? l.a > r.a : l.c != r.c ? l.c < r.c : l.b > r.b; }); else if (type == 14) sort(all(a), [&](U l, U r) { return l.a != r.a ? l.a > r.a : l.c != r.c ? l.c > r.c : l.b < r.b; }); else if (type == 15) sort(all(a), [&](U l, U r) { return l.a != r.a ? l.a > r.a : l.c != r.c ? l.c > r.c : l.b > r.b; }); else if (type == 16) sort(all(a), [&](U l, U r) { return l.b != r.b ? l.b < r.b : l.a != r.a ? l.a < r.a : l.c < r.c; }); else if (type == 17) sort(all(a), [&](U l, U r) { return l.b != r.b ? l.b < r.b : l.a != r.a ? l.a < r.a : l.c > r.c; }); else if (type == 18) sort(all(a), [&](U l, U r) { return l.b != r.b ? l.b < r.b : l.a != r.a ? l.a > r.a : l.c < r.c; }); else if (type == 19) sort(all(a), [&](U l, U r) { return l.b != r.b ? l.b < r.b : l.a != r.a ? l.a > r.a : l.c > r.c; }); else if (type == 20) sort(all(a), [&](U l, U r) { return l.b != r.b ? l.b > r.b : l.a != r.a ? l.a < r.a : l.c < r.c; }); else if (type == 21) sort(all(a), [&](U l, U r) { return l.b != r.b ? l.b > r.b : l.a != r.a ? l.a < r.a : l.c > r.c; }); else if (type == 22) sort(all(a), [&](U l, U r) { return l.b != r.b ? l.b > r.b : l.a != r.a ? l.a > r.a : l.c < r.c; }); else if (type == 23) sort(all(a), [&](U l, U r) { return l.b != r.b ? l.b > r.b : l.a != r.a ? l.a > r.a : l.c > r.c; }); else if (type == 24) sort(all(a), [&](U l, U r) { return l.b != r.b ? l.b < r.b : l.c != r.c ? l.c < r.c : l.a < r.a; }); else if (type == 25) sort(all(a), [&](U l, U r) { return l.b != r.b ? l.b < r.b : l.c != r.c ? l.c < r.c : l.a > r.a; }); else if (type == 26) sort(all(a), [&](U l, U r) { return l.b != r.b ? l.b < r.b : l.c != r.c ? l.c > r.c : l.a < r.a; }); else if (type == 27) sort(all(a), [&](U l, U r) { return l.b != r.b ? l.b < r.b : l.c != r.c ? l.c > r.c : l.a > r.a; }); else if (type == 28) sort(all(a), [&](U l, U r) { return l.b != r.b ? l.b > r.b : l.c != r.c ? l.c < r.c : l.a < r.a; }); else if (type == 29) sort(all(a), [&](U l, U r) { return l.b != r.b ? l.b > r.b : l.c != r.c ? l.c < r.c : l.a > r.a; }); else if (type == 30) sort(all(a), [&](U l, U r) { return l.b != r.b ? l.b > r.b : l.c != r.c ? l.c > r.c : l.a < r.a; }); else if (type == 31) sort(all(a), [&](U l, U r) { return l.b != r.b ? l.b > r.b : l.c != r.c ? l.c > r.c : l.a > r.a; }); else if (type == 32) sort(all(a), [&](U l, U r) { return l.c != r.c ? l.c < r.c : l.a != r.a ? l.a < r.a : l.b < r.b; }); else if (type == 33) sort(all(a), [&](U l, U r) { return l.c != r.c ? l.c < r.c : l.a != r.a ? l.a < r.a : l.b > r.b; }); else if (type == 34) sort(all(a), [&](U l, U r) { return l.c != r.c ? l.c < r.c : l.a != r.a ? l.a > r.a : l.b < r.b; }); else if (type == 35) sort(all(a), [&](U l, U r) { return l.c != r.c ? l.c < r.c : l.a != r.a ? l.a > r.a : l.b > r.b; }); else if (type == 36) sort(all(a), [&](U l, U r) { return l.c != r.c ? l.c > r.c : l.a != r.a ? l.a < r.a : l.b < r.b; }); else if (type == 37) sort(all(a), [&](U l, U r) { return l.c != r.c ? l.c > r.c : l.a != r.a ? l.a < r.a : l.b > r.b; }); else if (type == 38) sort(all(a), [&](U l, U r) { return l.c != r.c ? l.c > r.c : l.a != r.a ? l.a > r.a : l.b < r.b; }); else if (type == 39) sort(all(a), [&](U l, U r) { return l.c != r.c ? l.c > r.c : l.a != r.a ? l.a > r.a : l.b > r.b; }); else if (type == 40) sort(all(a), [&](U l, U r) { return l.c != r.c ? l.c < r.c : l.b != r.b ? l.b < r.b : l.a < r.a; }); else if (type == 41) sort(all(a), [&](U l, U r) { return l.c != r.c ? l.c < r.c : l.b != r.b ? l.b < r.b : l.a > r.a; }); else if (type == 42) sort(all(a), [&](U l, U r) { return l.c != r.c ? l.c < r.c : l.b != r.b ? l.b > r.b : l.a < r.a; }); else if (type == 43) sort(all(a), [&](U l, U r) { return l.c != r.c ? l.c < r.c : l.b != r.b ? l.b > r.b : l.a > r.a; }); else if (type == 44) sort(all(a), [&](U l, U r) { return l.c != r.c ? l.c > r.c : l.b != r.b ? l.b < r.b : l.a < r.a; }); else if (type == 45) sort(all(a), [&](U l, U r) { return l.c != r.c ? l.c > r.c : l.b != r.b ? l.b < r.b : l.a > r.a; }); else if (type == 46) sort(all(a), [&](U l, U r) { return l.c != r.c ? l.c > r.c : l.b != r.b ? l.b > r.b : l.a < r.a; }); else if (type == 47) sort(all(a), [&](U l, U r) { return l.c != r.c ? l.c > r.c : l.b != r.b ? l.b > r.b : l.a > r.a; });} void sort(string &a) { sort(all(a)); } template<class T> void sort(vector<T> &a) { sort(all(a)); } //P l, P rで f(P) の形で渡す template<class U, class F> void sort(vector<U> &a, F f) { sort(all(a), [&](U l, U r) { return f(l) < f(r); }); }; template<class T> void rsort(vector<T> &a) { sort(all(a), greater<T>()); }; template<class U, class F> void rsort(vector<U> &a, F f) { sort(all(a), [&](U l, U r) { return f(l) > f(r); }); }; //F = T<T> //例えばreturn p.fi + p.se; template<class A, class B> void sortp(vector<A> &a, vector<B> &b) { auto c = vtop(a, b); sort(c); rep(i, sz(a)) a[i] = c[i].fi, b[i] = c[i].se;}template<class A, class B, class F> void sortp(vector<A> &a, vector<B> &b, F f) { auto c = vtop(a, b); sort(c, f); rep(i, sz(a)) a[i] = c[i].fi, b[i] = c[i].se;}template<class A, class B> void rsortp(vector<A> &a, vector<B> &b) { auto c = vtop(a, b); rsort(c); rep(i, sz(a))a[i] = c[i].first, b[i] = c[i].second;}template<class A, class B, class F> void rsortp(vector<A> &a, vector<B> &b, F f) { auto c = vtop(a, b); rsort(c, f); rep(i, sz(a))a[i] = c[i].first, b[i] = c[i].second;} template<class A, class B, class C> void sortt(vector<A> &a, vector<B> &b, vector<C> &c) { auto d = vtot(a, b, c); sort(d); rep(i, sz(a)) a[i] = d[i].f, b[i] = d[i].s, c[i] = d[i].t;} template<class A, class B, class C, class F> void sortt(vector<A> &a, vector<B> &b, vector<C> &c, F f) { auto d = vtot(a, b, c); sort(d, f); rep(i, sz(a)) a[i] = d[i].f, b[i] = d[i].s, c[i] = d[i].t;} template<class A, class B, class C> void rsortt(vector<A> &a, vector<B> &b, vector<C> &c) { auto d = vtot(a, b, c); rsort(d); rep(i, sz(a)) a[i] = d[i].f, b[i] = d[i].s, c[i] = d[i].t;} template<class A, class B, class C, class F> void rsortt(vector<A> &a, vector<B> &b, vector<C> &c, F f) { auto d = vtot(a, b, c); rsort(d, f); rep(i, sz(a)) a[i] = d[i].f, b[i] = d[i].s, c[i] = d[i].t;} template<class A, class B, class C, class D> void sortf(vector<A> &a, vector<B> &b, vector<C> &c, vector<D> &d) { auto e = vtof(a, b, c, d); sort(e); rep(i, sz(a)) a[i] = e[i].a, b[i] = e[i].b, c[i] = e[i].c, d[i] = e[i].d;} template<class A, class B, class C, class D> void rsortf(vector<A> &a, vector<B> &b, vector<C> &c, vector<D> &d) { auto e = vtof(a, b, c, d); rsort(e); rep(i, sz(a)) a[i] = e[i].a, b[i] = e[i].b, c[i] = e[i].c, d[i] = e[i].d;} //sortindex 元のvectorはソートしない template<class T> vi sorti(vector<T> &a) { auto b = a; vi ind = iota(0, sz(a)); sortp(b, ind); return ind;}/*indexの分で型が変わるためpcomparatorが必要*/template<class T> vi sorti(vector<T> &a, pcomparator f) { auto b = a; vi ind = iota(0, sz(a)); sortp(b, ind, f); return ind;}template<class T, class F> vi sorti(vector<T> &a, F f) { vi ind = iota(0, sz(a)); sort(all(ind), [&](ll x, ll y) { return f(a[x]) < f(a[y]); }); return ind;}template<class T> vi rsorti(vector<T> &a) { auto b = a; vi ind = iota(0, sz(a)); rsortp(b, ind); return ind;}template<class T, class F> vi rsorti(vector<T> &a, F f) { vi ind = iota(0, sz(a)); sort(all(ind), [&](ll x, ll y) { return f(a[x]) > f(a[y]); }); return ind;}template<class A, class B, class F> vi sortpi(vector<A> &a, vector<B> &b, F f) { auto c = vtop(a, b); vi ind = iota(0, sz(a)); sort(all(ind), [&](ll x, ll y) { return f(c[x]) < f(c[y]); }); return ind;}template<class A, class B> vi sortpi(vector<A> &a, vector<B> &b, pcomparator f) { vi ind = iota(0, sz(a)); auto c = a; auto d = b; sortt(c, d, ind, f); return ind;}template<class A, class B> vi sortpi(vector<A> &a, vector<B> &b) { return sortpi(a, b, fisi); };template<class A, class B, class F> vi rsortpi(vector<A> &a, vector<B> &b, F f) { auto c = vtop(a, b); vi ind = iota(0, sz(a)); sort(all(ind), [&](ll x, ll y) { return f(c[x]) > f(c[y]); }); return ind;}template<class A, class B> vi rsortpi(vector<A> &a, vector<B> &b) { return sortpi(a, b, fdsd); };template<class A, class B, class C, class F> vi sortti(vector<A> &a, vector<B> &b, vector<C> &c, F f) { auto d = vtot(a, b, c); vi ind = iota(0, sz(a)); sort(all(ind), [&](ll x, ll y) { return f(d[x]) < f(d[y]); }); return ind;}template<class A, class B, class C> vi sortti(vector<A> &a, vector<B> &b, vector<C> &c, pcomparator f) { vi ind = iota(0, sz(a)); auto d = vtof(a, b, c, ind); sort(d, f); rep(i, sz(a))ind[i] = d[i].d; return ind;}template<class A, class B, class C> vi sortti(vector<A> &a, vector<B> &b, vector<C> &c) { vi ind = iota(0, sz(a)); sort(all(ind), [&](ll x, ll y) { if (a[x] == a[y]) { if (b[x] == b[y])return c[x] < c[y]; else return b[x] < b[y]; } else { return a[x] < a[y]; } }); return ind;}template<class A, class B, class C, class F> vi rsortti(vector<A> &a, vector<B> &b, vector<C> &c, F f) { auto d = vtot(a, b, c); vi ind = iota(0, sz(a)); sort(all(ind), [&](ll x, ll y) { return f(d[x]) > f(d[y]); }); return ind;}template<class A, class B, class C> vi rsortti(vector<A> &a, vector<B> &b, vector<C> &c) { vi ind = iota(0, sz(a)); sort(all(ind), [&](ll x, ll y) { if (a[x] == a[y]) { if (b[x] == b[y])return c[x] > c[y]; else return b[x] > b[y]; } else { return a[x] > a[y]; } }); return ind;} template<class T> void sort2(vector<vector<T >> &a) { for (ll i = 0, n = a.size(); i < n; ++i)sort(a[i]); } template<class T> void rsort2(vector<vector<T >> &a) { for (ll i = 0, n = a.size(); i < n; ++i)rsort(a[i]); } template<typename A, size_t N, typename T> void fill(A (&a)[N], const T &v) { rep(i, N)a[i] = v; }template<typename A, size_t N, size_t O, typename T> void fill(A (&a)[N][O], const T &v) { rep(i, N)rep(j, O)a[i][j] = v; }template<typename A, size_t N, size_t O, size_t P, typename T> void fill(A (&a)[N][O][P], const T &v) { rep(i, N)rep(j, O)rep(k, P)a[i][j][k] = v; }template<typename A, size_t N, size_t O, size_t P, size_t Q, typename T> void fill(A (&a)[N][O][P][Q], const T &v) { rep(i, N)rep(j, O)rep(k, P)rep(l, Q)a[i][j][k][l] = v; }template<typename A, size_t N, size_t O, size_t P, size_t Q, size_t R, typename T> void fill(A (&a)[N][O][P][Q][R], const T &v) { rep(i, N)rep(j, O)rep(k, P)rep(l, Q)rep(m, R)a[i][j][k][l][m] = v; }template<typename A, size_t N, size_t O, size_t P, size_t Q, size_t R, size_t S, typename T> void fill(A (&a)[N][O][P][Q][R][S], const T &v) { rep(i, N)rep(j, O)rep(k, P)rep(l, Q)rep(m, R)rep(n, S)a[i][j][k][l][m][n] = v; } template<typename W, typename T>void fill(W &xx, const T vall) { xx = vall;}template<typename W, typename T>void fill(vector<W> &vecc, const T vall) { for (auto &&vx : vecc)fill(vx, vall);} template<typename W,typename T>void fill(vector<W> &xx,const T v,ll len) {rep(i, len)xx[i]=v;} template<typename W,typename T>void fill(vector<vector<W>> &xx,const T v,ll lh,ll lw) {rep(i, lh)rep(j,lw)xx[i][j]=v;} template<class T,class U>void fill(vector<T> &a,U val,vi& ind) {fora(v,ind)a[v]=val;} template<typename A, size_t N> A sum(A (&a)[N]) { A res = 0; rep(i, N)res += a[i]; return res;}template<typename A, size_t N, size_t O> A sum(A (&a)[N][O]) { A res = 0; rep(i, N)rep(j, O)res += a[i][j]; return res;}template<typename A, size_t N, size_t O, size_t P> A sum(A (&a)[N][O][P]) { A res = 0; rep(i, N)rep(j, O)rep(k, P)res += a[i][j][k]; return res;}template<typename A, size_t N, size_t O, size_t P, size_t Q> A sum(A (&a)[N][O][P][Q]) { A res = 0; rep(i, N)rep(j, O)rep(k, P)rep(l, Q)res += a[i][j][k][l]; return res;}template<typename A, size_t N, size_t O, size_t P, size_t Q, size_t R> A sum(A (&a)[N][O][P][Q][R]) { A res = 0; rep(i, N)rep(j, O)rep(k, P)rep(l, Q)rep(m, R)res += a[i][j][k][l][m]; return res;}template<typename A, size_t N, size_t O, size_t P, size_t Q, size_t R, size_t S> A sum(A (&a)[N][O][P][Q][R][S]) { A res = 0; rep(i, N)rep(j, O)rep(k, P)rep(l, Q)rep(m, R)rep(n, S)res += a[i][j][k][l][m][n]; return res;} //@汎用便利関数 入力 ll in() {ll ret;cin >> ret;return ret;} string sin() {string ret;cin >> ret;return ret;} template<class T> void in(T &head) { cin >> head; }template<class T, class... U> void in(T &head, U &... tail) {cin >> head;in(tail...);} #define o_din(o1, o2, o3, o4, o5, o6, name, ...) name #define din1(a) ll a;cin>>a #define din2(a, b) ll a,b;cin>>a>> b #define din3(a, b, c) ll a,b,c;cin>>a>>b>>c #define din4(a, b, c, d) ll a,b,c,d;cin>>a>>b>>c>>d #define din5(a, b, c, d, e) ll a,b,c,d,e;cin>>a>>b>>c>>d>>e #define din6(a, b, c, d, e, f) ll a,b,c,d,e,f;cin>>a>>b>>c>>d>>e>>f #define din(...) o_din(__VA_ARGS__,din6,din5,din4,din3,din2 ,din1)(__VA_ARGS__) #define o_dind(o1, o2, o3, o4, name, ...) name #define din1d(a) din1(a);a-- #define din2d(a, b) din2(a,b);a--,b-- #define din3d(a, b, c) din3(a,b,c);a--,b--,c-- #define din4d(a, b, c, d) din4(a,b,c,d);a--,b--,c--,d-- #define dind(...) o_dind(__VA_ARGS__,din4d,din3d,din2d ,din1d)(__VA_ARGS__) template<class T> void out2(T &&head) { cout << head; } template<class T, class... U> void out2(T &&head, U &&... tail) { cout << head << " "; out2(tail...);} template<class T, class... U> void out(T &&head, U &&... tail) { cout << head << " "; out2(tail...); cout << "" << endl;} template<class T> void out(T &&head) { cout << head << endl;} void out() { cout << "" << endl;} #ifdef _DEBUG template<class T> string out_m(vector<T> &a, ll W = inf) {stringstream ss; if (W == inf)W = min(sz(a), 12ll); if(sz(a)==0)return ss.str(); rep(i, W) { ss << a[i] << " "; } ss << "" << endl; return ss.str();} template<class T> string out_m(vector<vector<T> > &a, ll H = inf, ll W = inf, int key = -1) { H = min({H, sz(a), 12ll}); W = min({W, sz(a[0]), 12ll}); stringstream ss; ss << endl; if (key == -1)ss << " *|"; else ss << " " << key << "|"; rep(w, W)ss << std::right << std::setw(4) << w; ss << "" << endl; rep(w, W * 4 + 3)ss << "_"; ss << "" << endl; rep(h, H) { ss << std::right << std::setw(2) << h << "|"; rep(w, min(sz(a[h]),12ll)) { if (a[h][w] == linf) ss << " e" << " "; else ss << std::right << std::setw(4) << a[h][w]; } ss << "" << endl; } ss << endl; return ss.str(); } /*@formatter:off*/ template<class T> string out_m(vector<vector<vector<T> > > &a, ll H = inf, ll W = inf, ll U = inf) {stringstream ss; if (H == inf)H = 5; H = min(H, sz(a)); rep(i, H) { ss << endl; ss << out_m(a[i], W, U, i); } ss << endl; return ss.str();} string out_m(int a) {stringstream ss;ss << a << endl;return ss.str();} template<class T> string out_m(T &a) {stringstream ss;ss << a << endl;return ss.str();} template<class T> void outv(vector<T> &a, ll W=inf) {cout << out_m(a,W) << endl;} template<class T> void outv(vector<vector<T> > &a, ll H = linf, ll W = linf,int key=-1) { cout << out_m(a,H,W,key) << endl;} template<class T> void outv(vector<vector<vector<T> > > &a, ll H = linf, ll W = linf,ll U = linf) {cout << out_m(a,H,W,U)<< endl;} #else template<class T> void outv(vector<T> &a, ll W = inf) { rep(i, min(W, sz(a))) { cout << a[i] << " "; } cout << "" << endl; } template<class T> void outv(vector<vector<T> > &a, ll H = linf, ll W = linf, int key = -1) { rep(i, min(H, sz(a))) { outv(a[i], W); }} template<class T> void outv(vector<vector<vector<T> > > &a, ll H = linf, ll W = linf, ll U = linf) { ; } #endif template<class T> void outl(vector<T> &a, int n = inf) { rep(i, min(n, sz(a)))cout << a[i] << endl; } template<class T> void na(vector<T> &a, ll n) { a.resize(n); rep(i, n)cin >> a[i]; } #define dna(a, n) vi a(n); rep(dnai,n) cin >> a[dnai]; template<class T> void nao(vector<T> &a, ll n) { a.resize(n + 1); a[0] = 0; rep(i, n)cin >> a[i + 1]; } template<class T> void naod(vector<T> &a, ll n) { a.resize(n + 1); a[0] = 0; rep(i, n)cin >> a[i + 1], a[i + 1]--; } template<class T> void nad(vector<T> &a, ll n) { a.resize(n); rep(i, n)cin >> a[i], a[i]--; } template<class T, class U> void na2(vector<T> &a, vector<U> &b, ll n) { a.resize(n); b.resize(n); rep(i, n)cin >> a[i] >> b[i]; } #define dna2(a, b, n) vi a(n),b(n);rep(dna2i, n)cin >> a[dna2i] >> b[dna2i]; template<class T, class U> void nao2(vector<T> &a, vector<U> &b, ll n) { a.resize(n + 1); b.resize(n + 1); a[0] = b[0] = 0; rep(i, n)cin >> a[i + 1] >> b[i + 1]; } #define dna2d(a, b, n) vi a(n),b(n);rep(dna2di, n){cin >> a[dna2di] >> b[dna2di];a[dna2di]--,b[dna2di]--;} template<class T, class U> void na2d(vector<T> &a, vector<U> &b, ll n) { a.resize(n); b.resize(n); rep(i, n)cin >> a[i] >> b[i], a[i]--, b[i]--; } template<class T, class U, class W> void na3(vector<T> &a, vector<U> &b, vector<W> &c, ll n) { a.resize(n); b.resize(n); c.resize(n); rep(i, n)cin >> a[i] >> b[i] >> c[i]; } #define dna3(a, b, c, n) vi a(n),b(n),c(n); rep(dna3i, n)cin >> a[dna3i] >> b[dna3i] >> c[dna3i]; template<class T, class U, class W> void na3d(vector<T> &a, vector<U> &b, vector<W> &c, ll n) { a.resize(n); b.resize(n); c.resize(n); rep(i, n)cin >> a[i] >> b[i] >> c[i], a[i]--, b[i]--, c[i]--; } #define dna3d(a, b, c, n) vi a(n),b(n),c(n); rep(dna3di, n){cin >> a[dna3di] >> b[dna3di] >> c[dna3di];a[dna3di]--,b[dna3di]--,c[dna3di]--;} template<class T, class U, class W, class X> void na4(vector<T> &a, vector<U> &b, vector<W> &c, vector<X> &d, ll n) { a.resize(n); b.resize(n); c.resize(n); d.resize(n); rep(i, n)cin >> a[i] >> b[i] >> c[i] >> d[i]; } #define dna4(a, b, c, d, n) vi a(n),b(n),c(n),d(n); rep(dna4i, n)cin >> a[dna4i] >> b[dna4i] >> c[dna4i]>>d[dna4i]; #define dna4d(a, b, c, d, n) vi a(n),b(n),c(n),d(n); rep(dna4i, n)cin >> a[dna4i] >> b[dna4i] >> c[dna4i]>>d[dna4i],--a[dna4i] ,-- b[dna4i],-- c[dna4i],--d[dna4i]; #define nt(a, h, w) resize(a,h,w);rep(nthi,h)rep(ntwi,w) cin >> a[nthi][ntwi]; #define ntd(a, h, w) resize(a,h,w);rep(ntdhi,h)rep(ntdwi,w) cin >> a[ntdhi][ntdwi], a[ntdhi][ntdwi]--; #define ntp(a, h, w) resize(a,h+2,w+2);fill(a,'#');rep(ntphi,1,h+1)rep(ntpwi,1,w+1) cin >> a[ntphi][ntpwi]; //デバッグ #define sp << " " << #define debugName(VariableName) # VariableName #define deb1(x) debugName(x)<<" = "<<out_m(x) #define deb2(x, ...) deb1(x) <<", "<< deb1(__VA_ARGS__) #define deb3(x, ...) deb1(x) <<", "<< deb2(__VA_ARGS__) #define deb4(x, ...) deb1(x) <<", "<< deb3(__VA_ARGS__) #define deb5(x, ...) deb1(x) <<", "<< deb4(__VA_ARGS__) #define deb6(x, ...) deb1(x) <<", "<< deb5(__VA_ARGS__) #define deb7(x, ...) deb1(x) <<", "<< deb6(__VA_ARGS__) #define deb8(x, ...) deb1(x) <<", "<< deb7(__VA_ARGS__) #define deb9(x, ...) deb1(x) <<", "<< deb8(__VA_ARGS__) #define deb10(x, ...) deb1(x) <<", "<< deb9(__VA_ARGS__) #define o_ebug(o1, o2, o3, o4, o5, o6, o7, o8, o9, o10, name, ...) name #ifdef _DEBUG #define deb(...) cerr<< o_ebug(__VA_ARGS__,deb10,deb9,deb8,deb7,deb6,deb5,deb4,deb3,deb2,deb1)(__VA_ARGS__) <<endl #else #define deb(...) ; #endif #define debugline(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n' //@formatter:off //よく使うクラス、構造体 struct unionfind { vector<ll> par; vector<ll> siz; vector<ll> es; ll n, trees;//連結グループの数(親の種類) unionfind(ll n) : n(n), trees(n) { par.resize(n); siz.resize(n); es.resize(n); for (ll i = 0; i < n; i++) { par[i] = i; siz[i] = 1; } } ll root(ll x) { if (par[x] == x) { return x; } else { return par[x] = root(par[x]); }} bool unite(ll x, ll y) { x = root(x); y = root(y); es[x]++; if (x == y) return false; if (siz[x] > siz[y]) swap(x, y); trees--; par[x] = y; siz[y] += siz[x]; es[y] += es[x]; return true; } bool same(ll x, ll y) { return root(x) == root(y); } ll size(ll x) { return siz[root(x)]; } ll esize(ll x) { return es[root(x)]; } vi sizes(){ vi cou(n); vi ret; ret.reserve(n); rep(i, n){ cou[root (i)]++; } rep(i, n){ if(cou[i])ret.push_back(cou[i]); } return ret; } //つながりを無向グラフと見なし、xが閉路に含まれるか判定 bool close(ll x) { return esize(x) >= size(x); } V<vi> sets() { vi ind(n, -1); ll i = 0; vvi(res, trees); rep(j, n) { ll r = root(j); if (ind[r] == -1)ind[r] = i++; res[ind[r]].push_back(j); } rep(i, trees) { ll r = root(res[i][0]); if (res[i][0] == r)continue; rep(j, 1, sz(res[i])) { if (res[i][j] == r) { swap(res[i][0], res[i][j]); break; } } } return res; } };//@formatter:off using bll =__int128; using u32 = unsigned; using u64 = unsigned long long; using u128 = __uint128_t; std::ostream &operator<<(std::ostream &dest, __int128_t value) { std::ostream::sentry s(dest); if (s) { __uint128_t tmp = value < 0 ? -value : value; char buffer[128]; char *d = std::end(buffer); do { --d; *d = "0123456789"[tmp % 10]; tmp /= 10; } while (tmp != 0); if (value < 0) { --d; *d = '-'; } ll len = std::end(buffer) - d; if (dest.rdbuf()->sputn(d, len) != len) { dest.setstate(std::ios_base::badbit); } } return dest;} //__int128 toi128(string &s) { __int128 ret = 0; for (ll i = 0; i < s.length(); ++i) if ('0' <= s[i] && s[i] <= '9') ret = 10 * ret + s[i] - '0'; return ret;} //エラー void ole() { #ifdef _DEBUG debugline("ole"); exit(0); #endif string a = "a"; rep(i, 30)a += a; rep(i, 1 << 17)cout << a << endl; cout << "OLE 出力長制限超過" << endl; exit(0);} void re() { assert(0 == 1); exit(0);} void tle() { while (inf)cout << inf << endl; } //便利関数 //テスト用 char ranc() { return (char) ('a' + rand() % 26); } ll rand(ll min, ll max) { assert(min <= max); if (min >= 0 && max >= 0) { return rand() % (max + 1 - min) + min; } else if (max < 0) { return -rand(-max, -min); } else { if (rand() % 2) { return rand(0, max); } else { return -rand(0, -min); }}} vi ranv(ll n, ll min, ll max) { vi v(n); rep(i, n)v[i] = rand(min, max); return v;} str ransu(ll n) { str s; rep(i, n)s += (char) rand('A', 'Z'); return s;} str ransl(ll n) { str s; rep(i, n)s += (char) rand('a', 'z'); return s;} //単調増加 vi ranvinc(ll n, ll min, ll max) { vi v(n); bool bad = 1; while (bad) { bad = 0; v.resize(n); rep(i, n) { if (i && min > max - v[i - 1]) { bad = 1; break; } if (i)v[i] = v[i - 1] + rand(min, max - v[i - 1]); else v[i] = rand(min, max); } } return v;} //便利 汎用 void ranvlr(ll n, ll min, ll max, vi &l, vi &r) { l.resize(n); r.resize(n); rep(i, n) { l[i] = rand(min, max); r[i] = l[i] + rand(0, max - l[i]); }} vp run_length(vi &a) { vp ret; ret.eb(a[0], 1); rep(i, 1, sz(a)) { if (ret.back().fi == a[i]) { ret.back().se++; } else { ret.eb(a[i], 1); }} return ret;} vector<pair<char, ll>> run_length(string &a) { vector<pair<char, ll>> ret; ret.eb(a[0], 1); rep(i, 1, sz(a)) { if (ret.back().fi == a[i]) { ret.back().se++; } else { ret.eb(a[i], 1); }} return ret;} template<class F> ll mgr(ll ok, ll ng, F f) { if (ok < ng) while (ng - ok > 1) { ll mid = (ok + ng) / 2; if (f(mid))ok = mid; else ng = mid; } else while (ok - ng > 1) { ll mid = (ok + ng) / 2; if (f(mid))ok = mid; else ng = mid; } return ok;} //strを整数として比較 string smax(str &a, str b) { if (sz(a) < sz(b)) { return b; } else if (sz(a) > sz(b)) { return a; } else if (a < b)return b; else return a;} //strを整数として比較 string smin(str &a, str b) { if (sz(a) > sz(b)) { return b; } else if (sz(a) < sz(b)) { return a; } else if (a > b)return b; else return a;} template<typename W, typename T> ll find(vector<W> &a, const T key) { rep(i, sz(a))if (a[i] == key)return i; return -1;} template<typename W, typename T> P find(vector<vector<W >> &a, const T key) { rep(i, sz(a))rep(j, sz(a[0]))if (a[i][j] == key)return mp(i, j); return mp(-1, -1);} template<typename W, typename U> T find(vector<vector<vector<W >>> &a, const U key) { rep(i, sz(a))rep(j, sz(a[0]))rep(k, sz(a[0][0]))if (a[i][j][k] == key)return mt(i, j, k); return mt(-1, -1, -1);} template<typename W, typename T> ll count2(W &a, const T k) { return a == k; } template<typename W, typename T> ll count2(vector<W> &a, const T k) { ll ret = 0; fora(v, a)ret += count2(v, k); return ret;} template<typename W, typename T> ll count(vector<W> &a, const T k) { ll ret = 0; fora(v, a)ret += count2(v, k); return ret;} ll count(str &a, str k) { ll ret = 0, len = k.length(); auto pos = a.find(k); while (pos != string::npos)pos = a.find(k, pos + len), ++ret; return ret;} vi count(str &a) { vi cou(26); char c = 'a'; if ('A' <= a[0] && a[0] <= 'Z')c = 'A'; rep(i, sz(a))++cou[a[i] - c]; return cou;} #define couif count_if //algorythm ll rev(ll a) { ll res = 0; while (a) { res *= 10; res += a % 10; a /= 10; } return res;} template<class T> void rev(vector<T> &a) { reverse(all(a)); } template<class U> void rev(vector<vector<U>> &a) { vector<vector<U> > b(sz(a[0]), vector<U>(sz(a))); rep(h, sz(a)) rep(w, sz(a[0]))b[w][h] = a[h][w]; a = b;} void rev(string &a) { reverse(all(a)); } constexpr ll p10[] = {1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000, 10000000000ll, 100000000000ll, 1000000000000ll, 10000000000000ll, 100000000000000ll, 1000000000000000ll, 10000000000000000ll, 100000000000000000ll, 1000000000000000000ll}; ll get(ll a, ll keta) { return (a / (ll) pow(10, keta)) % 10; } ll keta(ll v) { if (v < p10[9]) { if (v < p10[4]) { if (v < p10[2]) { if (v < p10[1]) return 1; else return 2; } else { if (v < p10[3]) return 3; else return 4; }} else { if (v < p10[7]) { if (v < p10[5]) return 5; else if (v < p10[6])return 6; else return 7; } else { if (v < p10[8])return 8; else return 9; }}} else { if (v < p10[13]) { if (v < p10[11]) { if (v < p10[10]) return 10; else return 11; } else { if (v < p10[12]) return 12; else return 13; }} else { if (v < p10[15]) { if (v < p10[14]) return 14; else if (v < p10[15])return 15; else return 16; } else { if (v < p10[17])return 17; else return 18; }}}} ll dsum(ll v,ll sin=10) { ll ret = 0; for (; v; v /= sin)ret += v % sin; return ret;} struct sint { ll v; sint(ll v) : v(v) {} operator ll() { return v; } //下からi番目 ll operator[](ll i) { return (v / p10[i]) % 10; } ll back(ll i) { return operator[](i); } //上からi番目 ll top(ll i) { ll len = keta(v); return operator[](len - 1 - i); } //先頭からi番目にセット ll settop(ll i, ll k) { ll len = keta(v); return set(len - 1 - i, k); } ll set(ll i, ll k) { if (i < 0)return settop(abs(i) - 1, k); return v += p10[i] * (k - (v / p10[i]) % 10); } ll add(ll i, ll k = 1) { return v += p10[i] * k; } ll addtop(ll i, ll k = 1) { return v += p10[keta(v) - i - 1] * k; } ll dec(ll i, ll k = 1) { return v -= p10[i] * k; } ll dectop(ll i, ll k = 1) { return v -= p10[keta(v) - i - 1] * k; } #define op(t, o)template<class T> t operator o(T r){return v o r;} op(ll, +=); op(ll, -=); op(ll, *=); op(ll, /=); op(ll, %=); op(ll, +); op(ll, -); op(ll, *); op(ll, /); op(ll, %); op(bool, ==); op(bool, !=); op(bool, <); op(bool, <=); op(bool, >); op(bool, >=); #undef op template<class T> ll operator<<=(T r) { return v *= p10[r]; } template<class T> ll operator<<(T r) { return v * p10[r]; } template<class T> ll operator>>=(T r) { return v /= p10[r]; } template<class T> ll operator>>(T r) { return v / p10[r]; } }; ll mask10(ll v) { return p10[v] - 1; } //変換系 template<class T> auto keys(T& a) { vector<decltype((a.begin())->fi)> res; for (auto &&k :a)res.push_back(k.fi); return res;} template<class T> auto values(T& a) { vector<decltype((a.begin())->se)> res; for (auto &&k :a)res.push_back(k.se); return res;} template<class T, class U> bool chma(T &a, const U &b) { if (a < b) { a = b; return true; } return false;} template<class U> bool chma(const U &b) { return chma(ma, b); } template<class T, class U> bool chmi(T &a, const U &b) { if (b < a) { a = b; return true; } return false;} template<class U> bool chmi(const U &b) { return chmi(mi, b); } template<class T> T min(T a, signed b) { return a < b ? a : b; } template<class T> T max(T a, signed b) { return a < b ? b : a; } template<class T> T min(T a, T b, T c) { return a >= b ? b >= c ? c : b : a >= c ? c : a; } template<class T> T max(T a, T b, T c) { return a <= b ? b <= c ? c : b : a <= c ? c : a; } template<class T> T min(vector<T>& a) { return *min_element(all(a)); } template<class T> T mini(vector<T>& a) { return min_element(all(a)) - a.begin(); } template<class T> T min(vector<T>& a, ll n) { return *min_element(a.begin(), a.begin() + min(n, sz(a))); } template<class T> T min(vector<T>& a, ll s, ll n) { return *min_element(a.begin() + s, a.begin() + min(n, sz(a))); } template<class T> T max(vector<T>& a) { return *max_element(all(a)); } template<class T,class U> T max(vector<T>& a,vector<U>& b) { return max(*max_element(all(a)),*max_element(all(b))); } template<class T> T maxi(vector<T>& a) { return max_element(all(a)) - a.begin(); } template<class T> T max(vector<T>& a, ll n) { return *max_element(a.begin(), a.begin() + min(n, sz(a))); } template<class T> T max(vector<T>& a, ll s, ll n) { return *max_element(a.begin() + s, a.begin() + min(n, sz(a))); } template<typename A, size_t N> A max(A (&a)[N]) { A res = a[0]; rep(i, N)res = max(res, a[i]); return res;}template<typename A, size_t N, size_t O> A max(A (&a)[N][O]) { A res = max(a[0]); rep(i, N)res = max(res, max(a[i])); return res;}template<typename A, size_t N, size_t O, size_t P> A max(A (&a)[N][O][P]) { A res = max(a[0]); rep(i, N)res = max(res, max(a[i])); return res;}template<typename A, size_t N, size_t O, size_t P, size_t Q> A max(A (&a)[N][O][P][Q], const T &v) { A res = max(a[0]); rep(i, N)res = max(res, max(a[i])); return res;}template<typename A, size_t N, size_t O, size_t P, size_t Q, size_t R> A max(A (&a)[N][O][P][Q][R]) { A res = max(a[0]); rep(i, N)res = max(res, max(a[i])); return res;}template<typename A, size_t N, size_t O, size_t P, size_t Q, size_t R, size_t S> A max(A (&a)[N][O][P][Q][R][S]) { A res = max(a[0]); rep(i, N)res = max(res, max(a[i])); return res;} template<typename A, size_t N> A min(A (&a)[N]) { A res = a[0]; rep(i, N)res = min(res, a[i]); return res;}template<typename A, size_t N, size_t O> A min(A (&a)[N][O]) { A res = min(a[0]); rep(i, N)res = min(res, max(a[i])); return res;}template<typename A, size_t N, size_t O, size_t P> A min(A (&a)[N][O][P]) { A res = min(a[0]); rep(i, N)res = min(res, min(a[i])); return res;}template<typename A, size_t N, size_t O, size_t P, size_t Q> A min(A (&a)[N][O][P][Q], const T &v) { A res = min(a[0]); rep(i, N)res = min(res, min(a[i])); return res;}template<typename A, size_t N, size_t O, size_t P, size_t Q, size_t R> A min(A (&a)[N][O][P][Q][R]) { A res = min(a[0]); rep(i, N)res = min(res, min(a[i])); return res;}template<typename A, size_t N, size_t O, size_t P, size_t Q, size_t R, size_t S> A min(A (&a)[N][O][P][Q][R][S]) { A res = min(a[0]); rep(i, N)res = min(res, min(a[i])); return res;} template<class T> T sum(vector<T> &v, ll s, ll t) { T ret = 0; rep(i, s, min(sz(v), t))ret += v[i]; return ret;}template<class T> T sum(vector<T> &v, ll t=inf) { return sum(v, 0, t);}template<class T> T sum(vector<vector<T> > &v) { T ret = 0; rep(i, sz(v))ret += sum(v[i]); return ret;}template<class T> T sum(vector<vector<vector<T> > > &v) { T ret = 0; rep(i, sz(v))ret += sum(v[i]); return ret;}template<class T> T sum(vector<vector<vector<vector<T> > > > &v) { T ret = 0; rep(i, sz(v))ret += sum(v[i]); return ret;}template<class T> T sum(vector<vector<vector<vector<vector<T> > > > > &v) { T ret = 0; rep(i, sz(v))ret += sum(v[i]); return ret;}template<class T> auto sum(priority_queue<T, vector<T>, greater<T> > &r) { auto q = r; T ret = 0; while (sz(q)) { ret += q.top(); q.pop(); } return ret;}template<class T> auto sum(priority_queue<T> &r) { auto q = r; T ret = 0; while (sz(q)) { ret += q.top(); q.pop(); } return ret;} //template<class T, class U, class... W> auto sumn(vector<T> &v, U head, W... tail) { auto ret = sum(v[0], tail...); rep(i, 1, min(sz(v), head))ret += sum(v[i], tail...); return ret;} void clear(PQ &q) { q = PQ(); } template<class T> void clear(queue<T> &q) { while (q.size())q.pop(); } template<class T> T *negarr(ll size) { T *body = (T *) malloc((size * 2 + 1) * sizeof(T)); return body + size;} template<class T> T *negarr2(ll h, ll w) { double **dummy1 = new double *[2 * h + 1]; double *dummy2 = new double[(2 * h + 1) * (2 * w + 1)]; dummy1[0] = dummy2 + w; for (ll i = 1; i <= 2 * h + 1; ++i) { dummy1[i] = dummy1[i - 1] + 2 * w + 1; } double **a = dummy1 + h; return a;} //imoは0-indexed //ruiは1-indexed template<class T> vector<T> imo(vector<T> &v) { vector<T> ret = v; rep(i, sz(ret) - 1)ret[i + 1] += ret[i]; return ret;} //kと同じものの数 template<class T, class U> vi imo(vector<T> &a, U k) {vector<T> ret = a;rep(i, sz(ret))ret[i] = a[i] == k;rep(i, sz(ret) - 1)ret[i + 1] += ret[i];return ret;} template<class T> vector<T> imox(vector<T> &v) { vector<T> ret = v; rep(i, sz(ret) - 1)ret[i + 1] ^= ret[i]; return ret;} //漸化的に最小を持つ template<class T> vector<T> imi(vector<T> &v) { vector<T> ret = v; rep(i, sz(ret) - 1)chmi(ret[i + 1], ret[i]); return ret;} template<class T> struct ruiC { const vector<T> rui; ruiC(vector<T> &ru) : rui(ru) {} T operator()(ll l, ll r) { if (l > r) { cerr<<"ruic ";deb(l, r);assert(0); } return rui[r] - rui[l]; } T operator[](ll i) { return rui[i]; } T back() { return rui.back(); } ll size() { return rui.size(); }}; template<class T> struct rruic { const T *rrui; rruic(T *ru) : rrui(ru) {} T operator()(ll l, ll r) { assert(l >= r); return rrui[r] - rrui[l]; } T operator[](ll i) { return rrui[i]; }}; template<class T>ostream &operator<<(ostream &os, ruiC<T> a) {fora(v,a.rui)os<<v<<" ";return os;} template<class T> vector<T> ruiv(vector<T> &a) { vector<T> ret(a.size() + 1); rep(i, a.size())ret[i + 1] = ret[i] + a[i]; return ret;} template<class T> ruiC<T> ruic(vector<T> &a) { vector<T> ret = ruiv(a); return ruiC<T>(ret);} vector<ll> ruiv(string &a) { if (sz(a) == 0)return vi(1); ll dec = ('0' <= a[0] && a[0] <= '9') ? '0' : 0; vector<ll> ret(a.size() + 1); rep(i, a.size())ret[i + 1] = ret[i] + a[i] - dec; return ret;} ruiC<ll> ruic(string &a) { vector<ll> ret = ruiv(a); return ruiC<ll>(ret);} //kと同じものの数 template<class T, class U> vi ruiv(T &a, U k) { vi ret(a.size() + 1); rep(i, a.size())ret[i + 1] = ret[i] + (a[i] == k); return ret;} template<class T, class U> ruiC<ll> ruic(T &a, U k) { vi ret = ruiv(a, k); return ruiC<ll>(ret);} //xor template<class T> struct ruixC { const vector<T> rui; ruixC(vector<T> &ru) : rui(ru) {} T operator()(ll l, ll r) { if (l > r) { cerr << "ruiXc "; deb(l, r); assert(0); } return rui[r] ^ rui[l]; } T operator[](ll i) { return rui[i]; } T back() { return rui.back(); } ll size() { return rui.size(); }}; template<class T> vector<T> ruix(vector<T> &a) { vector<T> ret(a.size() + 1); rep(i, a.size())ret[i + 1] = ret[i] ^ a[i]; return ret;} template<class T> ruixC<ll> ruixc(vector<T> &a) {vi ret = ruix(a);return ruixC<ll>(ret);} template<class T> vector<T> ruim(vector<T> &a) { vector<T> res(a.size() + 1, 1); rep(i, a.size())res[i + 1] = res[i] * a[i]; return res;} //漸化的に最小を1indexで持つ template<class T> vector<T> ruimi(vector<T> &a) { ll n = sz(a); vector<T> ret(n + 1); rep(i, 1, n) { ret[i] = a[i - 1]; chmi(ret[i + 1], ret[i]); } return ret;} //template<class T> T *rrui(vector<T> &a) { //右から左にかけての半開区間 (-1 n-1] template<class T> rruic<T> rrui(vector<T> &a) { ll len = a.size(); T *body = (T *) malloc((len + 1) * sizeof(T)); T *res = body + 1; rer(i, len - 1)res[i - 1] = res[i] + a[i]; return rruic<T>(res);} //掛け算 template<class T> T *rruim(vector<T> &a) { ll len = a.size(); T *body = (T *) malloc((len + 1) * sizeof(T)); T *res = body + 1; res[len - 1] = 1; rer(i, len - 1)res[i - 1] = res[i] * a[i]; return res;} template<class T, class U> void inc(T &a, U v = 1) { a += v; } template<class T, class U> void inc(vector<T> &a, U v = 1) { for (auto &u:a)inc(u, v); } template<class T, class U> void dec(T &a, U v = 1) { a -= v; } template<class T, class U> void dec(vector<T> &a, U v = 1) { for (auto &u :a)dec(u, v); } template<class U> void dec(string &a, U v = 1) { for (auto &u :a)dec(u, v); } template<class T> void dec(vector<T> &a) { for (auto &u :a)dec(u, 1); } template<class T,class U> void dec(vector<T> &a,vector<U> &b) { for (auto &u :a)dec(u, 1);for (auto &u :b)dec(u, 1); } template<class T,class U,class W> void dec(vector<T> &a,vector<U> &b,vector<W>&c ) { for (auto &u :a)dec(u, 1);for (auto &u :b)dec(u, 1);for (auto &u :c)dec(u, 1); } bool ins(ll h, ll w, ll H, ll W) { return h >= 0 && w >= 0 && h < H && w < W; } bool ins(ll l, ll v, ll r) { return l <= v && v < r; } template<class T> bool ins(vector<T> &a, ll i, ll j = 0) { return ins(0, i, sz(a)) && ins(0, j, sz(a)); } ll u(ll a) { return a < 0 ? 0 : a; } template<class T> vector<T> u(const vector<T> &a) { vector<T> ret = a; fora(v, ret)v = u(v); return ret;} #define MIN(a) numeric_limits<a>::min() #define MAX(a) numeric_limits<a>::max() template<class F> ll goldd_l(ll left, ll right, F calc) { double GRATIO = 1.6180339887498948482045868343656; ll lm = left + (ll) ((right - left) / (GRATIO + 1.0)); ll rm = lm + (ll) ((right - lm) / (GRATIO + 1.0)); ll fl = calc(lm); ll fr = calc(rm); while (right - left > 10) { if (fl < fr) { right = rm; rm = lm; fr = fl; lm = left + (ll) ((right - left) / (GRATIO + 1.0)); fl = calc(lm); } else { left = lm; lm = rm; fl = fr; rm = lm + (ll) ((right - lm) / (GRATIO + 1.0)); fr = calc(rm); } } ll minScore = MAX(ll); ll resIndex = left; for (ll i = left; i < right + 1; ++i) { ll score = calc(i); if (minScore > score) { minScore = score; resIndex = i; } } return resIndex;} template<class F> ll goldt_l(ll left, ll right, F calc) { double GRATIO = 1.6180339887498948482045868343656; ll lm = left + (ll) ((right - left) / (GRATIO + 1.0)); ll rm = lm + (ll) ((right - lm) / (GRATIO + 1.0)); ll fl = calc(lm); ll fr = calc(rm); while (right - left > 10) { if (fl > fr) { right = rm; rm = lm; fr = fl; lm = left + (ll) ((right - left) / (GRATIO + 1.0)); fl = calc(lm); } else { left = lm; lm = rm; fl = fr; rm = lm + (ll) ((right - lm) / (GRATIO + 1.0)); fr = calc(rm); } } if (left > right) { ll l = left; left = right; right = l; } ll maxScore = MIN(ll); ll resIndex = left; for (ll i = left; i < right + 1; ++i) { ll score = calc(i); if (maxScore < score) { maxScore = score; resIndex = i; } } return resIndex;} /*loopは200にすればおそらく大丈夫 余裕なら300に*/ template<class F> dou goldd_d(dou left, dou right, F calc, ll loop = 140) { dou GRATIO = 1.6180339887498948482045868343656; dou lm = left + ((right - left) / (GRATIO + 1.0)); dou rm = lm + ((right - lm) / (GRATIO + 1.0)); dou fl = calc(lm); dou fr = calc(rm); /*200にすればおそらく大丈夫*/ /*余裕なら300に*/ ll k = 141; loop++; while (--loop) { if (fl < fr) { right = rm; rm = lm; fr = fl; lm = left + ((right - left) / (GRATIO + 1.0)); fl = calc(lm); } else { left = lm; lm = rm; fl = fr; rm = lm + ((right - lm) / (GRATIO + 1.0)); fr = calc(rm); } } return left;} template<class F> dou goldt_d(dou left, dou right, F calc, ll loop = 140) { double GRATIO = 1.6180339887498948482045868343656; dou lm = left + ((right - left) / (GRATIO + 1.0)); dou rm = lm + ((right - lm) / (GRATIO + 1.0)); dou fl = calc(lm); dou fr = calc(rm); loop++; while (--loop) { if (fl > fr) { right = rm; rm = lm; fr = fl; lm = left + ((right - left) / (GRATIO + 1.0)); fl = calc(lm); } else { left = lm; lm = rm; fl = fr; rm = lm + ((right - lm) / (GRATIO + 1.0)); fr = calc(rm); } } return left;} //l ~ rを複数の区間に分割し、極致を与えるiを返す time-20 msまで探索 template<class F> ll goldd_ls(ll l, ll r, F calc, ll time = 2000) { auto lim = milliseconds(time - 20); ll mini = 0, minv = MAX(ll); /*区間をk分割する*/ rep(k, 1, inf) { auto s = system_clock::now(); ll haba = (r - l + k) / k;/*((r-l+1) + k-1) /k*/ ll nl = l; ll nr = l + haba; rep(i, k) { ll ni = goldd_l(nl, nr, calc); if (chmi(minv, calc(ni))) mini = ni; nl = nr; nr = nl + haba; } auto end = system_clock::now(); auto part = duration_cast<milliseconds>(end - s); auto elapsed = duration_cast<milliseconds>(end - start_time); if (elapsed + part * 2 >= lim) { break; } } return mini;} template<class F> ll goldt_ls(ll l, ll r, F calc, ll time = 2000) { auto lim = milliseconds(time - 20); ll maxi = 0, maxv = MIN(ll); /*区間をk分割する*/ rep(k, 1, inf) { auto s = system_clock::now(); ll haba = (r - l + k) / k;/*((r-l+1) + k-1) /k*/ ll nl = l; ll nr = l + haba; rep(i, k) { ll ni = goldt_l(nl, nr, calc); if (chma(maxv, calc(ni))) maxi = ni; nl = nr; nr = nl + haba; } auto end = system_clock::now(); auto part = duration_cast<milliseconds>(end - s); auto elapsed = duration_cast<milliseconds>(end - start_time); if (elapsed + part * 2 >= lim) { break; } } return maxi;} template<class F> dou goldd_d_s(dou l, dou r, F calc, ll time = 2000) { /*20ms余裕を持つ*/ auto lim = milliseconds(time - 20); dou mini = 0, minv = MAX(dou); /*区間をk分割する*/ rep(k, 1, inf) { auto s = system_clock::now(); dou haba = (r - l) / k; dou nl = l; dou nr = l + haba; rep(i, k) { dou ni = goldd_d(nl, nr, calc); if (chmi(minv, calc(ni))) mini = ni; nl = nr; nr = nl + haba; } auto end = system_clock::now(); auto part = duration_cast<milliseconds>(end - s); auto elapsed = duration_cast<milliseconds>(end - start_time); if (elapsed + part * 2 >= lim) { break; } } return mini;} template<class F> dou goldt_d_s(dou l, dou r, F calc, ll time = 2000) { /*20ms余裕を残している*/ auto lim = milliseconds(time - 20); dou maxi = 0, maxv = MIN(dou); /*区間をk分割する*/ rep(k, 1, inf) { auto s = system_clock::now(); dou haba = (r - l) / k; dou nl = l; dou nr = l + haba; rep(i, k) { dou ni = goldt_d(nl, nr, calc); if (chma(maxv, calc(ni))) maxi = ni; nl = nr; nr = nl + haba; } auto end = system_clock::now(); auto part = duration_cast<milliseconds>(end - s); auto elapsed = duration_cast<milliseconds>(end - start_time); if (elapsed + part * 2 >= lim) { break; } } return maxi;} template<class T> T min(vector<vector<T >> &a) { T res = MAX(T); rep(i, a.size())chmi(res, *min_element(all(a[i]))); return res;} template<class T> T max(vector<vector<T >> &a) { T res = MIN(T); rep(i, a.size())chma(res, *max_element(all(a[i]))); return res;} constexpr bool bget(ll m, ll keta) { return (m >> keta) & 1; } ll bget(ll m, ll keta, ll sinsuu) { m /= (ll) pow(sinsuu, keta); return m % sinsuu;} ll bit(ll n) { return (1LL << (n)); } ll bit(ll n, ll sinsuu) { return (ll) pow(sinsuu, n); } ll mask(ll n) { return (1ll << n) - 1; } #define bcou __builtin_popcountll //最下位ビット ll lbit(ll n) { return n & -n; } //最上位ビット ll hbit(ll n) { n |= (n >> 1); n |= (n >> 2); n |= (n >> 4); n |= (n >> 8); n |= (n >> 16); n |= (n >> 32); return n - (n >> 1);} ll hbitk(ll n) { ll k = 0; rer(i, 5) { ll a = k + (1ll << i); ll b = 1ll << a; if (b <= n)k += 1ll << i; } return k;} //初期化は0を渡す ll nextComb(ll &mask, ll n, ll r) { if (!mask)return mask = (1LL << r) - 1; ll x = mask & -mask; /*最下位の1*/ ll y = mask + x; /*連続した下の1を繰り上がらせる*/ ll res = ((mask & ~y) / x >> 1) | y; if (bget(res, n))return mask = 0; else return mask = res;} //n桁以下でビットがr個立っているもののvectorを返す vi bitCombList(ll n, ll r) { vi res; ll m = 0; while (nextComb(m, n, r)) { res.push_back(m); } return res;} char itoal(ll i) { return 'a' + i; } char itoaL(ll i) { return 'A' + i; } ll altoi(char c) { if ('A' <= c && c <= 'Z')return c - 'A'; return c - 'a';} ll ctoi(char c) { return c - '0'; } char itoc(ll i) { return i + '0'; } ll vtoi(vi &v) { ll res = 0; if (sz(v) > 18) { debugline("vtoi"); deb(sz(v)); ole(); } rep(i, sz(v)) { res *= 10; res += v[i]; } return res;} vi itov(ll i) { vi res; while (i) { res.push_back(i % 10); i /= 10; } rev(res); return res;} vi stov(string &a) { ll n = sz(a); vi ret(n); rep(i, n) { ret[i] = a[i] - '0'; } return ret;} //基準を満たさないものは0になる vi stov(string &a, char one) { ll n = sz(a); vi ret(n); rep(i, n)ret[i] = a[i] == one; return ret;} vector<vector<ll>> ctoi(vector<vector<char>> s, char c) { ll n = sz(s), m = sz(s[0]); vector<vector<ll>> res(n, vector<ll>(m)); rep(i, n)rep(j, m)res[i][j] = s[i][j] == c; return res;} #define unique(v) v.erase( unique(v.begin(), v.end()), v.end() ); //[i] := i番として圧縮されたものを返す vi compress(vi &a) { vi b; ll len = a.size(); for (ll i = 0; i < len; ++i) { b.push_back(a[i]); } sort(b); unique(b); for (ll i = 0; i < len; ++i) { a[i] = lower_bound(all(b), a[i]) - b.begin(); } ll blen = sz(b); vi ret(blen); rep(i, blen) { ret[i] = b[i]; } return ret;} vi compress(vi &a, umap<ll, ll> &map) { vi b; ll len = a.size(); for (ll i = 0; i < len; ++i) { b.push_back(a[i]); } sort(b); unique(b); for (ll i = 0; i < len; ++i) { ll v = a[i]; a[i] = lower_bound(all(b), a[i]) - b.begin(); map[v] = a[i]; } ll blen = sz(b); vi ret(blen); rep(i, blen) { ret[i] = b[i]; } return ret;} vi compress(vi &a, vi &r) { vi b; ll len = a.size(); fora(v, a)b.push_back(v); fora(v, r)b.push_back(v); sort(b); unique(b); for (ll i = 0; i < len; ++i) a[i] = lower_bound(all(b), a[i]) - b.begin(); for (ll i = 0; i < sz(r); ++i) r[i] = lower_bound(all(b), r[i]) - b.begin(); ll blen = sz(b); vi ret(blen); rep(i, blen) { ret[i] = b[i]; } return ret;} vi compress(vi &a, vi &r, vi &s) { vi b; ll len = a.size(); fora(v, a)b.push_back(v); fora(v, r)b.push_back(v); fora(v, s)b.push_back(v); sort(b); unique(b); for (ll i = 0; i < len; ++i) a[i] = lower_bound(all(b), a[i]) - b.begin(); for (ll i = 0; i < sz(r); ++i) r[i] = lower_bound(all(b), r[i]) - b.begin(); for (ll i = 0; i < sz(s); ++i) r[i] = lower_bound(all(b), s[i]) - b.begin(); ll blen = sz(b); vi ret(blen); rep(i, blen) { ret[i] = b[i]; } return ret;} vi compress(V<vi> &a) { vi b; fora(vv, a)fora(v, vv)b.push_back(v); sort(b); unique(b); fora(vv, a)fora(v, vv)v = lower_bound(all(b), v) - b.begin(); ll blen = sz(b); vi ret(blen); rep(i, blen) { ret[i] = b[i]; } return ret;} vi compress(vector<vector<vi >> &a) { vi b; fora(vvv, a)fora(vv, vvv)fora(v, vv)b.push_back(v); sort(b); unique(b); fora(vvv, a)fora(vv, vvv)fora(v, vv)v = lower_bound(all(b), v) - b.begin(); ll blen = sz(b); vi ret(blen); rep(i, blen) { ret[i] = b[i]; } return ret;} void compress(ll a[], ll len) { vi b; for (ll i = 0; i < len; ++i) { b.push_back(a[i]); } sort(b); unique(b); for (ll i = 0; i < len; ++i) { a[i] = lower_bound(all(b), a[i]) - b.begin(); }} //要素が見つからなかったときに困る #define binarySearch(a, v) (binary_search(all(a),v)) #define lowerIndex(a, v) (lower_bound(all(a),v)-a.begin()) #define lowerBound(a, v) (*lower_bound(all(a),v)) #define upperIndex(a, v) (upper_bound(all(a),v)-a.begin()) #define upperBound(a, v) (*upper_bound(all(a),v)) #define rlowerIndex(a, v) (upper_bound(all(a),v)-a.begin()-1) #define rlowerBound(a, v) *(--(upper_bound(all(a),v))) #define rupperIndex(a, v) (lower_bound(all(a),v)-a.begin()-1) #define rupperBound(a, v) *(--(lower_bound(all(a),v))) //iteratorを返す //valueが1以上の物を返す 0は見つけ次第削除 //vを減らす場合 (*it).se--でいい template<class T, class U, class V> auto lower_map(map<T, U> &m, V k) { auto ret = m.lower_bound(k); while (ret != m.end() && (*ret).second == 0) { ret = m.erase(ret); } return ret;} template<class T, class U, class V> auto upper_map(map<T, U> &m, V k) { auto ret = m.upper_bound(k); while (ret != m.end() && (*ret).second == 0) { ret = m.erase(ret); } return ret;} //存在しなければエラー template<class T, class U, class V> auto rlower_map(map<T, U> &m, V k) { auto ret = upper_map(m, k); assert(ret != m.begin()); ret--; while (1) { if ((*ret).second != 0)break; assert(ret != m.begin()); auto next = ret; --next; m.erase(ret); ret = next; } return ret;} template<class T, class U, class V> auto rupper_map(map<T, U> &m, V k) { auto ret = lower_map(m, k); assert(ret != m.begin()); ret--; while (1) { if ((*ret).second != 0)break; assert(ret != m.begin()); auto next = ret; --next; m.erase(ret); ret = next; } return ret;} template<class T> void fin(T s) { cout << s << endl, exit(0); } //便利 数学 math ll mod(ll a, ll m) { return (a % m + m) % m; } ll pow(ll a) { return a * a; }; ll fact(ll v) { return v <= 1 ? 1 : v * fact(v - 1); } ll comi(ll n, ll r) { assert(n < 100); static vvi(pas, 100, 100); if (pas[0][0])return pas[n][r]; pas[0][0] = 1; rep(i, 1, 100) { pas[i][0] = 1; rep(j, 1, i + 1)pas[i][j] = pas[i - 1][j - 1] + pas[i - 1][j]; } return pas[n][r];} double comd(ll n, ll r) { assert(n < 2020); static vvd(comb, 2020, 2020); if (comb[0][0] == 0) { comb[0][0] = 1; rep(i, 2000) { comb[i + 1][0] = 1; rep(j, 1, i + 2) { comb[i + 1][j] = comb[i][j] + comb[i][j - 1]; } } } return comb[n][r];} ll gcd(ll a, ll b) {while (b) a %= b, swap(a, b);return abs(a);} ll gcd(vi b) {ll res = b[0];rep(i, 1, sz(b))res = gcd(b[i], res);return res;} ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } ll lcm(vi a) {ll res = a[0];rep(i, 1, sz(a))res = lcm(a[i], res);return res;} ll ceil(ll a, ll b) {if (b == 0) {debugline("ceil");deb(a, b);ole();return -1;} else if (a < 0) { return 0; } else { return (a + b - 1) / b; }} ll lower_remi__bx_a(ll kei, ll rem, ll x) {if (rem >= x) return 0;return (x - rem + kei - 1) / kei;} ll lower_remv__bx_a(ll kei, ll rem, ll x) {if (rem >= x) return rem;return (x - rem + kei - 1) / kei * kei + rem;} ll upper_remi__bx_a(ll kei, ll rem, ll x) {if (rem > x) return 0;return (x - rem + kei) / kei;} ll upper_remv__bx_a(ll kei, ll rem, ll x) {if (rem > x) return rem;return (x - rem + kei) / kei * kei + rem;} //v * v >= aとなる最小のvを返す ll sqrt(ll a) {if (a < 0) {debugline("sqrt");deb(a);ole();}ll res = (ll) std::sqrt(a);while (res * res < a)++res;return res;} double log(double e, double x) { return log(x) / log(e); } ll sig(ll t) { return ((1 + t) * t) >> 1; } ll sig(ll s, ll t) { return ((s + t) * (t - s + 1)) >> 1; } //幾何 Pをcomplexとして扱う template<class T, class U> bool eq(T a, U b) { return fabs(a - b) < eps; } dou atan2(pd a) { return atan2(a.se, a.fi); } dou angle(pd f, pd t) { return atan2(t.se - f.se, t.fi - f.fi); } dou distance(pd a, pd b) { return hypot(a.fi - b.fi, a.se - b.se); } //bを中心とするabcのtheta aからcにかけて時計回り dou angle(pd a, pd b, pd c) { dou ax = a.fi - b.fi; dou ay = a.se - b.se; dou cx = c.fi - b.fi; dou cy = c.se - b.se; double ret = atan2(cy, cx) - atan2(ay, ax); if (ret < 0) ret += 2 * PI; return ret;} dou dot(pd a, pd b) { return a.fi * b.fi + a.se + b.se; } dou cro(pd a, pd b) { return a.fi * b.se - a.se + b.fi; } //機能拡張 template<typename CharT, typename Traits, typename Alloc>basic_string<CharT, Traits, Alloc>operator+(const basic_string<CharT, Traits, Alloc> &lhs, const int rv) { basic_string<CharT, Traits, Alloc> str(lhs); str.append(to_string(rv)); return str;}template<typename CharT, typename Traits, typename Alloc>void operator+=(basic_string<CharT, Traits, Alloc> &lhs, const int rv) { lhs += to_string(rv);}template<typename CharT, typename Traits, typename Alloc>basic_string<CharT, Traits, Alloc>operator+(const basic_string<CharT, Traits, Alloc> &lhs, const signed rv) { basic_string<CharT, Traits, Alloc> str(lhs); str.append(to_string(rv)); return str;}template<typename CharT, typename Traits, typename Alloc>void operator+=(basic_string<CharT, Traits, Alloc> &lhs, const signed rv) { lhs += to_string(rv);} template<class T, class U> void operator+=(queue<T> &a, U v) { a.push(v); }template<class T, class U> void operator+=(deque<T> &a, U v) { a.push_back(v); }template<class T> priority_queue<T, vector<T>, greater<T> > &operator+=(priority_queue<T, vector<T>, greater<T> > &a, vector<T> &v) { fora(d, v)a.push(d); return a;}template<class T, class U> priority_queue<T, vector<T>, greater<T> > &operator+=(priority_queue<T, vector<T>, greater<T> > &a, U v) { a.push(v); return a;}template<class T, class U> priority_queue<T> &operator+=(priority_queue<T> &a, U v) { a.push(v); return a;}template<class T> set<T> &operator+=(set<T> &a, vector<T> v) { fora(d, v)a.insert(d); return a;}template<class T, class U> auto operator+=(set<T> &a, U v) { return a.insert(v);}template<class T, class U> auto operator-=(set<T> &a, U v) { return a.erase(v);}template<class T, class U> auto operator+=(mset<T> &a, U v) { return a.insert(v); }template<class T, class U> set<T, greater<T>> &operator+=(set<T, greater<T>> &a, U v) { a.insert(v); return a;}template<class T, class U> vector<T> &operator+=(vector<T> &a, U v) { a.push_back(v); return a;}template<class T, class U> vector<T> operator+(const vector<T> &a, U v) { vector<T> ret = a; ret += v; return ret;}template<class T, class U> vector<T> operator+(U v, const vector<T> &a) { vector<T> ret = a; ret.insert(ret.begin(), v); return ret;}template<class T> vector<T> operator+(vector<T> a, vector<T> b) { vector<T> ret; ret = a; fora(v, b)ret += v; return ret;}template<class T> vector<T> &operator+=(vector<T> &a, vector<T> &b) { fora(v, b)a += v; return a;}template<class T> vector<T> &operator-=(vector<T> &a, vector<T> &b) { if (sz(a) != sz(b)) { debugline("vector<T> operator-="); deb(a); deb(b); exit(0); } rep(i, sz(a))a[i] -= b[i]; return a;} template<class T> vector<T> operator-(vector<T> &a, vector<T> &b) { if (sz(a) != sz(b)) { debugline("vector<T> operator-"); deb(a); deb(b); ole(); } vector<T> res(sz(a)); rep(i, sz(a))res[i] = a[i] - b[i]; return res;} template<class T, class U> vector<T> operator*(vector<T> &a, U b) { vector<T> ret; fora(v, a)ret += v * b; return ret;} template<class T, class U> vector<T> operator/(vector<T> &a, U b) { vector<T> ret; fora(v, a)ret += v / b; return ret;} template<class T, class U> vector<T> operator*=(vector<T> &a, U b) { fora(v, a)v *= b; return a;} template<class T, class U> vector<T> operator/=(vector<T> &a, U b) { fora(v, a)v /= b; return a;} template<typename T> void erase(vector<T> &v, unsigned ll i) { v.erase(v.begin() + i); } template<typename T> void erase(vector<T> &v, unsigned ll s, unsigned ll e) { v.erase(v.begin() + s, v.begin() + e); } template<class T, class U> void erase(map<T, U> &m, ll okl, ll ngr) { m.erase(m.lower_bound(okl), m.lower_bound(ngr)); } template<class T> void erase(set<T> &m, ll okl, ll ngr) { m.erase(m.lower_bound(okl), m.lower_bound(ngr)); } template<typename T> void erasen(vector<T> &v, unsigned ll s, unsigned ll n) { v.erase(v.begin() + s, v.begin() + s + n); } template<typename T, typename U> void insert(vector<T> &v, unsigned ll i, U t) { v.insert(v.begin() + i, t); } template<typename T, typename U> void push_front(vector<T> &v, U t) { v.insert(v.begin(), t); } template<typename T, typename U> void insert(vector<T> &v, unsigned ll i, vector<T> list) { for (auto &&va:list)v.insert(v.begin() + i++, va); } template<typename T> void insert(set<T> &v, vector<T> list) { for (auto &&va :list)v.insert(va); } vector<string> split(const string a, const char deli) { string b = a + deli; ll l = 0, r = 0, n = b.size(); vector<string> res; rep(i, n) { if (b[i] == deli) { r = i; if (l < r)res.push_back(b.substr(l, r - l)); l = i + 1; } } return res;} vector<string> split(const string a, const string deli) { vector<string> res; ll kn = sz(deli); std::string::size_type Pos(a.find(deli)); ll l = 0; while (Pos != std::string::npos) { if (Pos - l)res.push_back(a.substr(l, Pos - l)); l = Pos + kn; Pos = a.find(deli, Pos + kn); } if (sz(a) - l)res.push_back(a.substr(l, sz(a) - l)); return res;} void yn(bool a) { if (a)cout << "yes" << endl; else cout << "no" << endl; } void Yn(bool a) { if (a)cout << "Yes" << endl; else cout << "No" << endl; } void YN(bool a) { if (a)cout << "YES" << endl; else cout << "NO" << endl; } void fyn(bool a) { if (a)cout << "yes" << endl; else cout << "no" << endl; exit(0);} void fYn(bool a) { if (a)cout << "Yes" << endl; else cout << "No" << endl; exit(0);} void fYN(bool a) { if (a)cout << "YES" << endl; else cout << "NO" << endl; exit(0);} void Possible(bool a) { if (a)cout << "Possible" << endl; else cout << "Impossible" << endl; exit(0);} void POSSIBLE(bool a) { if (a)cout << "POSSIBLE" << endl; else cout << "IMPOSSIBLE" << endl; exit(0);} template<typename T> class fixed_point : T {public: explicit constexpr fixed_point(T &&t) noexcept: T(std::forward<T>(t)) {} template<typename... Args> constexpr decltype(auto) operator()(Args &&... args) const { return T::operator()(*this, std::forward<Args>(args)...); }};template<typename T> static inline constexpr decltype(auto) fix(T &&t) noexcept { return fixed_point<T>{std::forward<T>(t)}; } //@formatter:off template<typename T> T minv(T a, T m); template<typename T> T minv(T a); template<typename T> class Modular { public: using Type = typename decay<decltype(T::value)>::type; constexpr Modular() : value() {} template<typename U> Modular(const U &x) { value = normalize(x); } template<typename U> static Type normalize(const U &x) { Type v; if (-mod() <= x && x < mod()) v = static_cast<Type>(x); else v = static_cast<Type>(x % mod()); if (v < 0) v += mod(); return v; } const Type &operator()() const { return value; } template<typename U>explicit operator U() const { return static_cast<U>(value); } constexpr static Type mod() { return T::value; } Modular &operator+=(const Modular &other) { if ((value += other.value) >= mod()) value -= mod(); return *this; } Modular &operator-=(const Modular &other) { if ((value -= other.value) < 0) value += mod(); return *this; } template<typename U> Modular &operator+=(const U &other) { return *this += Modular(other); } template<typename U> Modular &operator-=(const U &other) { return *this -= Modular(other); } Modular &operator++() { return *this += 1; } Modular &operator--() { return *this -= 1; } Modular operator++(signed) { Modular result(*this); *this += 1; return result; } Modular operator--(signed) { Modular result(*this); *this -= 1; return result; } Modular operator-() const { return Modular(-value); } template<typename U = T>typename enable_if<is_same<typename Modular<U>::Type, signed>::value, Modular>::type &operator*=(const Modular &rhs) { #ifdef _WIN32 uint64_t x = static_cast<int64_t>(value) * static_cast<int64_t>(rhs.value);uint32_t xh = static_cast<uint32_t>(x >> 32), xl = static_cast<uint32_t>(x), d, m;asm("divl %4; \n\t": "=a" (d), "=d" (m): "d" (xh), "a" (xl), "r" (mod()));value = m; #else value = normalize(static_cast<int64_t>(value) * static_cast<int64_t>(rhs.value)); #endif return *this; } template<typename U = T> typename enable_if<is_same<typename Modular<U>::Type, int64_t>::value, Modular>::type &operator*=(const Modular &rhs) { int64_t q = static_cast<int64_t>(static_cast<double>(value) * rhs.value / mod()); value = normalize(value * rhs.value - q * mod()); return *this; } template<typename U = T> typename enable_if<!is_integral<typename Modular<U>::Type>::value, Modular>::type &operator*=(const Modular &rhs) { value = normalize(value * rhs.value); return *this; } Modular &operator/=(const Modular &other) { return *this *= Modular(minv(other.value)); } template<typename U> friend bool operator==(const Modular<U> &lhs, const Modular<U> &rhs); template<typename U> friend bool operator<(const Modular<U> &lhs, const Modular<U> &rhs); template<typename U> friend std::istream &operator>>(std::istream &stream, Modular<U> &number); operator int() { return value; }private: Type value; }; template<typename T> bool operator==(const Modular<T> &lhs, const Modular<T> &rhs) { return lhs.value == rhs.value; }template<typename T, typename U> bool operator==(const Modular<T> &lhs, U rhs) { return lhs == Modular<T>(rhs); }template<typename T, typename U> bool operator==(U lhs, const Modular<T> &rhs) { return Modular<T>(lhs) == rhs; }template<typename T> bool operator!=(const Modular<T> &lhs, const Modular<T> &rhs) { return !(lhs == rhs); }template<typename T, typename U> bool operator!=(const Modular<T> &lhs, U rhs) { return !(lhs == rhs); }template<typename T, typename U> bool operator!=(U lhs, const Modular<T> &rhs) { return !(lhs == rhs); }template<typename T> bool operator<(const Modular<T> &lhs, const Modular<T> &rhs) { return lhs.value < rhs.value; }template<typename T> Modular<T> operator+(const Modular<T> &lhs, const Modular<T> &rhs) { return Modular<T>(lhs) += rhs; }template<typename T, typename U> Modular<T> operator+(const Modular<T> &lhs, U rhs) { return Modular<T>(lhs) += rhs; }template<typename T, typename U> Modular<T> operator+(U lhs, const Modular<T> &rhs) { return Modular<T>(lhs) += rhs; }template<typename T> Modular<T> operator-(const Modular<T> &lhs, const Modular<T> &rhs) { return Modular<T>(lhs) -= rhs; }template<typename T, typename U> Modular<T> operator-(const Modular<T> &lhs, U rhs) { return Modular<T>(lhs) -= rhs; }template<typename T, typename U> Modular<T> operator-(U lhs, const Modular<T> &rhs) { return Modular<T>(lhs) -= rhs; }template<typename T> Modular<T> operator*(const Modular<T> &lhs, const Modular<T> &rhs) { return Modular<T>(lhs) *= rhs; }template<typename T, typename U> Modular<T> operator*(const Modular<T> &lhs, U rhs) { return Modular<T>(lhs) *= rhs; }template<typename T, typename U> Modular<T> operator*(U lhs, const Modular<T> &rhs) { return Modular<T>(lhs) *= rhs; }template<typename T> Modular<T> operator/(const Modular<T> &lhs, const Modular<T> &rhs) { return Modular<T>(lhs) /= rhs; }template<typename T, typename U> Modular<T> operator/(const Modular<T> &lhs, U rhs) { return Modular<T>(lhs) /= rhs; }template<typename T, typename U> Modular<T> operator/(U lhs, const Modular<T> &rhs) { return Modular<T>(lhs) /= rhs; } constexpr signed MOD = // 998244353; 1e9 + 7;//MOD using mint = Modular<std::integral_constant<decay<decltype(MOD)>::type, MOD>>; constexpr int mint_len = 1400001; vi fac, finv, inv; vi p2; mint com(int n, int r) { if (r < 0 || r > n) return 0; return mint(finv[r] * fac[n] % MOD * finv[n - r]);} mint pom(int n, int r) {/* if (!sz(fac)) com(0, -1);*/ if (r < 0 || r > n) return 0; return mint(fac[n] * finv[n - 1]);} mint npr(int n, int r) {/* if (!sz(fac)) com(0, -1);*/ if (r < 0 || r > n) return 0; return mint(fac[n] * finv[n - r]);} int nprin(int n, int r) {/* if (!sz(fac)) com(0, -1);*/ if (r < 0 || r > n) return 0; return fac[n] * finv[n - r] % MOD;} int icom(int n, int r) { const int NUM_ = 1400001; static ll fac[NUM_ + 1], finv[NUM_ + 1], inv[NUM_ + 1]; if (fac[0] == 0) { inv[1] = fac[0] = finv[0] = 1; for (int i = 2; i <= NUM_; ++i) inv[i] = inv[MOD % i] * (MOD - MOD / i) % MOD; for (int i = 1; i <= NUM_; ++i) fac[i] = fac[i - 1] * i % MOD, finv[i] = finv[i - 1] * inv[i] % MOD; } if (r < 0 || r > n) return 0; return ((finv[r] * fac[n] % MOD) * finv[n - r]) % MOD;} #define ncr com #define ncri icom //n個の場所にr個の物を置く mint nhr(int n, int r) { return com(n + r - 1, r); } mint hom(int n, int r) { return com(n + r - 1, r); } int nhri(int n, int r) { return icom(n + r - 1, r); } template<typename T> T minv(T a, T m) { T u = 0, v = 1; while (a != 0) { T t = m / a; m -= t * a; swap(a, m); u -= t * v; swap(u, v); } assert(m == 1); return u;} template<typename T> T minv(T a) { if (a < mint_len)return inv[a]; T u = 0, v = 1; T m = MOD; while (a != 0) { T t = m / a; m -= t * a; swap(a, m); u -= t * v; swap(u, v); } assert(m == 1); return u;} template<typename T, typename U> Modular<T> mpow(const Modular<T> &a, const U &b) { assert(b >= 0); int x = a(), res = 1; U p = b; while (p > 0) { if (p & 1) (res *= x) %= MOD; (x *= x) %= MOD; p >>= 1; } return res;} template<typename T, typename U, typename V> mint mpow(const T a, const U b, const V m = MOD) { assert(b >= 0); int x = a, res = 1; U p = b; while (p > 0) { if (p & 1) (res *= x) %= m; (x *= x) %= m; p >>= 1; } return res;} template<typename T, typename U> mint mpow(const T a, const U b) { assert(b >= 0); int x = a, res = 1; U p = b; while (p > 0) { if (p & 1) (res *= x) %= MOD; (x *= x) %= MOD; p >>= 1; } return res;} template<typename T, typename U, typename V> int mpowi(const T &a, const U &b, const V &m = MOD) { assert(b >= 0); int x = a, res = 1; U p = b; while (p > 0) { if (p & 1) (res *= x) %= m; (x *= x) %= m; p >>= 1; } return res;} template<typename T> string to_string(const Modular<T> &number) { return to_string(number());} string yuri(const mint &a) { stringstream st; rep(i, 300) {rep(j, 300) {if ((mint) i / j == a) {st << i << " / " << j;return st.str();}}} rep(i, 1000) {rep(j, 1000) {if ((mint) i / j == a) {st << i << " / " << j;return st.str();}}} return st.str();} template<typename T> std::ostream &operator<<(std::ostream &stream, const Modular<T> &number) {stream << number(); #ifdef _DEBUG // stream << " -> " << yuri(number); #endif return stream; } //@formatter:off template<typename T> std::istream &operator>>(std::istream &stream, Modular<T> &number) { typename common_type<typename Modular<T>::Type, int64_t>::type x; stream >> x; number.value = Modular<T>::normalize(x); return stream;} using PM = pair<mint, mint>; using vm = vector<mint>; using mapm = map<int, mint>; using umapm = umap<int, mint>; #define vvm(...) o_vvt(__VA_ARGS__,vvt4,vvt3,vvt2 ,vvt1,vvt0)(mint,__VA_ARGS__) #define vnm(name, ...) auto name = make_v<mint>(__VA_ARGS__) struct setmod{ setmod() { // p2.resize(mint_len);p2[0] = 1; for (int i = 1; i < mint_len; ++i) p2[i] = p2[i - 1] * 2 % MOD; fac.resize(mint_len); finv.resize(mint_len); inv.resize(mint_len); inv[1] = fac[0] = finv[0] = 1; for (int i = 2; i < mint_len; ++i) inv[i] = inv[MOD % i] * (MOD - MOD / i) % MOD; for (int i = 1; i < mint_len; ++i) fac[i] = fac[i - 1] * i % MOD, finv[i] = finv[i - 1] * inv[i] % MOD; } }setmodv; //@formatter:on //nhr n個の場所にr個の物を分ける //@起動時 struct initon { initon() { cin.tie(0); ios::sync_with_stdio(false); cout.setf(ios::fixed); cout.precision(16); srand((unsigned) clock() + (unsigned) time(NULL)); }; } initonv;//@formatter:on //gra mll pr //上下左右 const string udlr = "udlr"; string UDLR = "UDLR";//x4と連動 UDLR.find('U') := x4[0] //右、上が正 constexpr ll y4[] = {1, -1, 0, 0}; constexpr ll x4[] = {0, 0, -1, 1}; constexpr ll y8[] = {0, 1, 0, -1, -1, 1, 1, -1}; constexpr ll x8[] = {1, 0, -1, 0, 1, -1, 1, -1}; ll n, m, k, d, H, W, x, y, z, q; ll cou; vi a, b, c; //vvi (s, 0, 0); vvc (ba, 0, 0); vp p; str s; /*@formatter:off*/ #define forg(gi, ve) for (ll gi = 0,forglim = ve.size(), f, t, c; gi < forglim && (f = ve[gi].f, t = ve[gi].t, c = ve[gi].c, true); ++gi) #define fort(gi, ve) for (ll gi = 0, f, t, c; gi < ve.size() && (f = ve[gi].f, t = ve[gi].t, c = ve[gi].c, true); ++gi)if(t!=p) #define fore(gi, ve) for (ll gi = 0,forglim = ve.size(), f, t, c; gi < forglim && (f = ve[gi].f, t = ve[gi].t, c = ve[gi].c, true); ++gi) template<class T> struct edge { int f, t; T c; edge(int f, int t, T c = 1) : f(f), t(t), c(c) {} bool operator<(const edge &b) const { return c < b.c; } bool operator>(const edge &b) const { return c > b.c; }}; template<class T> ostream &operator<<(ostream &os, edge<T> &e) {os << e.f << " " << e.t << " " << e.c;return os;} template<typename T> class graph { public : vector<vector<edge<T>>> g; vector<edge<T>> edges; int n; explicit graph(int n) : n(n) { g.resize(n); } void clear() { g.clear(), edges.clear(); } void resize(int n) {this->n = n;g.resize(n);} int size() { return n; } vector<edge<T> > &operator[](int i) { return g[i]; } virtual void add(int f, int t, T c) = 0; virtual void set_edges() = 0; }; template<typename T =ll> class digraph : public graph<T> { public: using graph<T>::g; using graph<T>::n; using graph<T>::edges; explicit digraph(int n) : graph<T>(n) {} void add(int f, int t, T c = 1) { if (!(0 <= f && f < n && 0 <= t && t < n)) {debugline("digraph add");deb(f, t, c);ole();} g[f].emplace_back(f, t, c); edges.emplace_back(f, t, c);//edgesを使わないなら消せる } void ing(int n, int m, int minus = 1) { this->resize(n); rep(i, m) { int f, t; cin >> f >> t; f -= minus; t -= minus; add(f, t); } } void ingc(int n, int m, int minus = 1) { this->resize(n); rep(i, m) { int f, t, c; cin >> f >> t >> c; f -= minus; t -= minus; add(f, t, c); } } void set_edges() override{ if (sz(edges))return; rep(i, n)fora(e, g[i])edges.push_back(e); } }; template<class T=int> class undigraph : public graph<T> { public: using graph<T>::g; using graph<T>::n; using graph<T>::edges; explicit undigraph(int n) : graph<T>(n) {} // f < t void add(int f, int t, T c = 1) { if (!(0 <= f && f < n && 0 <= t && t < n)) { debugline("undigraph add"); deb(f, t, c); ole(); } g[f].emplace_back(f, t, c); g[t].emplace_back(t, f, c); edges.emplace_back(f, t, c);//edgesを使わないなら消せる edges.emplace_back(t, f, c); } void add(edge<T> &e) { int f = e.f, t = e.t; T c = e.c; add(f, t, c); } void ing(int n, int m, int minus = 1) { this->resize(n); rep(i, m) { int f, t; cin >> f >> t; f -= minus; t -= minus; add(f, t); } } void ingc(int n, int m, int minus = 1) { this->resize(n); rep(i, m) { int f, t, c; cin >> f >> t >> c; f -= minus; t -= minus; add(f, t, c); } } void set_edges () override{ if (sz(edges))return; rep(i, n)fora(e, g[i])edges.push_back(e); } }; template<class T> vector<T> dijkstra_mitu(const graph<T> &g, int s, int init_value = -1) { if (!(0 <= s && s < g.n)) { debugline("dijkstra_mitu"); deb(s, g.n); ole(); } T initValue = MAX(T); vector<T> dis(g.n, initValue); dis[s] = 0; vb used(g.n); while (true) { int v = -1; rep(i, g.n) { if (!used[i] && ((v == -1 && dis[i] != initValue) || (dis[i] < dis[v]))) { v = i; } } if (v == -1)break; used[v] = 1; for (auto &&e : g.g[v]) { if (dis[e.t] > dis[v] + e.c) { dis[e.t] = dis[v] + e.c; } } } /*基本、たどり着かないなら-1*/ for (auto &&d :dis) { if (d == initValue) { d = init_value; } } return dis;} template<typename T> struct radixheap { vector<pair<u64, T> > v[65]; u64 size, last; radixheap() : size(0), last(0) {} bool empty() const { return size == 0; } int getbit(int a) { return a ? 64 - __builtin_clzll(a) : 0; } void push(u64 key, const T &value) { ++size; v[getbit(key ^ last)].emplace_back(key, value); } pair<u64, T> pop() { if (v[0].empty()) { int idx = 1; while (v[idx].empty()) ++idx; last = min_element(begin(v[idx]), end(v[idx]))->first; for (auto &p : v[idx]) v[getbit(p.first ^ last)].emplace_back(p); v[idx].clear(); } --size; auto ret = v[0].back(); v[0].pop_back(); return ret; }}; /*radix_heap こっちの方が早い*/ vi dijkstra(const graph<int> &g, int s, int init_value = -1) { if (!(0 <= s && s < g.n)) { debugline("dijkstra"); deb(s, g.n); ole(); } /*O((N+M) log N) vs O(N^2)*/ if ((g.n + sz(g.edges)) * 20 > g.n * g.n) { return dijkstra_mitu(g, s, init_value); } int initValue = MAX(int); vi dis(g.n, initValue); radixheap<int> q; dis[s] = 0; q.push(0, s); while (!q.empty()) { int nowc, i; tie(nowc, i) = q.pop(); if (dis[i] != nowc)continue; for (auto &&e : g.g[i]) { int to = e.t; int c = nowc + e.c; if (dis[to] > c) { dis[to] = c; q.push(dis[to], to); } } } /*基本、たどり着かないなら-1*/ for (auto &&d :dis) if (d == initValue)d = init_value; return dis;} template<class T> vector<T> dijkstra_normal(const graph<T> &g, int s, int init_value = -1) { if (!(0 <= s && s < g.n)) { debugline("dijkstra"); deb(s, g.n); ole(); } if ((g.n + sz(g.edges)) * 20 > g.n * g.n) { return dijkstra_mitu(g, s, init_value); } T initValue = MAX(T); vector<T> dis(g.n, initValue); priority_queue<pair<T, int>, vector<pair<T, int>>, greater<pair<T, int>>> q; dis[s] = 0; q.emplace(0, s); while (q.size()) { T nowc = q.top().fi; int i = q.top().se; q.pop(); if (dis[i] != nowc)continue; for (auto &&e : g.g[i]) { int to = e.t; T c = nowc + e.c; if (dis[to] > c) { dis[to] = c; q.emplace(dis[to], to); } } } /*基本、たどり着かないなら-1*/ for (auto &&d :dis) if (d == initValue)d = init_value; return dis;} template<class T> vector<T> dijkstra_01(graph<T> &g, int s) { int N = g.n; vi dis(N, linf); dis[s] = 0; deque<int> q; q.push_back(s); vb was(N); while (!q.empty()) { int f = q.front(); q.pop_front(); if (was[f])continue; was[f] = true; fora(e, g[f]) { if (dis[e.t] > dis[f] + e.c) { if (e.c) { dis[e.t] = dis[f] + 1; q.push_back(e.t); } else { dis[e.t] = dis[f]; q.push_front(e.t); } } } } return dis;} //dijkstra_cou<mint> : 数える型で書く return vp(dis,cou) template<class COU,class T=int> auto dijkstra_cou(const graph<T> &g, int s, int init_value = -1) { if (!(0 <= s && s < g.n)) { debugline("dijkstra"); deb(s, g.n); ole(); } err("count by type COU "); err("int or mint"); T initValue = MAX(T); vector<T> dis(g.n, initValue); vector<COU> cou(g.n); cou[s] = 1; priority_queue<pair<T, int>, vector<pair<T, int>>, greater<pair<T, int>>> q; dis[s] = 0; q.emplace(0, s); while (q.size()) { T nowc = q.top().fi; int i = q.top().se; q.pop(); if (dis[i] != nowc)continue; for (auto &&e : g.g[i]) { int to = e.t; T c = nowc + e.c; if (dis[to] > c) { dis[to] = c; cou[to] = cou[e.f]; q.emplace(dis[to], to); } else if (dis[to] == c) { cou[to] += cou[e.f]; } } } /*基本、たどり着かないなら-1*/ for (auto &&d :dis) if (d == initValue)d = init_value; return vtop(dis, cou);} //密グラフの時、warshallに投げる template<class T> vector<vector<T>> dijkstra_all(const graph<T> &g, int init_value = -1) {int n = g.n;assert(n < 1e4);if (n * n < (n + sz(g.edges)) * 14) { /*O(N^3) vs O(N (N+M)log N)*/ return warshall(g, init_value); }vector<vector<T>> dis(n);rep(i, n) { dis[i] = dijkstra(g, i, init_value); }return dis;} //コストを無限に減らせる := -linf //たどり着けない := linf template<class T> vector<T> bell(graph<T> &g, int s) { if (g.n >= 1e4) { cout << "bell size too big" << endl; exit(0); } vector<T> res(g.n, linf); res[s] = 0; vb can(g.n); /*頂点から行けない頂点を持つ、辺を消しておく */ fix([&](auto ds, int p, int i) -> void { if (can[i])return; can[i] = true; forg(gi, g[i])if (t != p)ds(i, t); })(-1, 0); vector<edge<T>> es; fora(e, g.edges) { if (can[e.f])es += e; } rep(i, g.n) { bool upd = false; fora(e, es) { if (res[e.f] != linf && res[e.t] > res[e.f] + e.c) { upd = true; res[e.t] = res[e.f] + e.c; } } if (!upd)break; } rep(i, g.n * 2) { bool upd = 0; fora(e, g.edges) { if (res[e.f] != linf && res[e.t] != -linf && res[e.t] > res[e.f] + e.c) { upd = 1; res[e.t] = -linf; } } if (!upd)break; } return res;} //コストを無限に増やせる := linf //たどり着けない := -linf template<class T> vector<T> bell_far(graph<T> &g, int s) { if (g.n >= 1e4) { cout << "bell_far size too big" << endl; exit(0); } vector<T> res(g.n, linf); res[s] = 0; vb can(g.n); /*頂点から行けない頂点を持つ、辺を消しておく*/ fix([&](auto ds, int p, int i) -> void { if (can[i])return; can[i] = true; forg(gi, g[i])if (t != p)ds(i, t); })(-1, 0); vector<edge<T>> es; fora(e, g.edges) { if (can[e.f])es += e; } rep(i, g.n) { bool upd = false; fora(e, es) { if (res[e.f] != linf && res[e.t] > res[e.f] - e.c) {/*-c*/ upd = true; res[e.t] = res[e.f] - e.c;/*-c*/ } } if (!upd)break; } rep(i, g.n * 2) { bool upd = 0; fora(e, g.edges) { if (res[e.f] != linf && res[e.t] != -linf && res[e.t] > res[e.f] - e.c) {/*-c*/ upd = 1; res[e.t] = -linf; } } if (!upd)break; } rep(i, g.n)res[i] *= -1; return res;} template<class T> vector<vector<T>> warshall(const graph<T> &g, int init_value = -1) { int n = g.n; assert(n < 1e4); vector<vector<T> > dis(n, vector<T>(n, linf)); rep(i, n)fora(e, g.g[i]) { if (dis[e.f][e.t] > e.c) { dis[e.f][e.t] = e.c; } } rep(i, n)dis[i][i] = 0; rep(k, n) rep(i, n) rep(j, n) { if (dis[i][j] > dis[i][k] + dis[k][j]) { dis[i][j] = dis[i][k] + dis[k][j]; } } rep(i, n)rep(j, n) if (dis[i][j] == linf)dis[i][j] = init_value; return dis;} template<class T> class MinOp { public: T operator()(T a, T b) { return min(a, b); }}; template<typename OpFunc> struct SparseTable { OpFunc op; signed size; vector<signed> lg; vector<vector<pair<signed, signed>>> table; void init(const vector<pair<signed, signed>> &array, OpFunc opfunc) { signed n = array.size(); op = opfunc; lg.assign(n + 1, 0); for (signed i = 1; i <= n; i++) { lg[i] = 31 - __builtin_clz(i); } table.assign(lg[n] + 1, array); for (signed i = 1; i <= lg[n]; i++) { for (signed j = 0; j < n; j++) { if (j + (1 << (i - 1)) < n) { table[i][j] = op(table[i - 1][j], table[i - 1][j + (1 << (i - 1))]); } else { table[i][j] = table[i - 1][j]; }}} } pair<signed, signed> query(signed l, signed r) { assert(l < r); return op(table[lg[r - l]][l], table[lg[r - l]][r - (1 << lg[r - l])]); }}; struct PMORMQ { vector<signed> a; SparseTable<MinOp<pair<signed, signed> > > sparse_table; vector<vector<vector<signed> > > lookup_table; vector<signed> block_type; signed block_size, n_block; void init(const vector<signed> &array) { a = array; signed n = a.size(); block_size = std::max(1, (31 - __builtin_clz(n)) / 2); while (n % block_size != 0) { a.push_back(a.back() + 1); n++; } n_block = n / block_size; vector<pair<signed, signed> > b(n_block, make_pair(INT_MAX, INT_MAX)); for (signed i = 0; i < n; i++) { b[i / block_size] = min(b[i / block_size], make_pair(a[i], i)); } sparse_table.init(b, MinOp<pair<signed, signed> >()); block_type.assign(n_block, 0); for (signed i = 0; i < n_block; i++) { signed cur = 0; for (signed j = 0; j < block_size - 1; j++) { signed ind = i * block_size + j; if (a[ind] < a[ind + 1]) { cur |= 1 << j; } } block_type[i] = cur; } lookup_table.assign(1 << (block_size - 1), vector<vector<signed> >(block_size, vector<signed>(block_size + 1))); for (signed i = 0; i < (1 << (block_size - 1)); i++) { for (signed j = 0; j < block_size; j++) { signed res = 0; signed cur = 0; signed pos = j; for (signed k = j + 1; k <= block_size; k++) { lookup_table[i][j][k] = pos; if (i & (1 << (k - 1))) { cur++; } else { cur--; } if (res > cur) { pos = k; res = cur; } } } } } signed query(signed l, signed r) { assert(l < r); signed lb = l / block_size; signed rb = r / block_size; if (lb == rb) { return lb * block_size + lookup_table[block_type[lb]][l % block_size][r % block_size]; } signed pl = lb * block_size + lookup_table[block_type[lb]][l % block_size][block_size]; signed pr = rb * block_size + lookup_table[block_type[rb]][0][r % block_size]; signed pos = pl; if (r % block_size > 0 && a[pl] > a[pr]) { pos = pr; } if (lb + 1 == rb) { return pos; } signed spv = sparse_table.query(lb + 1, rb).second; if (a[pos] > a[spv]) { return spv; } return pos; }}; template<class T=int> class tree : public undigraph<T> {PMORMQ rmq; int cnt; vector<signed> id, in; bool never = true; bool never_hld = true; void dfs(int x, int p, int d, int dis = 0) { id[cnt] = x; par[x] = p; rmq_dep.push_back(d); disv[x] = dis; in[x] = cnt++; forg(gi, g[x]) { if (t == p) { continue; } dfs(t, x, d + 1, dis + c); id[cnt] = x; rmq_dep.push_back(d); cnt++; } } void precalc() { never = false; cnt = 0; rmq_dep.clear(); disv.assign(n, 0); in.assign(n, -1); id.assign(2 * n - 1, -1); par.assign(n, -1); dfs(root, -1, 0); rmq.init(rmq_dep); #ifdef _DEBUG if(n>=100)return;cerr << "---tree---" << endl; rep(i, n) { if (!(i == root || sz(g[i]) > 1))continue; cerr << i << " -> "; vi ts; forg(gi, g[i]) { if (t != par[i])ts.push_back(t); } rep(i, sz(ts) - 1)cerr << ts[i] << ", "; if(sz(ts))cerr << ts.back() << endl; } cerr << endl; #endif } int pos; void hld_build() { never_hld = false; if (never)precalc(); g.resize(n); vid.resize(n, -1); head.resize(n); heavy.resize(n, -1); depth.resize(n); inv.resize(n); subl.resize(n); subr.resize(n); dfs(root, -1); t = 0; dfs_hld(root); #ifdef _DEBUG if(n>=100)return;cerr << "---hld_index---" << endl; vi inds; rep(i, n) if (sz(g[i]))inds.push_back(i); rep(i, sz(inds)) { str s = tos(bel(inds[i])); cerr << std::right << std::setw(sz(s) + (i ? 1 : 0)) << inds[i]; } cerr << endl; rep(i, sz(inds)) { cerr << bel(inds[i]) << " "; } cerr << endl << endl; cerr << "---hld_edge_index---" << endl; fora(e, edges) { if (e.f <= e.t) cerr << e.f << "-" << e.t << " " << bel(e) << endl; } cerr << endl << endl; cerr << "!!edge or not edge carefull!!" << endl; cerr << "!!if(f<t) seg.add(bel(f,t),c) carefully(f,t) (t,f)!!" << endl; #endif } int dfs(int curr, int prev) { int sub = 1, max_sub = 0; heavy[curr] = -1; forg(i, g[curr]) { int next = t; if (next != prev) { depth[next] = depth[curr] + 1; int sub_next = dfs(next, curr); sub += sub_next; if (max_sub < sub_next) max_sub = sub_next, heavy[curr] = next; } } return sub; } int t = 0; void dfs_hld(int v = 0) { vid[v] = subl[v] = t; t++; inv[subl[v]] = v; if (0 <= heavy[v]) { head[heavy[v]] = head[v]; dfs_hld(heavy[v]); } forg(i, g[v])if (depth[v] < depth[t]) if (t != heavy[v]) { head[t] = t; dfs_hld(t); } subr[v] = t; }vector<signed> rmq_dep; public: using undigraph<T>::g; using undigraph<T>::n; using undigraph<T>::edges; vector<int> disv; //部分木の [左端、右端) index //部分木の辺に加算する場合 //add(subl[i],subr[i],x) //add(sub[i],sub[i+1],-x) vector<int> vid, head, heavy, par, depth, inv, subl, subr; int root; tree(int n_, int root = 0) : undigraph<T>(n_), root(root) { n = n_; } int lca(int a, int b) { if (never)precalc(); int x = in[a]; int y = in[b]; if (x > y) { swap(x, y); } int pos = rmq.query(x, y + 1); return id[pos]; } int dis(int a, int b) { if (never)precalc(); int x = in[a]; int y = in[b]; if (x > y) { swap(x, y); } int pos = rmq.query(x, y + 1); int p = id[pos]; return disv[a] + disv[b] - disv[p] * 2; } /*O(N) hldを使わず木を普通にたどる*/ void for_each_l(int u, int v, function<void(int)> fnode) { int r = lca(u, v); while (u != r) { fnode(u); u = par[u]; } while (v != r) { fnode(v); v = par[v]; } fnode(r); } void for_each_edge_l/*O(N) 頂点に対しての処理順が可換*/(int u, int v, function<void(edge<int> &)> fedge) { int r = lca(u, v); auto sub = [&](int u, int r) { while (u != r) { forg(gi, g[u]) { if (t == par[u]) { fedge(g[u][gi]); u = par[u]; break; } } } }; sub(u, r); sub(v, r); } //Fは半開 (u,v)は木の頂点 //中ではhldの頂点を見るため、seg木のupdateはhldのindexで行なう void for_each_/*[l,r)*/(int u, int v, const function<void(int, int)> &f) { if (never_hld)hld_build(); while (1) { if (vid[u] > vid[v]) swap(u, v); int l = max(vid[head[v]], vid[u]); int r = vid[v] + 1; f(l, r); if (head[u] != head[v]) v = par[head[v]]; else break; } } void for_each_edge/*[l,r) O(log(N)) 辺を頂点として扱っている 上と同じ感じで使える*/(int u, int v, const function<void(int, int)> &f) { if (never_hld)hld_build(); while (1) { if (vid[u] > vid[v]) swap(u, v); if (head[u] != head[v]) { int l = vid[head[v]]; int r = vid[v] + 1; f(l, r); v = par[head[v]]; } else { if (u != v) { int l = vid[u] + 1; int r = vid[v] + 1; f(l, r); } break; } } } int bel(int v) { /*hld内での頂点番号を返す*/ if (never_hld)hld_build();return vid[v];} //下の頂点に辺のクエリを持たせている int bel(int f, int t) { /*辺のクエリを扱うときどの頂点に持たせればいいか(vidを返すのでそのままupd出来る)*/ if (never_hld)hld_build();return depth[f] > depth[t] ? vid[f] : vid[t];} int bel(edge<T> &e) { /*辺のクエリを扱うときどの頂点に持たせればいいか(vidを返すのでそのままupd出来る)*/ if (never_hld)hld_build();return depth[e.f] > depth[e.t] ? vid[e.f] : vid[e.t];} template<class ... U> int operator()(U ... args) { return bel(args...); } //path l -> r += v template<class S> void seg_add(S &seg, int lhei, int rhei, int v) {for_each_(lhei, rhei, [&](int l, int r) { seg.add(l, r, v); });} template<class S> void seg_update(S &seg, int lhei, int rhei, int v) {for_each_(lhei, rhei, [&](int l, int r) { seg.update(l, r, v); });} template<class S> int seg_get(S &seg, int lhei, int rhei) { int res = 0; for_each_(lhei, rhei, [&](int l, int r) { res += seg.get(l, r); }); return res; } template<class S> void seg_add_edge(S &seg, int lhei, int rhei, int v) {for_each_edge(lhei, rhei, [&](int l, int r) { seg.add(l, r, v); });} template<class S> void seg_update_edge(S &seg, int lhei, int rhei, int v) {for_each_edge(lhei, rhei, [&](int l, int r) { seg.update(l, r, v); });} template<class S> int seg_get_edge(S &seg, int lhei, int rhei) {int res = 0;for_each_edge(lhei, rhei, [&](int l, int r) { res += seg.get(l, r); });return res;} //部分木iに対するクエリ template<class S> void seg_add_sub(S &seg, int i, int v) {if (never_hld)hld_build();seg.add(subl[i], subr[i], v);} template<class S> void seg_update_sub(S &seg, int i, int v) {if (never_hld)hld_build();seg.update(subl[i], subr[i], v);} template<class S> int seg_get_sub(S &seg, int i, int v) {if (never_hld)hld_build();return seg.get(subl[i], subr[i], v);} template<class S> void seg_add_sub_edge(S &seg, int i, int v) {if (never_hld)hld_build();/*iの上の辺が数えられてしまうため、i+1から*/seg.add(subl[i] + 1, subr[i], v);} template<class S> void seg_update_sub_edge(S &seg, int i, int v) {if (never_hld)hld_build();/*iの上の辺が数えられてしまうため、i+1から*/seg.update(subl[i] + 1, subr[i], v);} template<class S> int seg_get_sub_edge(S &seg, int i, int v) {if (never_hld)hld_build();/*iの上の辺が数えられてしまうため、i+1から*/return seg.get(subl[i] + 1, subr[i], v);} }; //辺が多いのでedgesを持たない //cost oo, ox, xo, xx 渡す template<class T=int> class grid_k6 : public undigraph<T> { vi costs; public: using undigraph<T>::g; using undigraph<T>::n; using undigraph<T>::edges; int H, W; vector<vector<char>> ba; char wall; void add(int f, int t, T c = 1){ cout << "grid" << endl; if (!(0 <= f && f < n && 0 <= t && t < n)) { debugline("grid_k6 add"); deb(f, t, c); ole(); } g[f].emplace_back(f, t, c); g[t].emplace_back(t, f, c); //undigraphと違い、edgesを持たない } int getid(int h, int w) { assert(ins(h, w, H, W)); return W * h + w; } int getid(P p) { return getid(p.first, p.second); } P get2(int id) { return mp(id / W, id % W); } P operator()(int id) { return get2(id); } int operator()(int h, int w) { return getid(h, w); } int operator()(P p) { return getid(p); } //辺は無い grid_k6(int H, int W) : H(H), W(W), undigraph<T>(H * W) {} grid_k6(vector<vector<char>> ba, char wall = '#') : H(sz(ba)), W(sz(ba[0])), undigraph<T>(sz(ba) * sz(ba[0])) { rep(h, H) { rep(w, W) { if (ba[h][w] == wall)con; int f = getid(h, w); if (w + 1 < W && ba[h][w + 1] != wall) { add(f, getid(h, w + 1)); } if (h + 1 < H && ba[h + 1][w] != wall) { add(f, getid(h + 1, w)); } } } } /*o -> o, o -> x, x-> x*/ grid_k6(vector<vector<char>> ba, int oo, int ox, int xo, int xx, char wall = '#') : H(sz(ba)), W(sz(ba[0])), undigraph<T>(sz(ba) * sz(ba[0])), costs({oo, ox, xo, xx}), ba(ba), wall(wall) { rep(h, H) { rep(w, W) { add(h, w, h + 1, w); add(h, w, h - 1, w); add(h, w, h, w + 1); add(h, w, h, w - 1); } } } void add(int fh, int fw, int th, int tw) { if (ins(fh, fw, H, W) && ins(th, tw, H, W)) { int cm = 0; if (ba[fh][fw] == wall) { cm += 2; } if (ba[th][tw] == wall) { cm++; } int f = getid(fh, fw); int t = getid(th, tw); g[f].emplace_back(f, t, costs[cm]); } } void set_edges() { rep(i, n)fora(e, g[i])if (e.f < e.t)edges.push_back(e); } }; //辺によりメモリを大量消費ためedgesを消している //頂点10^6でメモリを190MB(制限の8割)使う //左上から右下に移動できる template<class T=int> class digrid_k6 : public digraph<T> { public: using digraph<T>::g; using digraph<T>::n; using digraph<T>::edges; int H, W; void add(int f, int t, T c = 1) { if (!(0 <= f && f < n && 0 <= t && t < n)) { debugline("digrid_k6 add"); deb(f, t, c); ole(); } g[f].emplace_back(f, t, c); /*digraphと違いedgesを持たない*/ } int getid(int h, int w) { if (!ins(h, w, H, W))return -1; return W * h + w; } P get2(int id) { return mp(id / W, id % W); } P operator()(int id) { return get2(id); } int operator()(int h, int w) { return getid(h, w); } digrid_k6(int H, int W) : H(H), W(W), digraph<T>(H * W) { rep(h, H) { rep(w, W) { int f = getid(h, w); if (w + 1 < W) add(f, getid(h, w + 1)); if (h + 1 < H)add(f, getid(h + 1, w)); } } } digrid_k6(vector<vector<char>> ba, char wall = '#') : H(sz(ba)), W(sz(ba[0])), digraph<T>(sz(ba) * sz(ba[0])) { rep(h, H) { rep(w, W) { if (ba[h][w] == wall)con; int f = getid(h, w); if (w + 1 < W && ba[h][w + 1] != wall) { add(f, getid(h, w + 1)); } if (h + 1 < H && ba[h + 1][w] != wall) { add(f, getid(h + 1, w)); } } } } void add(int fh, int fw, int th, int tw) { add(getid(fh, fw), getid(th, tw)); } void set_edges() { rep(i, n)fora(e, g[i])edges.push_back(e); } }; //@出力 template<class T> ostream &operator<<(ostream &os, digraph<T> &g) { os << endl << g.n << " " << sz(g.edges) << endl; fore(gi, g.edges) { os << f << " " << t << " " << c << endl; } return os;}template<class T> ostream &operator<<(ostream &os, undigraph<T> &g) { os << endl << g.n << " " << sz(g.edges) << endl; fore(gi, g.edges) { if (f < t)os << f << " " << t << " " << c << endl; } return os;} //@判定 template<class T> bool nibu(const graph<T> &g) {int size = 0; rep(i, g.n)size += sz(g.g[i]); if (size == 0)return true; unionfind uf(g.n * 2); rep(i, g.n)fora(e, g.g[i])uf.unite(e.f, e.t + g.n), uf.unite(e.f + g.n, e.t); rep(i, g.n)if (uf.same(i, i + g.n))return 0; return 1;} //二部グラフを色分けした際の頂点数を返す template<class T> vp nibug(graph<T> &g) { vp cg; if (!nibu(g)) { debugline("nibu"); ole(); } int n = g.size(); vb was(n); queue<P> q; rep(i, n) { if (was[i])continue; q.push(mp(i, 1)); was[i] = 1; int red = 0; int coun = 0; while (q.size()) { int now = q.front().fi; int col = q.front().se; red += col; coun++; q.pop(); forg(gi, g[now]) { if (was[t])continue; q.push(mp(t, col ^ 1)); was[t] = 1; } } cg.push_back(mp(red, coun - red)); } return cg;} //連結グラフが与えられる 閉路があるか template<class T> bool close(undigraph<T> &g) { int n = 0; int e = 0; rep(i, g.n) { if (sz(g[i]))n++; forg(gi, g[i]) { e++; } } return (e >> 1) >= n;} template<class T> bool close(undigraph<T> &g, int v) { unionfind uf(g.n); rep(i, g.n) { forg(gi, g[i]) { if (f < t)break; if (f == t && f == v)return true; if (uf.same(f, v) && uf.same(t, v))return true; uf.unite(f, t); } } return false;}template<class T> bool close(digraph<T> &g) { vi res; return topo(res, g);} //@変形 //閉路がなければtrue bool topo(vi &res, digraph<int> &g) { int n = g.g.size(); vi nyu(n); rep(i, n)for (auto &&e :g[i])nyu[e.t]++; queue<int> st; rep(i, n)if (nyu[i] == 0)st.push(i); while (st.size()) { int v = st.front(); st.pop(); res.push_back(v); fora(e, g[v]) if (--nyu[e.t] == 0)st.push(e.t); } return res.size() == n;} //辞書順最小トポロジカルソート bool topos(vi &res, digraph<int> &g) { int n = g.g.size(); vi nyu(n); rep(i, n)for (auto &&e :g[i])nyu[e.t]++; /*小さい順*/ priority_queue<int, vector<int>, greater<int> > q; rep(i, n)if (nyu[i] == 0)q.push(i); while (q.size()) { int i = q.top(); q.pop(); res.push_back(i); fora(e, g[i])if (--nyu[e.t] == 0)q.push(e.t); } return res.size() == n;} template<class T> digraph<T> rev(digraph<T> &g) { digraph<T> r(g.n); rep(i, g.n) { forg(gi, g[i]) { r.add(t, f, c); }} return r;} //lc,rcは子を持つ中で一番左、右 //(g,ind,l,r) template<class T> tree<T> get_bfs_tree(tree<T> &g, vi &ind, vi &l, vi &r) {if (sz(ind)) {cerr << "ind must be empty" << endl;exit(0);}int N = sz(g);ind.resize(N);l.resize(N, inf);r.resize(N, -1);tree<T> h(N);queue<P> q;q.emplace(-1, 0);int c = 0;while (sz(q)) {int p = q.front().first;int i = q.front().second;q.pop();ind[i] = c;if (~p)chmi(l[ind[p]], c);if (~p)chma(r[ind[p]], c);c++;forg(gi, g[i]) {if (t != p)q.emplace(i, t);}}fora(e, g.edges) {if (e.f < e.t) {h.add(ind[e.f], ind[e.t], e.c);}}rep(i, N) {if (l[i] == inf)l[i] = -1;}return h;} //lc,rcは子を持つ中で一番左、右 // たとえばl[lc[x]は2段下の最左 //(g,ind,l,r,lc,rc) template<class T> tree<T> get_bfs_tree(tree<T> &g, vi &ind, vi &l, vi &r, vi &lc, vi &rc) { if (sz(ind)) { cerr << "ind must be empty" << endl; exit(0); } int N = sz(g); ind.resize(N); l.resize(N, inf); lc.resize(N, inf); r.resize(N, -1); rc.resize(N, -1); tree<T> h(N); queue<P> q; q.emplace(-1, 0); int c = 0; while (sz(q)) { int p = q.front().first; int i = q.front().second; q.pop(); ind[i] = c; if (~p) { chmi(l[ind[p]], c); chma(r[ind[p]], c); if (sz(g[i]) > 1) { chmi(lc[ind[p]], c); chma(rc[ind[p]], c); } } c++; forg(gi, g[i]) { if (t != p)q.emplace(i, t); } } fora(e, g.edges) { if (e.f < e.t) { h.add(ind[e.f], ind[e.t], e.c); } } rep(i, N) { if (l[i] == inf)l[i] = -1; if (lc[i] == inf)lc[i] = -1; } return h;} //@集計 template<class T> vi indegree(graph<T> &g) {vi ret(g.size());rep(i, g.size()) { forg(gi, g[i]) { ret[t]++; }}return ret;} template<class T> vi outdegree(graph<T> &g) {vi ret(g.size());rep(i, g.size()) { ret[i] = g[i].size(); }return ret;} #define kansetu articulation P farthest(undigraph<> &E, int cur, int pre, int d, vi &D) { D[cur] = d; P r = {d, cur}; forg(gi, E[cur]) if (t != pre) { P v = farthest(E, t, cur, d + 1, D); r = max(r, v); } return r;} //dagでなければ-1を返す int diameter(digraph<> &g) { vi per; if (!topo(per, g))return -1; int n = g.n; vi dp(n, 1); fora(v, per) { forg(gi, g[v]) { chma(dp[t], dp[f] + 1); }} return max(dp);} //iから最も離れた距離 vi diameters(undigraph<> &E) { /* diameter,center*/vi D[3]; D[0].resize(E.size()); D[1].resize(E.size()); auto v1 = farthest(E, 0, 0, 0, D[0]); auto v2 = farthest(E, v1.second, v1.second, 0, D[0]); farthest(E, v2.second, v2.second, 0, D[1]); int i; rep(i, D[0].size()) D[2].push_back(max(D[0][i], D[1][i])); return D[2];} int diameter(undigraph<> &E) {vi d = diameters(E);return max(d);} //i d vp diameter_p(undigraph<> &E) { /* diameter,center*/vector<int> D[3]; D[0].resize(E.size()); D[1].resize(E.size()); auto v1 = farthest(E, 0, 0, 0, D[0]); auto v2 = farthest(E, v1.second, v1.second, 0, D[0]); farthest(E, v2.second, v2.second, 0, D[1]); int i; vp res(E.size()); rep(i, D[0].size()) { if (D[0][i] > D[1][i])res[i] = mp(D[0][i], v1.second); else res[i] = mp(D[1][i], v2.second); } return res;} //@列挙 取得 //閉路がある時linfを返す template<class T> int longest_path(digraph<T> &g) { vi top; if (!topo(top, g)) { return linf; } int n = sz(top); vi dp(n, 0); for (auto &&i : top) { forg(gi, g[i]) { chma(dp[t], dp[i] + 1); }} return max(dp);} template<class T> vi longest_path_v(digraph<T> &g) { vi top; if (!topo(top, g)) { return vi(); } int n = sz(top); vi dp(n, 0); vi pre(n, -1); for (auto &&i : top) { forg(gi, g[i]) { if (chma(dp[t], dp[i] + 1)) { pre[t] = i; }}} int s = std::max_element(dp.begin(), dp.end()) - dp.begin(); vi path; while (s != -1) { path.push_back(s); s = pre[s]; } std::reverse(path.begin(), path.end()); return path;} //橋を列挙する (取り除くと連結でなくなる辺) template<class T> vp bridge(graph<T> &G) { static bool was; vp brid; vi articulation; vi ord(G.n), low(G.n); vb vis(G.n); function<void(int, int, int)> dfs = [&](int v, int p, int k) { vis[v] = true; ord[v] = k++; low[v] = ord[v]; bool isArticulation = false; int ct = 0; for (int i = 0; i < G[v].size(); i++) { if (!vis[G[v][i].t]) { ct++; dfs(G[v][i].t, v, k); low[v] = min(low[v], low[G[v][i].t]); if (~p && ord[v] <= low[G[v][i].t]) isArticulation = true; if (ord[v] < low[G[v][i].t]) brid.push_back(make_pair(min(v, G[v][i].t), max(v, G[v][i].t))); } else if (G[v][i].t != p) { low[v] = min(low[v], ord[G[v][i].t]); } } if (p == -1 && ct > 1) isArticulation = true; if (isArticulation) articulation.push_back(v); }; int k = 0; rep(i, G.n) { if (!vis[i]) dfs(i, -1, k); } sort(brid.begin(), brid.end()); return brid;} //間接点を列挙する (取り除くと連結でなくなる点) template<class T> vi articulation(undigraph<T> &G) { static bool was; vp bridge; vi arti; vi ord(G.n), low(G.n); vb vis(G.n); function<void(int, int, int)> dfs = [&](int v, int p, int k) { vis[v] = true; ord[v] = k++; low[v] = ord[v]; bool isArticulation = false; int ct = 0; for (int i = 0; i < G[v].size(); i++) { if (!vis[G[v][i].t]) { ct++; dfs(G[v][i].t, v, k); low[v] = min(low[v], low[G[v][i].t]); if (~p && ord[v] <= low[G[v][i].t]) isArticulation = true; if (ord[v] < low[G[v][i].t]) bridge.push_back(make_pair(min(v, G[v][i].t), max(v, G[v][i].t))); } else if (G[v][i].t != p) { low[v] = min(low[v], ord[G[v][i].t]); } } if (p == -1 && ct > 1) isArticulation = true; if (isArticulation) arti.push_back(v); }; int k = 0; rep(i, G.n) { if (!vis[i]) dfs(i, -1, k); } sort(arti.begin(), arti.end()); return arti;} //閉路パスを一つ返す vi close_path(digraph<> &g) { int n = g.n; vi state(n); vi path; rep(i, n) if (!state[i]) { if (fix([&](auto dfs, int v) -> bool { if (state[v]) { if (state[v] == 1) { path.erase(path.begin(), find(path.begin(), path.end(), v)); return true; } return false; } path.push_back(v); state[v] = 1; forg(gi, g[v]) { if (dfs(t))return true; } state[v] = -1; path.pop_back(); return false; })(i)) { return path; } } return vi();} vi close_path_min(digraph<> &g) { int n = g.n; vvi(dis, n); rep(i, n)dis[i] = dijkstra(g, i, linf); int mind = linf; int f = 0, t = 0; rep(i, n) { rep(j, n) { if (i == j)continue; if (chmi(mind, dis[i][j] + dis[j][i])) { f = i; t = j; } } } vi path; auto add = [&](int f, int t) { int now = f; while (now != t) { rep(i, n) { if (dis[now][i] == 1 && dis[f][i] + dis[i][t] == dis[f][t]) { path.push_back(i); now = i; break; } } } }; add(f, t); add(t, f); return path;} /*閉路が1つしかない場合、その閉路に含まれる頂点を1としたvectorを返す*/; template<class T> vi get_close1(digraph<T> &g) { int n = g.n; queue<int> q; vi d = outdegree(g); vi res(n, 1); rep(i, n) { if (d[i] == 0) { q += i; res[i] = 0; } } auto rg = rev(g); while (q.size()) { auto now = q.front(); q.pop(); forg(gi, rg[now]) { if (--d[t] == 0) { q += t; res[t] = 0; } } } return res;} //@アルゴリズム template<class T> int krus(undigraph<T> &g) { int res = 0; unionfind uf(g.n); if (sz(g.edges) == 0)g.set_edges(); int i = 0; auto E = g.edges; sort(E); fora(e, E) { if (uf.unite(e.f, e.t)) { res += e.c; }} return res;} template<class T> vector<edge<T>> krus_ed(undigraph<T> &g) { unionfind uf(g.n); if (sz(g.edges) == 0)g.set_edges(); int i = 0; auto E = g.edges; sort(E); vector<edge<T>> res; fora(e, E) { if (uf.unite(e.f, e.t)) { res.push_back(e); }} return res;} template<class T> tree<T> krus_tr(undigraph<T> &g) { tree<T> res(g.n); unionfind uf(g.n); if (sz(g.edges) == 0)g.set_edges(); int i = 0; auto E = g.edges; sort(E); fora(e, E) { if (uf.unite(e.f, e.t)) { res.add(e.f, e.t); }} return res;} //@実験 digraph<> rang_di(int n, int m, bool zibun = 0, bool taju = 0) { umapp was; digraph<> g(n); was[mp(-1, -2)] = 1; while (m) { int f = -1, t = -2; while (f < 0 || (!taju && was[mp(f, t)])) { f = rand(0, n - 1); t = rand(0, n - 1); if (!zibun && f == t)f = -1; } g.add(f, t); was[mp(f, t)] = 1; m--; } return g;} digraph<> perfect_di(int n, bool zibun = 0) { digraph<> g(n); rep(i, n) { rep(j, n) { if (!zibun && i == j)con; g.add(i, j); } } return g;} undigraph<> rang_un(int n, int m, bool zibun = 0, bool taju = 0) { umapp was; undigraph<> g(n); was[mp(-1, -2)] = 1; while (m) { int f = -1, t = -2; while (f < 0 || (!taju && was[mp(min(f, t), max(f, t))])) { f = rand(0, n - 1); t = rand(0, n - 1); if (!zibun && f == t)f = -1; } g.add(f, t); was[mp(min(f, t), max(f, t))] = 1; m--; } return g;} undigraph<> perfect_un(int n, bool zibun = 0){ undigraph<> g(n); rep(i, n) { rep(j, i, n) { if (!zibun && i == j)con; g.add(i, j); } } return g;} /*頂点数がkの木を一つ返す サイズが0の木が帰ったら終了*/ tree<int> next_tree(int k) { assert(2 <= k && k < 11); static str name; static ifstream ina; static int rem; static vp edges; static int pk = -1;/*前回見たk*/ if (pk != k) { if (~pk)ina.close(); edges.clear(); pk = k; name = (k == 6) ? "C:\\Users\\kaout\\Desktop\\trees_sizek\\nazeka6.txt" : "C:\\Users\\kaout\\Desktop\\trees_sizek\\tree_size" + tos(k) + ".txt"; ina = ifstream(name); rem = pow(k, k - 2);/*Cayleyの定理*/ rep(i, k)rep(j, i + 1, k)edges.emplace_back(i, j); pk = k; } tree<int> g(k); if (rem == 0) { g.resize(0); return g; } int m; ina >> m; while (m) { int lb = lbit(m); int id = log2(lb); g.add(edges[id].first, edges[id].second); m ^= lb; } rem--; return g;} undigraph<int> next_undi(int k) { assert(2 <= k && k < 9); static str name; static ifstream ina; static int rem; static vp edges; static vi lims = {-1, -1, 1, 4, 38, 728, 26704, 1866256}; static int pk = -1;/*前回見たk*/ if (pk != k) { if (~pk)ina.close(); edges.clear(); pk = k; name = (k == 6) ? "C:\\Users\\kaout\\Desktop\\undi_sizek\\roku.txt" : "C:\\Users\\kaout\\Desktop\\undi_sizek\\undi_size" + tos(k) + ".txt"; ina = ifstream(name); rem = lims[k]; rep(i, k)rep(j, i + 1, k)edges.emplace_back(i, j); pk = k; } undigraph<int> g(k); if (rem == 0) { g.resize(0); return g; } int m; ina >> m; while (m) { int lb = lbit(m); int id = log2(lb); g.add(edges[id].first, edges[id].second); m ^= lb; } rem--; return g;} vector<tree<int>> trees(int k) { vector<tree<int>> res; while (1) { tree<int> g = next_tree(k); if (sz(g) == 0)break; res.push_back(g); } return res;} vector<undigraph<int>> undis(int k) { vector<undigraph<int>> res; while (1) { undigraph<int> g = next_undi(k); if (sz(g) == 0)break; res.push_back(g); } return res;} /*@formatter:on*/ //type,idが使いたい場合はgraty digraph<> g(2 * k5); void solve() { in(n, m); rep(i, m) { int f, t, c; cin >> f >> t >> c; --f, --t; // g.add(f, t, -c); g.add(f, t, c); } // auto d = bell(g, 0); auto d = bell_far(g, 0); // if (d[n - 1] == -linf)fin("inf"); if (d[n - 1] == linf)fin("inf"); // else cout << -d[n - 1] << endl; else cout << d[n - 1] << endl; } auto my(ll n, vi &a) { return 0; } auto sister(ll n, vi &a) { ll ret = 0; return ret; } signed main() { solve(); #define arg n,a #ifdef _DEBUG bool bad = 0; for (ll i = 0, ok = 1; i < k5 && ok; ++i) { ll n = rand(1, 8); vi a = ranv(n, 1, 10); auto myres = my(arg); auto res = sister(arg); ok = myres == res; if (!ok) { out(arg); cerr << "AC : " << res << endl; cerr << "MY : " << myres << endl; bad = 1; break; } } if (!bad) { // cout << "完璧 : solveを書き直そう" << endl; // cout << " : そして、solve()を呼び出すのだ" << endl; // cout << " : cin>>n; na(a,n);も忘れるな" << endl; } #endif return 0; };
a.cc: In function 'auto dijkstra_cou(const graph<T>&, long long int, long long int)': a.cc:909:203: error: there are no arguments to 'err' that depend on a template parameter, so a declaration of 'err' must be available [-fpermissive] 909 | template<class COU,class T=int> auto dijkstra_cou(const graph<T> &g, int s, int init_value = -1) { if (!(0 <= s && s < g.n)) { debugline("dijkstra"); deb(s, g.n); ole(); } err("count by type COU "); err("int or mint"); T initValue = MAX(T); vector<T> dis(g.n, initValue); vector<COU> cou(g.n); cou[s] = 1; priority_queue<pair<T, int>, vector<pair<T, int>>, greater<pair<T, int>>> q; dis[s] = 0; q.emplace(0, s); while (q.size()) { T nowc = q.top().fi; int i = q.top().se; q.pop(); if (dis[i] != nowc)continue; for (auto &&e : g.g[i]) { int to = e.t; T c = nowc + e.c; if (dis[to] > c) { dis[to] = c; cou[to] = cou[e.f]; q.emplace(dis[to], to); } else if (dis[to] == c) { cou[to] += cou[e.f]; } } } /*基本、たどり着かないなら-1*/ for (auto &&d :dis) if (d == initValue)d = init_value; return vtop(dis, cou);} | ^~~ a.cc:909:203: note: (if you use '-fpermissive', G++ will accept your code, but allowing the use of an undeclared name is deprecated) a.cc:909:233: error: there are no arguments to 'err' that depend on a template parameter, so a declaration of 'err' must be available [-fpermissive] 909 | template<class COU,class T=int> auto dijkstra_cou(const graph<T> &g, int s, int init_value = -1) { if (!(0 <= s && s < g.n)) { debugline("dijkstra"); deb(s, g.n); ole(); } err("count by type COU "); err("int or mint"); T initValue = MAX(T); vector<T> dis(g.n, initValue); vector<COU> cou(g.n); cou[s] = 1; priority_queue<pair<T, int>, vector<pair<T, int>>, greater<pair<T, int>>> q; dis[s] = 0; q.emplace(0, s); while (q.size()) { T nowc = q.top().fi; int i = q.top().se; q.pop(); if (dis[i] != nowc)continue; for (auto &&e : g.g[i]) { int to = e.t; T c = nowc + e.c; if (dis[to] > c) { dis[to] = c; cou[to] = cou[e.f]; q.emplace(dis[to], to); } else if (dis[to] == c) { cou[to] += cou[e.f]; } } } /*基本、たどり着かないなら-1*/ for (auto &&d :dis) if (d == initValue)d = init_value; return vtop(dis, cou);} | ^~~
s288215499
p03722
C
#include<iostream> #include<vector> using namespace std; struct edge{long from,to,cost;}; long bellman_ford(int start){ long n,m,a; cin>>n>>m; edge es[m]; for(int i=0;i<m;i++){ cin>>es[i].from>>es[i].to>>es[i].cost; es[i].from--;es[i].to--;es[i].cost*=-1; } vector<long>dist(n,0x7fffffffffffff); dist[start]=0L; for(int i=0;i<n;i++){ for(int j=0;j<m;j++){ if(dist[es[j].to]>dist[es[j].from]+es[j].cost){ dist[es[j].to]=dist[es[j].from]+es[j].cost; } } } bool f[n]={}; for(int i=0;i<n;i++){ for(int j=0;j<m;j++){ if(dist[es[j].from]==0x7fffffffffffff)continue; if(dist[es[j].to]>dist[es[j].from]+es[j].cost){ dist[es[j].to]=dist[es[j].from]+es[j].cost; f[es[j].to]=true; } if(f[es[j].from]==true)f[es[j].to]=true; } } return f[n-1]?0x7fffffffffffff:dist[n-1]; } int main(){ long a=bellman_ford(0)*-1; if(a==0x7fffffffffffff*-1)cout<<"inf"<<endl; else cout<<a<<endl; return 0; }
main.c:1:9: fatal error: iostream: No such file or directory 1 | #include<iostream> | ^~~~~~~~~~ compilation terminated.
s975814328
p03722
C++
#include<iostream> #include<string> #include<string.h> #include<algorithm> #include<vector> #include<iomanip> #include<math.h> #include<complex> #include<queue> #include<deque> #include<stack> #include<map> #include<set> #include<bitset> using namespace std; #define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i ) #define rep(i,n) REP(i,0,n) typedef long long ll; typedef pair<int,int> pint; typedef pair<ll,int> pli; const int inf=1e9+7; const ll longinf=1000000000000 ; const ll mod=1000003 ; struct edge{int from,to,cost;}; edge es[200020]; ll d[200020]; int V,E; void shortest_path(int s){ for(int i=0;i<V;i++)d[i]=longinf; d[s]=0; while(true){ bool update=false; for(int i=0;i<E;i++){ edge e=es[i]; if(d[e.from]!=inf && d[e.to]>d[e.from]+e.cost){ d[e.to]=d[e.from]+e.cost; update=true; } } if(!update)break; } } bool find_negative_loop(){ memset(d,0,sizeof(d)); rep(i,V){ rep(j,E){ edge e=es[j]; if(d[e.to]>d[e.from]+e.cost){ d[e.to]=d[e.from]+e.cost; if(i==V-1)return true; } } } return false; } int main(){ int n,m; cin >> n >> m; rep(i,m){ int x,y,z; cin >> x >> y >> z; x--,y--; es[i]={x,y,-z}; } V=n; E=m; if(find_negative_loop()){ cout << "inf" << endl; return 0; } shortest_path(0); if(ng){ cout << "inf" << endl; return 0; } cout << -d[n-1] << endl; return 0;}
a.cc: In function 'int main()': a.cc:78:6: error: 'ng' was not declared in this scope; did you mean 'n'? 78 | if(ng){ | ^~ | n
s737563269
p03722
C++
#include<iostream> #include<string> #include<string.h> #include<algorithm> #include<vector> #include<iomanip> #include<math.h> #include<complex> #include<queue> #include<deque> #include<stack> #include<map> #include<set> #include<bitset> using namespace std; #define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i ) #define rep(i,n) REP(i,0,n) typedef long long ll; typedef pair<int,int> pint; typedef pair<ll,int> pli; const int inf=1e9+7; const ll longinf=1LL<<62 ; const ll mod=1000003 ; struct edge{int from,to,cost;}; edge es[200020]; ll d[200020]; int V,E; void shortest_path(int s){ for(int i=0;i<V;i++)d[i]=longinf; d[s]=0; while(true){ bool update=false; for(int i=0;i<E;i++){ edge e=es[i]; if(d[e.from]!=inf && d[e.to]>d[e.from]+e.cost){ d[e.to]=d[e.from]+e.cost; update=true; cnt++; } } if(!update)break; } } bool find_negative_loop(){ memset(d,0,sizeof(d)); rep(i,V){ rep(j,E){ edge e=es[j]; if(d[e.to]>d[e.from]+e.cost){ d[e.to]=d[e.from]+e.cost; if(i==V-1)return true; } } } return false; } int main(){ int n,m; cin >> n >> m; rep(i,m){ int x,y,z; cin >> x >> y >> z; x--,y--; es[i]={x,y,-z}; } V=n; E=m; if(find_negative_loop()){ cout << "inf" << endl; return 0; } shortest_path(0); if(ng){ cout << "inf" << endl; return 0; } cout << -d[n-1] << endl; return 0;}
a.cc: In function 'void shortest_path(int)': a.cc:42:9: error: 'cnt' was not declared in this scope; did you mean 'int'? 42 | cnt++; | ^~~ | int a.cc: In function 'int main()': a.cc:79:6: error: 'ng' was not declared in this scope; did you mean 'n'? 79 | if(ng){ | ^~ | n
s935362953
p03722
C++
#include <iostream> #include <vector> #include <utility> #include <algorithm> using namespace std; const long long int INF=1e14; vector<pair<pair<int, long long int>, int> > E; int main() { int N, M; cin >> N >> M; E.resize(M); for(int m=0; m<M; m++) { int a, b; long long int c; cin >> a >> b >> c; E[m]=make_pair(make_pair(a-1, b-1), -c); } vector<long long int> score(N, INF); score[0]=0; for(int n=0; n<N; n++) { for(int m=0; m<M; m++) { int from = E[m].first.first; int target = E[m].first.second; long long int cost = E[m].second; if(score[from]!=INF && score[target]>score[from]+cost) { if(n==N-1 && score[target]!=INF) { cout << "inf" << endl; return 0; } score[target] = score[from]+cost; // if(n==N-1) { // cout << "inf" << endl; // return 0; } } } } cout << -score[N-1] << endl; return 0; }
a.cc:46:5: error: 'cout' does not name a type 46 | cout << -score[N-1] << endl; | ^~~~ a.cc:48:5: error: expected unqualified-id before 'return' 48 | return 0; | ^~~~~~ a.cc:50:1: error: expected declaration before '}' token 50 | } | ^
s959699747
p03722
C++
#include <iostream> #include <stdio.h> #include <cmath> #include <algorithm> #include <climits> #include <vector> #include <iomanip> #include <string> #include <queue> #include <numeric> #include <functional> #include <array> #include <map> #include <set> #define INF /*1000000007*/ 1000000000000000003 #define MOD 1000000007 using namespace std; using P = pair<int, long long>; using T = tuple<int, int, int>; using edge = struct { int to; long long dist; }; vector<edge>tree[100010]; vector<P> connect[100005]; long long cost[100005]; bool compare_by_second(pair<int, int> a, pair<int, int> b) { if (a.second != b.second) { return a.second < b.second; } else { return a.first < b.first; } } int main() { int M; cin >> N >> M; for (int i = 0; i < M;++i) { int a, b; long long c; cin >> a >> b; cin >> c; --a, --b; connect[a].push_back(make_pair(b, -c)); } for (int i = 0; i < N;++i) { cost[i] = INF; } cost[0] = 0; bool isInf = false; for (int i = 0; i < N;++i) { for (int j = 0; j < N;++j) { for (P e : connect[j]) { if (cost[j] != INF && cost[j] + e.second < cost[e.first]) cost[e.first] = cost[j] + e.second; if (i == N - 1 && j == N - 1)isInf = true; } } } if (isInf)cout << "inf" << endl; else cout << -cost[N - 1] << endl; }
a.cc: In function 'int main()': a.cc:40:16: error: 'N' was not declared in this scope 40 | cin >> N >> M; | ^
s288036609
p03722
C++
from collections import deque N,M = map(int,input().split()) dic = {} for i in range(M): a,b,c = map(int,input().split()) a -= 1 b -= 1 if a not in dic: dic[a] = [] dic[a].append([b,c]) lis = [[0] * N for j in range(N)] lis[0][0] = 1 lmax = [0] * N lmax[0] = 1 mcost = [-1 * float("inf")] * N mcost[0] = 0 q = deque([]) q.append(0) cnt = 0 while len(q) > 0: now = q.pop() if now not in dic or lmax[now] > N: continue for npath in dic[now]: b = npath[0] c = npath[1] if mcost[now] + c > mcost[b]: mcost[b] = mcost[now] + c lis[b] = lis[now].copy() lmax[b] = lmax[now] lis[b][b] += 1 lmax[b] = max(lmax[b],lis[b][b]) if lmax[b] >= 2: mcost[b] = float("inf") q.append(b) if lis[N-1][N-1] != -1 * float("inf") and lmax[N-1] >= 2: mcost[N-1] = float("inf") break elif mcost[N-1] == float("inf"): break print (mcost[N-1])
a.cc:1:1: error: 'from' does not name a type 1 | from collections import deque | ^~~~ a.cc:8:1: error: expected unqualified-id before 'for' 8 | for i in range(M): | ^~~
s866777210
p03722
C++
#include <bits/stdc++.h> using namespace std; // macro----------------------------------------------------------------------------------------- #define rep(i, a, b) for (int i = a; i < b; i++) #define int long long const int inf = 100100100100000; const int mod = 1000000007; #define isvisiblechar(c) (0x21 <= (c) && (c) <= 0x7E) #define cin scanner #define cout printer namespace { class MaiScanner { public: template <typename T> void input_integer(T &var) { var = 0; T sign = 1; int cc = getchar_unlocked(); for (; cc < '0' || '9' < cc; cc = getchar_unlocked()) if (cc == '-') sign = -1; for (; '0' <= cc && cc <= '9'; cc = getchar_unlocked()) var = (var << 3) + (var << 1) + cc - '0'; var = var * sign; } inline int c() { return getchar_unlocked(); } inline MaiScanner &operator>>(int &var) { input_integer<int>(var); return *this; } inline MaiScanner &operator>>(long long &var) { input_integer<long long>(var); return *this; } inline MaiScanner &operator>>(string &var) { int cc = getchar_unlocked(); for (; !isvisiblechar(cc); cc = getchar_unlocked()) ; for (; isvisiblechar(cc); cc = getchar_unlocked()) var.push_back(cc); return *this; } template <typename IT> void in(IT begin, IT end) { for (auto it = begin; it != end; ++it) *this >> *it; } }; class MaiPrinter { public: template <typename T> void output_integer(T var) { if (var == 0) { putchar_unlocked('0'); return; } if (var < 0) putchar_unlocked('-'), var = -var; char stack[32]; int stack_p = 0; while (var) stack[stack_p++] = '0' + (var % 10), var /= 10; while (stack_p) putchar_unlocked(stack[--stack_p]); } inline MaiPrinter &operator<<(char c) { putchar_unlocked(c); return *this; } inline MaiPrinter &operator<<(int var) { output_integer<int>(var); return *this; } inline MaiPrinter &operator<<(long long var) { output_integer<long long>(var); return *this; } inline MaiPrinter &operator<<(char *str_p) { while (*str_p) putchar_unlocked(*(str_p++)); return *this; } inline MaiPrinter &operator<<(const string &str) { const char *p = str.c_str(); const char *l = p + str.size(); while (p < l) putchar_unlocked(*p++); return *this; } template <typename IT> void join(IT begin, IT end, char sep = ' ') { for (bool b = 0; begin != end; ++begin, b = 1) b ? *this << sep << *begin : *this << *begin; } }; } // namespace MaiScanner scanner; MaiPrinter printer; struct edge { int from, to, cost; }; signed main() { int n, m; cin >> n >> m; vector<edge> edges(m); rep(i, 0, m) { int a, b, c; cin >> a >> b >> c; edges[i] = {a - 1, b - 1, -c}; } bool isnc = false; vector<int> dist(n, inf); dist[0] = 0; rep(i, 0, n) { rep(j, 0, m) { int frm = edges[j].from, to = edges[j].to, cost = edges[j].cost; if (dist[frm] != inf && dist[to] > dist[frm] + cost) { dist[to] = dist[frm] + cost; if (i == n - 1 && to == n - 1) isnc = true; } } } if (isnc) cout << "inf\n"; else cout << -dist.back() << "\n"; }
a.cc:32:24: error: '{anonymous}::MaiScanner& {anonymous}::MaiScanner::operator>>(long long int&)' cannot be overloaded with '{anonymous}::MaiScanner& {anonymous}::MaiScanner::operator>>(long long int&)' 32 | inline MaiScanner &operator>>(long long &var) { | ^~~~~~~~ a.cc:28:24: note: previous declaration '{anonymous}::MaiScanner& {anonymous}::MaiScanner::operator>>(long long int&)' 28 | inline MaiScanner &operator>>(int &var) { | ^~~~~~~~ a.cc:73:24: error: '{anonymous}::MaiPrinter& {anonymous}::MaiPrinter::operator<<(long long int)' cannot be overloaded with '{anonymous}::MaiPrinter& {anonymous}::MaiPrinter::operator<<(long long int)' 73 | inline MaiPrinter &operator<<(long long var) { | ^~~~~~~~ a.cc:69:24: note: previous declaration '{anonymous}::MaiPrinter& {anonymous}::MaiPrinter::operator<<(long long int)' 69 | inline MaiPrinter &operator<<(int var) { | ^~~~~~~~ a.cc: In function 'int main()': a.cc:127:17: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings] 127 | cout << "inf\n"; | ^~~~~~~ a.cc:129:33: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings] 129 | cout << -dist.back() << "\n"; | ^~~~
s271325366
p03722
C++
#include<cstdio> struct edge { int from, to; int cost; }; int n, m; long d[1000]; bool jf[1000], jb[1000]; edge e[2000]; int main() { scanf("%d %d", &n, &m); for (int i = 0; i < m; i++) { int a, b, c; scanf("%d %d %d", &a, &b, &c); e[i].from = a - 1; e[i].to = b - 1; e[i].cost = c; } jf[0] = true; for (int i = 0; i < v; i++) { for (int j = 0; j < m; j++) { if (jf[e[j].from]) jf[e[j].to] = true; } } jb[n - 1] = true; for (int i = 0; i < v; i++) { for (int j = 0; j < m; j++) { if (jb[e[j].to]) jb[e[j].from] = true; } } for (int i = 1; i < n; i++) d[i] = -1e18; bool update = true; int cnt = 0; while (update) { if (++cnt == n + 1) { printf("inf\n"); return 0; } update = false; for (int i = 0; i < m; i++) { if (jf[e[i].from] && jb[e[i].to] && d[e[i].from] + e[i].cost > d[e[i].to]) { d[e[i].to] = d[e[i].from] + e[i].cost; update = true; } } } printf("%ld\n", d[n - 1]); return 0; }
a.cc: In function 'int main()': a.cc:24:25: error: 'v' was not declared in this scope 24 | for (int i = 0; i < v; i++) { | ^ a.cc:30:25: error: 'v' was not declared in this scope 30 | for (int i = 0; i < v; i++) { | ^
s055143583
p03722
C++
#include <bits/stdc++.h> using namespace std; using ll = long long; using P = pair<ll, ll>; using Graph = vector<vector<ll>>; #define rep(i, n) for(ll i=0;i<(ll)(n);i++) #define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++) #define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--) const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1}; const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1}; const ll MOD = 1000000007; const ll INF = 1000000000000000000L; #ifdef __DEBUG #include "cpp-pyprint/pyprint.h" #endif void Main() { int N, M; cin >> N >> M; vector<vector<P>> graph(N); rep(i, M) { ll a, b, c; cin >> a >> b >> c; a--; b--; graph[a].push_back({b, -c}); } vector<ll> cost(N, INF); bool updated = false; cost[0] = 0; rep(k, N) { for (int i = 0; i < N; ++i) { for (P &p : graph[i]) { if (cost[p.first] > cost[i] + p.second) { cost[p.first] = cost[i] + p.second; if (k == N - 1 && p.first == N -1) updated = true; } } } } print(cost); if (updated) { cout << "inf" << '\n'; } else { cout << -cost[N - 1] << '\n'; } } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); Main(); }
a.cc: In function 'void Main()': a.cc:48:5: error: 'print' was not declared in this scope; did you mean 'rint'? 48 | print(cost); | ^~~~~ | rint
s718570423
p03722
C++
#include <bits/stdc++.h> #define For(i,n) for(long long i=0; i<n; i++) using namespace std; long long dp[2020]; bool visited[2020]; bool inff = false; struct line{ long long a; long long b; long long c; }; bool cmp(const line a, const line b){ return a.a<b.a; } void move(long long i, line* tes, long long M, long long N){ if(inff) return; if(visited[tes[i].b && dp[tes[i].b]<dp[tes[i].a]+tes[i].c) inff=true; else visited[tes[i].b] = true; dp[tes[i].b] = max(dp[tes[i].b], dp[tes[i].a]+tes[i].c); for(long long j=0; j<M; j++) if(tes[j].a==tes[i].b) move(j,tes,M,N); visited[tes[i].b] = false; } int main(){ long long N,M; long long inf=-1e12+10; cin >> N >> M; struct line tes[M]; For(i,M) cin >> tes[i].a >> tes[i].b >> tes[i].c; For(i,2020) dp[i] = inf; dp[1] = 0; For(i,2020) visited[i] = false; visited[1]=true; sort(tes,tes+M,cmp); for(long long i=0; i<M; i++) if(tes[i].a==1) move(i,tes,M,N); if(inff) cout << "inf" << endl; else cout << dp[N] << endl; return 0; }
a.cc: In function 'void move(long long int, line*, long long int, long long int)': a.cc:23:60: error: expected ']' before ')' token 23 | if(visited[tes[i].b && dp[tes[i].b]<dp[tes[i].a]+tes[i].c) inff=true; | ^ | ]
s835736826
p03722
C++
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for (int i=0; i<(int)(n); i++) using ll = long long; using Graph = vector<vector<int>>; vector<bool> seen, finished; int pos; // vertex in cycle stack<int> hist; vector<ll> score; vector<vector<ll>> value; const ll INFTY = 1000000000001; void loop(stack<int> st) { // score increase in cycle vector<int> cycle; while (!st.empty()) { // restore cycle int t = st.top(); cycle.push_back(t); st.pop(); if (t == pos) break; } int s = cycle.size(); cycle.push_back(cycle.at(0)); ll sum = 0; rep(i,s) sum += value[cycle.at(i+1)][cycle.at(i)]; if (sum > 0) rep(i,s) score[cycle.at(i)] = INFTY; return; } void dfs(const Graph &G, int v) { seen[v] = true; hist.push(v); for (auto nv : G[v]) { if (score[nv] == INFTY) { // entered cycle continue; } if (seen[nv] && !finished[nv]) { //detected cycle pos = nv; loop(hist); continue; } if (score[v] == INFTY && score[nv] =! INFTY) { score[nv] = INFTY; dfs(G, nv); continue; } if (score[nv] < score[v]+value[v][nv]) { score[nv] = score[v]+value[v][nv]; dfs(G, nv); } } hist.pop(); finished[v] = true; } int main() { int N, M; cin >> N >> M; Graph G(N); value.assign(N, vector<ll>(N)); rep(i,M) { int a, b; ll c; cin >> a >> b >> c; --a, --b; // 0-indexed G[a].push_back(b); value[a][b] = c; } seen.assign(N, false), finished.assign(N, false); score.assign(N, -INFTY); score[0] = 0; dfs(G,0); if (score[N-1] == INFTY) cout << "inf" << endl; else cout << score[N-1] << endl; return 0; }
a.cc: In function 'void dfs(const Graph&, int)': a.cc:42:27: error: lvalue required as left operand of assignment 42 | if (score[v] == INFTY && score[nv] =! INFTY) {
s077230576
p03722
C++
#include <bits/stdc++.h> #pragma GCC optimize("O3") #define REP(i,n) for(int i=0;i<n;i++) #define REPP(i,n) for(int i=1;i<=n;i++) const double PI = acos(-1); const double EPS = 1e-15; long long INF=(long long)1E17; #define i_7 (long long)(1E9+7) long mod(long a){ long long c=a%i_7; if(c>=0)return c; return c+i_7; } using namespace std; bool prime_(int n){ if(n==1){ return false; }else if(n==2){ return true; }else{ for(int i=2;i<=sqrt(n);i++){ if(n%i==0){ return false; } } return true; } } long long gcd_(long long a, long long b){ if(a<b){ swap(a,b); } if(a%b==0){ return b; }else{ return gcd_(b,a%b); } } long long lcm_(long long x, long long y){ return (x/gcd_(x,y))*y; } vector<int> G[1'005]; vector<int> revG[1'005]; bool reachableFrom1[1'005]; bool reachableToN[1'005]; void dfs1(int v){ if(reachableFrom1[v]){ return; } reachableFrom1[v] = true; for(int next_:G[v]){ dfs1(next_); } return; } void dfsN(int v){ if(reachableToN[v]){ return; } reachableToN[v] = true; for(int next_:revG[v]){ dfsN(next_); } return; } int main(){ int n,m; cin>>n>>m; int a[m],b[m],c[m]; REP(i,m){ cin>>a[i]>>b[i]>>c[i]; a[i]--;b[i]--; G[a[i]].push_back(b[i]); revG[b[i]].push_back(a[i]); } bool usable[n]={}; dfs1(0); dfsN(n-1); REP(i,n){ usable[i] = reachableFrom1[i] && reachableToN[i]; } vector<long long> dist(n,-INF); dist[0] = 0; REP(_,m){ REP(i,m){ if(usable[a[i]] && usable[b[i]]){ dist[b[i]] = max(dist[b[i]], dist[a[i]] + c[i]); } } } bool cycle_ = false; REP(i,m){ if(usable[a[i]] && usable[b[i]]){ if(dist[b[i]]<dist[a[i]] + c[i]){ cycle = true; break; } } } if(cycle_){ cout<<"inf"<<endl; }else{ cout<<dist[n-1]<<endl; } return 0; }
a.cc: In function 'int main()': a.cc:104:9: error: 'cycle' was not declared in this scope; did you mean 'cycle_'? 104 | cycle = true; | ^~~~~ | cycle_
s680840481
p03722
C++
#include <bits/stdc++.h> #define sz(v) ((int)(v).size()) #define all(v) ((v).begin()),((v).end()) #define allr(v) ((v).rbegin()),((v).rend()) #define pb push_back #define mp make_pair #define mt make_tuple #define Y imag() #define X real() #define clr(v,d) memset( v, d ,sizeof(v)) #define angle(n) atan2((n.imag()),(n.real())) #define vec(a,b) ((b)-(a)) //#define length(a) hypot( (a.imag()),(a.real()) ) #define normalize(a) (a)/(length(a)) #define dp(a,b) (((conj(a))*(b)).real()) //#define cp(a,b) (((conj(a))*(b)).imag()) #define lengthsqrt(a) dp(a,a) #define rotate0( a,ang) ((a)*exp( point(0,ang) )) #define rotateA(about,p,ang) (rotate0(vec(about,p),ang)+about) #define reflection0(m,v) (conj((v)/(m))*(m)) #define reflectionA(m,v,p0) (conj( (vec(p0,v))/(vec(p0,m)) ) * (vec(p0,m)) ) + p0 //#define same(p1,p2) ( dp( vec(p1,p2),vec(p1,p2)) < eps ) #define point complex<double> #define outfile freopen("out.out", "w", stdout); #define infile freopen("in.in", "r", stdin); #define PI acos(-1) typedef long long ll ; typedef unsigned long long ull; const double eps= (1e-9); using namespace std; int dcmp(double a,double b){ return fabs(a-b)<=eps ? 0: (a>b)? 1:-1 ;} int getBit(int num, int idx) {return ((num >> idx) & 1) == 1;} ll setBit1(ll num, int idx) {return num | (1ll<<idx);} ll setBit0(ll num, int idx) {return num & ~(1ll<<idx);} ll flipBit(int num, int idx) {return num ^ (1<<idx);} void FS(){ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);} const int N=100009; int n,m,tim,str[N],en[N]; vector< vector< pair<int,int> > >v(N); ll mem[N]; bool iscy=0; ll solve(int no) { if(no==n) return 0; ll &ret=mem[no]; if(ret!=-1) return ret; ll ret=-1e14; for(int i=0;i<sz(v[no]);i++) { int nw=v[no][i].first; int co=v[no][i].second; ret=max(ret,co+solve(nw)); } return ret; } void dfs(int no) { str[no]=tim++; for(int i=0;i<sz(v[no]);i++) { int nw=v[no][i].first; if(str[nw]==-1) { dfs(nw); } else { if(en[nw]==-1) { iscy=1; } else { ; } } } en[no]=tim++; } int main() { cin>>n>>m; for(int i=0;i<m;i++) { int a,b,c; cin>>a>>b>>c; v[a].pb(mp(b,c)); } clr(str,-1); clr(en,-1); tim=1; dfs(1); if(iscy) { cout<<"inf"<<endl; return 0; } clr(mem,-1); cout<<solve(1)<<endl; }
a.cc: In function 'll solve(int)': a.cc:49:8: error: conflicting declaration 'll ret' 49 | ll ret=-1e14; | ^~~ a.cc:46:9: note: previous declaration as 'll& ret' 46 | ll &ret=mem[no]; | ^~~
s460031095
p03722
C++
#include<bits/stdc++.h> using namespace std; #define int long struct edge{int a,b,c;}; main(){ int n,m,r; cin>>n>>m; vector<edge> e(m); vector<int> d(n,-1e18),nc(n,0); for(int i=0;i<m;++i){ cin>>e[i].a>>e[i].b>>e[i].c; --e[i].a;--e[i].b; } dist[0]=0; for(int i=0;i<2*n-1;++i)for(int j=0;j<m;++j){ if(d[e[j].a]+e[j].c>d[e[j].b]){ if(i>n-2)nc[e[j].b]=1; d[e[j].b]=d[e[j].a]+e[j].c; } nc[e[j].b]|=nc[e[j].a]; } if(nc[n-1])cout<<"inf"; else cout<<r; }
a.cc:5:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type] 5 | main(){ | ^~~~ a.cc: In function 'int main()': a.cc:14:3: error: 'dist' was not declared in this scope 14 | dist[0]=0; | ^~~~
s941765017
p03722
C++
#include<iostream> #include <iomanip> #include <vector> #include <algorithm> #include <string> #include <string.h> #include <cmath> #include <map> #include <set> #include <bitset> #include <stack> #include <queue> #include <fstream> #include <functional> using namespace std; using ll = long long; #define all(x) (x).begin(),(x).end() #define PRI(n) cout << n <<endl; #define PRI2(n, m) cout << n << " " << m << " "<<endl; #define REP(i, n) for(int i = 0; i < (int)n; ++i) #define REPbit(bit, n) for(int bit = 0; bit < (int)(1<<n); ++bit) #define FOR(i, t, n) for(int i = t; i <= (int)n; ++i) const char alphabet[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'}; const ll MOD = (ll) 1e9 + 7; const int MAX_INT = 1 << 17; bool isPrime(ll x) { if (x == 0)return 0; if (x == 1)return 0; if (x == 2)return 1; if (x % 2 == 0)return 0; FOR(i, 3, x - 1) { if (x % i == 0)return 0; } return 1; } ll GCD(ll a, ll b) { if (b == 0)return a; return GCD(b, a % b); } ll LCM(ll a, ll b) { ll gcd = GCD(a, b); return a / gcd * b; } ll nCr(int n, int r) { vector<ll> C(r + 1); C[0] = 1; FOR(i, 1, n) for (int j = min(i, r); j < 1; --j)C[j] = (C[j] + C[j - 1]) % MOD; return C[r]; } template<class T> class SegTree { int n; vector<T> data; T def; function<T(T, T)> operation; function<T(T, T)> update; T _query(int a, int b, int k, int l, int r) { if (r <= a || b <= l) return def; if (a <= l && r <= b) return data[k]; else { T c1 = _query(a, b, 2 * k + 1, l, (l + r) / 2); T c2 = _query(a, b, 2 * k + 2, (l + r) / 2, r); return operation(c1, c2); } } public: SegTree(size_t _n, T _def, function<T(T, T)> _operation, function<T(T, T)> _update) : def(_def), operation(_operation), update(_update) { n = 1; while (n < _n) { n *= 2; } data = vector<T>(2 * n - 1, def); } void change(int i, T x) { i += n - 1; data[i] = update(data[i], x); while (i > 0) { i = (i - 1) / 2; data[i] = operation(data[i * 2 + 1], data[i * 2 + 2]); } } T query(int a, int b) { return _query(a, b, 0, 0, n); } T operator[](int i) { return data[i + n - 1]; } }; struct UnionFind { vector<int> par; vector<int> rank; UnionFind(int N) { for (int i = 0; i < N; ++i) { par.push_back(i); rank.push_back(0); } } int find(int x) { if (par[x] == x)return x; else return par[x] = find(par[x]); } void unite(int x, int y) { x = find(x); y = find(y); if (x == y)return; if (rank[x] < rank[y])par[x] = y; else { par[y] = x; if (rank[x] == rank[y])rank[x]++; } } bool same(int x, int y) { return find(x) == find(y); } }; struct ListNode { int val; ListNode *next; ListNode(int x) : val(x), next(NULL) {} }; const ll MAX_E = 10010; const ll MAX_V = 2010; ll V,E; struct edge { ll from, to, cost; }; edge ES[MAX_E]; ll d[MAX_V]; void Bellman_short(int s) { REP(i, V+1)d[i] = LLONG_MAX; d[s] = 0; while (true) { bool up = false; REP(i, E) { edge e = ES[i]; if (d[e.from] != LLONG_MAX && d[e.to] > d[e.from] + e.cost) { d[e.to] = d[e.from] + e.cost; up = true; } } if (!up)break; } } bool Bellman_negLoop() { memset(d, 0, sizeof(d)); REP(i, V) REP(j, E) { edge e = ES[j]; if (d[e.to] > d[e.from] + e.cost) { d[e.to] = d[e.from] + e.cost; if (i == V - 1)return true; } } return false; } int main() { cin >> V >> E; REP(i, E) { ll a, b, c; cin >> a >> b >> c; ES[i] = edge{a, b, -c}; } if (Bellman_negLoop()) { PRI("inf") return 0; } Bellman_short(1); PRI(-d[V]) return 0; }
a.cc: In function 'void Bellman_short(int)': a.cc:157:23: error: 'LLONG_MAX' was not declared in this scope 157 | REP(i, V+1)d[i] = LLONG_MAX; | ^~~~~~~~~ a.cc:15:1: note: 'LLONG_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>' 14 | #include <functional> +++ |+#include <climits> 15 | a.cc:163:30: error: 'LLONG_MAX' was not declared in this scope 163 | if (d[e.from] != LLONG_MAX && d[e.to] > d[e.from] + e.cost) { | ^~~~~~~~~ a.cc:163:30: note: 'LLONG_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
s535291359
p03722
C++
#include<iostream> #include <iomanip> #include <vector> #include <algorithm> #include <string> #include <string.h> #include <cmath> #include <map> #include <set> #include <bitset> #include <stack> #include <queue> #include <fstream> #include <functional> using namespace std; using ll = long long; #define all(x) (x).begin(),(x).end() #define PRI(n) cout << n <<endl; #define PRI2(n, m) cout << n << " " << m << " "<<endl; #define REP(i, n) for(int i = 0; i < (int)n; ++i) #define REPbit(bit, n) for(int bit = 0; bit < (int)(1<<n); ++bit) #define FOR(i, t, n) for(int i = t; i <= (int)n; ++i) const char alphabet[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'}; const ll MOD = (ll) 1e9 + 7; const int MAX_INT = 1 << 17; bool isPrime(ll x) { if (x == 0)return 0; if (x == 1)return 0; if (x == 2)return 1; if (x % 2 == 0)return 0; FOR(i, 3, x - 1) { if (x % i == 0)return 0; } return 1; } ll GCD(ll a, ll b) { if (b == 0)return a; return GCD(b, a % b); } ll LCM(ll a, ll b) { ll gcd = GCD(a, b); return a / gcd * b; } ll nCr(int n, int r) { vector<ll> C(r + 1); C[0] = 1; FOR(i, 1, n) for (int j = min(i, r); j < 1; --j)C[j] = (C[j] + C[j - 1]) % MOD; return C[r]; } template<class T> class SegTree { int n; vector<T> data; T def; function<T(T, T)> operation; function<T(T, T)> update; T _query(int a, int b, int k, int l, int r) { if (r <= a || b <= l) return def; if (a <= l && r <= b) return data[k]; else { T c1 = _query(a, b, 2 * k + 1, l, (l + r) / 2); T c2 = _query(a, b, 2 * k + 2, (l + r) / 2, r); return operation(c1, c2); } } public: SegTree(size_t _n, T _def, function<T(T, T)> _operation, function<T(T, T)> _update) : def(_def), operation(_operation), update(_update) { n = 1; while (n < _n) { n *= 2; } data = vector<T>(2 * n - 1, def); } void change(int i, T x) { i += n - 1; data[i] = update(data[i], x); while (i > 0) { i = (i - 1) / 2; data[i] = operation(data[i * 2 + 1], data[i * 2 + 2]); } } T query(int a, int b) { return _query(a, b, 0, 0, n); } T operator[](int i) { return data[i + n - 1]; } }; struct UnionFind { vector<int> par; vector<int> rank; UnionFind(int N) { for (int i = 0; i < N; ++i) { par.push_back(i); rank.push_back(0); } } int find(int x) { if (par[x] == x)return x; else return par[x] = find(par[x]); } void unite(int x, int y) { x = find(x); y = find(y); if (x == y)return; if (rank[x] < rank[y])par[x] = y; else { par[y] = x; if (rank[x] == rank[y])rank[x]++; } } bool same(int x, int y) { return find(x) == find(y); } }; struct ListNode { int val; ListNode *next; ListNode(int x) : val(x), next(NULL) {} }; const ll MAX_E = 1001; const ll MAX_V = 2001; ll V,E; struct edge { ll from, to, cost; }; edge ES[MAX_E]; ll d[MAX_V]; void Bellman_short(int s) { REP(i, V+1)d[i] = LLONG_MAX; d[s] = 0; while (true) { bool up = false; REP(i, E) { edge e = ES[i]; if (d[e.from] != LLONG_MAX && d[e.to] > d[e.from] + e.cost) { d[e.to] = d[e.from] + e.cost; up = true; } } if (!up)break; } } bool Bellman_negLoop() { memset(d, 0, sizeof(d)); REP(i, V) REP(j, E) { edge e = ES[j]; if (d[e.to] > d[e.from] + e.cost) { d[e.to] = d[e.from] + e.cost; if (i == V - 1)return true; } } return false; } int main() { cin >> V >> E; REP(i, E) { ll a, b, c; cin >> a >> b >> c; ES[i] = edge{a, b, -c}; } if (Bellman_negLoop()) { PRI("inf") return 0; } Bellman_short(1); PRI(-d[V]) return 0; }
a.cc: In function 'void Bellman_short(int)': a.cc:157:23: error: 'LLONG_MAX' was not declared in this scope 157 | REP(i, V+1)d[i] = LLONG_MAX; | ^~~~~~~~~ a.cc:15:1: note: 'LLONG_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>' 14 | #include <functional> +++ |+#include <climits> 15 | a.cc:163:30: error: 'LLONG_MAX' was not declared in this scope 163 | if (d[e.from] != LLONG_MAX && d[e.to] > d[e.from] + e.cost) { | ^~~~~~~~~ a.cc:163:30: note: 'LLONG_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
s509261024
p03722
C++
#include<iostream> #include <iomanip> #include <vector> #include <algorithm> #include <string> #include <cmath> #include <map> #include <set> #include <bitset> #include <stack> #include <queue> #include <fstream> #include <functional> using namespace std; using ll = long long; #define all(x) (x).begin(),(x).end() #define PRI(n) cout << n <<endl; #define PRI2(n, m) cout << n << " " << m << " "<<endl; #define REP(i, n) for(int i = 0; i < (int)n; ++i) #define REPbit(bit, n) for(int bit = 0; bit < (int)(1<<n); ++bit) #define FOR(i, t, n) for(int i = t; i <= (int)n; ++i) const char alphabet[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'}; const ll MOD = (ll) 1e9 + 7; const int MAX_INT = 1 << 17; const ll INFL = 1e18; bool isPrime(ll x) { if (x == 0)return 0; if (x == 1)return 0; if (x == 2)return 1; if (x % 2 == 0)return 0; FOR(i, 3, x - 1) { if (x % i == 0)return 0; } return 1; } ll GCD(ll a, ll b) { if (b == 0)return a; return GCD(b, a % b); } ll LCM(ll a, ll b) { ll gcd = GCD(a, b); return a / gcd * b; } ll nCr(int n, int r) { vector<ll> C(r + 1); C[0] = 1; FOR(i, 1, n) for (int j = min(i, r); j < 1; --j)C[j] = (C[j] + C[j - 1]) % MOD; return C[r]; } template<class T> class SegTree { int n; vector<T> data; T def; function<T(T, T)> operation; function<T(T, T)> update; T _query(int a, int b, int k, int l, int r) { if (r <= a || b <= l) return def; if (a <= l && r <= b) return data[k]; else { T c1 = _query(a, b, 2 * k + 1, l, (l + r) / 2); T c2 = _query(a, b, 2 * k + 2, (l + r) / 2, r); return operation(c1, c2); } } public: SegTree(size_t _n, T _def, function<T(T, T)> _operation, function<T(T, T)> _update) : def(_def), operation(_operation), update(_update) { n = 1; while (n < _n) { n *= 2; } data = vector<T>(2 * n - 1, def); } void change(int i, T x) { i += n - 1; data[i] = update(data[i], x); while (i > 0) { i = (i - 1) / 2; data[i] = operation(data[i * 2 + 1], data[i * 2 + 2]); } } T query(int a, int b) { return _query(a, b, 0, 0, n); } T operator[](int i) { return data[i + n - 1]; } }; struct UnionFind { vector<int> par; vector<int> rank; UnionFind(int N) { for (int i = 0; i < N; ++i) { par.push_back(i); rank.push_back(0); } } int find(int x) { if (par[x] == x)return x; else return par[x] = find(par[x]); } void unite(int x, int y) { x = find(x); y = find(y); if (x == y)return; if (rank[x] < rank[y])par[x] = y; else { par[y] = x; if (rank[x] == rank[y])rank[x]++; } } bool same(int x, int y) { return find(x) == find(y); } }; struct ListNode { int val; ListNode *next; ListNode(int x) : val(x), next(NULL) {} }; const ll MAX_E = 1001; const ll MAX_V = 2001; ll E, V; struct edge { ll from, to, cost; }; edge ES[MAX_E]; ll d[MAX_V]; void Bellman_short(int s) { REP(i, V)d[i] = INFL; d[s] = 0; while (true) { bool up = false; REP(i, E) { edge e = ES[i]; if (d[e.from] != INFL && d[e.to] > d[e.from] + e.cost) { d[e.to] = d[e.from] + e.cost; up = true; } } if (!up)break; } } bool Bellman_negLoop() { memset(d, 0, sizeof(d)); REP(i, V) REP(j, E) { edge e = ES[j]; if (d[e.to] > d[e.from] + e.cost) { d[e.to] = d[e.from] + e.cost; if (i == V - 1)return true; } } return false; } int main() { cin >> V >> E; REP(i, E) { ll a, b, c; cin >> a >> b >> c; ES[i] = edge{a, b, -c}; } if (Bellman_negLoop()) { PRI("inf") return 0; } Bellman_short(1); PRI(-d[V]) return 0; }
a.cc: In function 'bool Bellman_negLoop()': a.cc:173:5: error: 'memset' was not declared in this scope 173 | memset(d, 0, sizeof(d)); | ^~~~~~ a.cc:14:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>' 13 | #include <functional> +++ |+#include <cstring> 14 |
s531994753
p03722
C++
//include //------------------------------------------ #include <bits/stdc++.h> using namespace std; //typedef //------------------------------------------ typedef long long LL; typedef vector<LL> VL; typedef vector<VL> VVL; typedef vector<string> VS; typedef pair<LL, LL> PLL; //container util //------------------------------------------ #define ALL(a) (a).begin(),(a).end() #define RALL(a) (a).rbegin(), (a).rend() #define PB push_back #define MP make_pair #define SZ(a) int((a).size()) #define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i) #define EXIST(s,e) ((s).find(e)!=(s).end()) #define SORT(c) sort((c).begin(),(c).end()) //constant //-------------------------------------------- const double EPS = 1e-10; const double PI = acos(-1.0); const int MOD = 1000000007; // grid //-------------------------------------------- VL dx = {0, 1, 0, -1}; VL dy = {1, 0, -1, 0}; VL dx2 = {-1, 0, 1, -1, 1, -1, 0, 1}; VL dy2 = {-1, -1, -1, 0, 0, 1, 1, 1}; //debug //-------------------------------------------- #define dump(x) cerr << #x << " = " << (x) << endl; #define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl; //IO accelerate //-------------------------------------------- struct InitIO { InitIO() { cin.tie(nullptr); ios_base::sync_with_stdio(false); cout << fixed << setprecision(30); } } init_io; //template //-------------------------------------------- template<typename T> istream& operator >>(istream& is, vector<T>& vec) { for(T& x: vec) is >> x; return is; } template<typename T> ostream& operator <<(ostream& os, const vector<T>& vec) { for(int i=0; i<vec.size(); i++){ os << vec[i] << ( i+1 == vec.size() ? "" : "\t" ); } return os; } template<typename T> ostream& operator <<(ostream& s, const vector<vector<T>>& vv) { for (int i = 0; i < vv.size(); ++i) { s << vv[i] << endl; } return s; } // 多重vector // auto dp=make_v<int>(4,h,w) みたいに使える template<typename T> vector<T> make_v(size_t a){return vector<T>(a);} template<typename T,typename... Ts> auto make_v(size_t a,Ts... ts){ return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...)); } // 多重vectorのためのfill // fill_v(dp,0) みたいに使える template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;} template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){ for(auto &e:t) fill_v(e,v); } //main code template<typename T> class bellmanford { public: struct edge { int from, to; T cost; }; int V; T inf; vector<T> d; vector<edge> es; bellmanford(int n) : V(n), inf(numeric_limits<T>::max()/2), d(n, inf){} void add_edge(int from, int to, T cost){ es.push_back((edge){from,to,cost}); } bool solve(int s) { d[s] = 0; T cnt; for (cnt = 0; cnt < V; cnt++) { bool update = false; for (auto&& e : es) { if (d[e.from] < inf and d[e.to] > d[e.from] + e.cost) { d[e.to] = d[e.from] + e.cost; update = true; } } if (!update) { break; } } return (cnt == V); } set<edge> check_inf_edge() { set<edge> inf_es; for (auto&& e : es) { if (d[e.from] < inf and d[e.to] > d[e.from] + e.cost) { inf_es.insert(e); } } return inf_es; } }; int main(int argc, char const* argv[]) { int n,m; cin >> n >> m; bellmanford<LL> bel(n); bellmanford<LL> belr(n); for (int i = 0; i < m; i++) { int a,b,c; cin >> a >> b >> c; a--;b--; bel.add_edge(a,b,-c); belr.add_edge(a,b,-c); } if(bel.solve(0)){ belr.solve(n-1); auto inf_es_0 = bel.check_inf_edge(); auto inf_es_n = bel.check_inf_edge(); set_intersection(ALL(inf_es_0), ALL(inf_es_n), inf_es_0); if (inf_es_0.size() > 0) { cout << "inf" << endl; return 0; } } cout << -bel.d[n-1] << endl; return 0; }
In file included from /usr/include/c++/14/algorithm:61, from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51, from a.cc:3: /usr/include/c++/14/bits/stl_algo.h: In instantiation of '_OutputIterator std::__set_intersection(_InputIterator1, _InputIterator1, _InputIterator2, _InputIterator2, _OutputIterator, _Compare) [with _InputIterator1 = _Rb_tree_const_iterator<bellmanford<long long int>::edge>; _InputIterator2 = _Rb_tree_const_iterator<bellmanford<long long int>::edge>; _OutputIterator = set<bellmanford<long long int>::edge, less<bellmanford<long long int>::edge>, allocator<bellmanford<long long int>::edge> >; _Compare = __gnu_cxx::__ops::_Iter_less_iter]': /usr/include/c++/14/bits/stl_algo.h:5234:48: required from '_OIter std::set_intersection(_IIter1, _IIter1, _IIter2, _IIter2, _OIter) [with _IIter1 = _Rb_tree_const_iterator<bellmanford<long long int>::edge>; _IIter2 = _Rb_tree_const_iterator<bellmanford<long long int>::edge>; _OIter = set<bellmanford<long long int>::edge, less<bellmanford<long long int>::edge>, allocator<bellmanford<long long int>::edge> >]' 5234 | return _GLIBCXX_STD_A::__set_intersection(__first1, __last1, | ^ a.cc:161:19: required from here 161 | set_intersection(ALL(inf_es_0), ALL(inf_es_n), inf_es_0); | ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/include/c++/14/bits/stl_algo.h:5184:13: error: no match for 'operator*' (operand type is 'std::set<bellmanford<long long int>::edge, std::less<bellmanford<long long int>::edge>, std::allocator<bellmanford<long long int>::edge> >') 5184 | *__result = *__first1; | ^~~~~~~~~ In file included from /usr/include/c++/14/ccomplex:39, from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:127: /usr/include/c++/14/complex:400:5: note: candidate: 'template<class _Tp> std::complex<_Tp> std::operator*(const complex<_Tp>&, const complex<_Tp>&)' 400 | operator*(const complex<_Tp>& __x, const complex<_Tp>& __y) | ^~~~~~~~ /usr/include/c++/14/complex:400:5: note: candidate expects 2 arguments, 1 provided /usr/include/c++/14/complex:409:5: note: candidate: 'template<class _Tp> std::complex<_Tp> std::operator*(const complex<_Tp>&, const _Tp&)' 409 | operator*(const complex<_Tp>& __x, const _Tp& __y) | ^~~~~~~~ /usr/include/c++/14/complex:409:5: note: candidate expects 2 arguments, 1 provided /usr/include/c++/14/complex:418:5: note: candidate: 'template<class _Tp> std::complex<_Tp> std::operator*(const _Tp&, const complex<_Tp>&)' 418 | operator*(const _Tp& __x, const complex<_Tp>& __y) | ^~~~~~~~ /usr/include/c++/14/complex:418:5: note: candidate expects 2 arguments, 1 provided In file included from /usr/include/c++/14/valarray:605, from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:166: /usr/include/c++/14/bits/valarray_after.h:407:5: note: candidate: 'template<class _Dom1, class _Dom2> std::_Expr<std::__detail::_BinClos<std::__multiplies, std::_Expr, std::_Expr, _Dom1, _Dom2>, typename std::__fun<std::__multiplies, typename _Dom1::value_type>::result_type> std::operator*(const _Expr<_Dom1, typename _Dom1::value_type>&, const _Expr<_Dom2, typename _Dom2::value_type>&)' 407 | _DEFINE_EXPR_BINARY_OPERATOR(*, struct std::__multiplies) | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/include/c++/14/bits/valarray_after.h:407:5: note: candidate expects 2 arguments, 1 provided /usr/include/c++/14/bits/valarray_after.h:407:5: note: candidate: 'template<class _Dom> std::_Expr<std::__detail::_BinClos<std::__multiplies, std::_Expr, std::_Constant, _Dom, typename _Dom::value_type>, typename std::__fun<std::__multiplies, typename _Dom1::value_type>::result_type> std::operator*(const _Expr<_Dom1, typename _Dom1::value_type>&, const typename _Dom::value_type&)' 407 | _DEFINE_EXPR_BINARY_OPERATOR(*, struct std::__multiplies) | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/include/c++/14/bits/valarray_after.h:407:5: note: candidate expects 2 arguments, 1 provided /usr/include/c++/14/bits/valarray_after.h:407:5: note: candidate: 'template<class _Dom> std::_Expr<std::__detail::_BinClos<std::__multiplies, std::_Constant, std::_Expr, typename _Dom::value_type, _Dom>, typename std::__fun<std::__multiplies, typename _Dom1::value_type>::result_type> std::operator*(const typename _Dom::value_type&, const _Expr<_Dom1, typename _Dom1::value_type>&)' 407 | _DEFINE_EXPR_BINARY_OPERATOR(*, struct std::__multiplies) | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/include/c++/14/bits/valarray_after.h:407:5: note: candidate expects 2 arguments, 1 provided /usr/include/c++/14/bits/valarray_after.h:407:5: note: candidate: 'template<class _Dom> std::_Expr<std::__detail::_BinClos<std::__multiplies, std::_Expr, std::_ValArray, _Dom, typename _Dom::value_type>, typename std::__fun<std::__multiplies, typename _Dom1::value_type>::result_type> std::operator*(const _Expr<_Dom1, typename _Dom1::value_type>&, const valarray<typename _Dom::value_type>&)' 407 | _DEFINE_EXPR_BINARY_OPERATOR(*, struct std::__multiplies) | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/include/c++/14/bits/valarray_after.h:407:5: note: candidate expects 2 arguments, 1 provided /usr/include/c++/14/bits/valarray_after.h:407:5: note: candidate: 'template<class _Dom> std::_Expr<std::__detail::_BinClos<std::__multiplies, std::_ValArray, std::_Expr, typename _Dom::value_type, _Dom>, typename std::__fun<std::__multiplies, typename _Dom1::value_type>::result_type> std::operator*(const valarray<typename _Dom::value_type>&, const _Expr<_Dom1, typename _Dom1::value_type>&)' 407 | _DEFINE_EXPR_BINARY_OPERATOR(*, struct std::__multiplies) | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/include/c++/14/bits/valarray_after.h:407:5: note: candidate expects 2 arguments, 1 provided /usr/include/c++/14/valarray:1198:1: note: candidate: 'template<class _Tp> std::_Expr<std::__detail::_BinClos<std::__multiplies, std::_ValArray, std::_ValArray, _Tp, _Tp>, typename std::__fun<std::__multiplies, _Tp>::result_type> std::operator*(const valarray<_Tp>&, const valarray<_Tp>&)' 1198 | _DEFINE_BINARY_OPERATOR(*, __multiplies) | ^~~~~~~~~~~~~~~~~~~~~~~ /usr/include/c++/14/valarray:1198:1: note: candidate expects 2 arguments, 1 provided /usr/include/c++/14/valarray:1198:1: note: candidate: 'template<class _Tp> std::_Expr<std::__detail::_BinClos<std::__multiplies, std::_ValArray, std::_Constant, _Tp, _Tp>, typename std::__fun<std::__multiplies, _Tp>::result_type> std::operator*(const valarray<_Tp>&, const typename valarray<_Tp>::value_type&)' 1198 | _DEFINE_BINARY_OPERATOR(*, __multiplies) | ^~~~~~~~~~~~~~~~~~~~~~~ /usr/include/c++/14/valarray:1198:1: note: candidate expects 2 arguments, 1 provided /usr/include/c++/14/valarray:1198:1: note: candidate: 'template<class _Tp> std::_Expr<std::__detail::_BinClos<std::__multiplies, std::_Constant, std::_ValArray, _Tp, _Tp>, typename std::__fun<std::__multiplies, _Tp>::result_type> std::operator*(const typename valarray<_Tp>::value_type&, const valarray<_Tp>&)' 1198 | _DEFINE_BINARY_OPERATOR(*, __multiplies) | ^~~~~~~~~~~~~~~~~~~~~~~ /usr/include/c++/14/valarray:1198:1: note: candidate expects 2 arguments, 1 provided /usr/include/c++/14/bits/stl_algo.h:5187:13: error: no match for 'operator++' (operand type is 'std::set<bellmanford<long long int>::edge, std::less<bellmanford<long long int>::edge>, std::allocator<bellmanford<long long int>::edge> >') 5187 | ++__result; | ^~~~~~~~~~ In file included from /usr/include/c++/14/bits/stl_algobase.h:71, from /usr/include/c++/14/algorithm:60: /usr/include/c++/14/bits/predefined_ops.h: In instantiation of 'constexpr bool __gnu_cxx::__ops::_Iter_less_iter::operator()(_Iterator1, _Iterator2) const [with _Iterator1 = std::_Rb_tree_const_iterator<bellmanford<long long int>::edge>; _Iterator2 = std::_Rb_tree_const_iterator<bellmanford<long long int>::edge>]': /usr/include/c++/14/bits/stl_algo.h:5178:12: required from '_OutputIterator std::__set_intersection(_InputIterator1, _InputIterator1, _InputIterator2, _InputIterator2, _OutputIterator, _Compare) [with _InputIterator1 = _Rb_tree_const_iterator<bellmanford<long long int>::edge>; _InputIterator2 = _Rb_tree_const_iterator<bellmanford<long long int>::edge>; _OutputIterator = set<bellmanford<long long int>::edge, less<bellmanford<long long int>::edge>, allocator<bellmanford<long long int>::edge> >; _Compare = __gnu_cxx::__ops::_Iter_less_iter]' 5178 | if (__comp(__first1, __first2)) | ~~~~~~^~~~~~~~~~~~~~~~~~~~ /usr/include/c++/14/bits/stl_algo.h:5234:48: required from '_OIter std::set_intersection(_IIter1, _IIter1, _IIter2, _IIter2, _OIter) [with _IIter1 = _Rb_tree_const_iterator<bellmanford<long long int>::edge>; _IIter2 = _Rb_tree_const_iterator<bellmanford<long long int>::edge>; _OIter = set<bellmanford<long long int>::edge, less<bellmanford<long long int>::edge>, allocator<bellmanford<long long int>::edge> >]' 5234 | return _GLIBCXX_STD_A::__set_intersection(__first1, __last1, | ^ a.cc:161:19: required from here 161 | set_intersection(ALL(inf_es_0), ALL(inf_es_n), inf_es_0); | ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /usr/include/c++/14/bits/predefined_ops.h:45:23: error: no match for 'operator<' (operand types are 'const bellmanford<long long int>::edge' and 'const bellmanford<long long int>::edge') 45 | { return *__it1 < *__it2; } | ~~~~~~~^~~~~~~~ In file included from /usr/include/c++/14/bits/stl_algobase.h:67: /usr/include/c++/14/bits/stl_iterator.h:1241:5: note: candidate: 'template<class _IteratorL, class _IteratorR, class _Container> bool __gnu_cxx::operator<(const __normal_iterator<_IteratorL, _Container>&, const __normal_iterator<_IteratorR, _Container>&)' 1241 | operator<(const __normal_iterator<_IteratorL, _Container>& __lhs, | ^~~~~~~~ /usr/include/c++/14/bits/stl_iterator.h:1241:
s288914029
p03722
C++
void solve(); int main() { solve(); return 0; } ////////////////////////////////////////////////// ////////////////////////////////////////////////// #include <iostream> #include <vector> #include <limits.h> #include <algorithm> #include <string> #include <math.h> #include <limits.h> #include <queue> #include <map> #include <set> using namespace std; int N, M,; class edge { public: int a, b, c; }; vector<edge> Edges; vector<int> dp; void solve() { cin >> N >> M; Edges.resize(M); for (int m = 0; m < M; m++) { cin >> Edges[m].a >> Edges[m].b >> Edges[m].c; Edges[m].a--; Edges[m].b--; Edges[m].c = - Edges[m].c; } dp.resize(N, INT_MAX); dp[0] = 0; for (int time = 0;time < N; time++) { for (auto itr = Edges.begin(); itr != Edges.end(); itr++) { if (dp[itr->a] == INT_MAX)continue; if (dp[itr->b] > dp[itr->a] + itr->c) { dp[itr->b] = dp[itr->a] + itr->c; } } } vector<bool> negcheck; negcheck.resize(N,false); for (int time = 0; time < N; time++) { for (auto itr = Edges.begin(); itr != Edges.end(); itr++) { if (dp[itr->a] == INT_MAX)continue; if (dp[itr->b] > dp[itr->a] + itr->c) { dp[itr->b] = dp[itr->a] + itr->c; negcheck[itr->a] = true; } } } if (negcheck[N - 1])cout << "inf" << endl; else cout << -dp[N - 1] << endl; return; }
a.cc:22:10: error: expected unqualified-id before ';' token 22 | int N, M,; | ^
s780364393
p03722
C++
#include<iostream> #include<string> #include<cstdio> #include <cstring> #include<vector> #include<cmath> #include<algorithm> #include<functional> #include<iomanip> #include<queue> #include<ciso646> #include<random> #include<map> #include<set> #include<complex> #include<bitset> #include<stack> #include<unordered_map> #include<utility> using namespace std; typedef long long ll; typedef unsigned int ui; const ll mod = 1000000007; typedef long double ld; const ll INF = 1e+14; typedef pair<int, int> P; #define stop char nyaa;cin>>nyaa; #define rep(i,n) for(int i=0;i<n;i++) #define per(i,n) for(int i=n-1;i>=0;i--) #define Rep(i,sta,n) for(int i=sta;i<n;i++) #define rep1(i,n) for(int i=1;i<=n;i++) #define per1(i,n) for(int i=n;i>=1;i--) #define Rep1(i,sta,n) for(int i=sta;i<=n;i++) typedef complex<ld> Point; const ld eps = 1e-8; const ld pi = acos(-1.0); typedef pair<ld, ld> LDP; typedef pair<ll, ll> LP; #define fr first #define sc second #define all(c) c.begin(),c.end() #define pb push_back #define int long long void Yes(){ cout<<"Yes"<<endl; exit(0); } void No(){ cout<<"No"<<endl; exit(0); } struct edge{int from, to, cost; }; edge es[2020]; int d[1010]; bool dd[1010]; int N, M; signed main() { ios::sync_with_stdio(false); cin.tie(0); cin >> N >> M; rep(i, M) { int a, b, c; cin >> a >> b >> c; a --; b --; es[i] = edge{a, b, c}; } rep(i, N) d[i] = INF; rep(i, N) dd[i] = false; d[0] = 0; int cnt = 0; while(true) { bool update = true; cnt ++; rep(i, M) { edge e = es[i]; if(d[e.from] != INF && d[e.to] = d[e.from] + e.cost) { d[e.to] = d[e.from] + e.cost; update = true; } } if(cnt >= N) { rep(i, M) { edge e = es[i]; if(d[e.from] != INF && d[e.to] = d[e.from] + e.cost) { dd[e.to] = true; } if(dd[e.from]) { dd[e.to] = true; } } } if(!update) break; if(cnt >= 2 * N) break; } if(dd[N - 1]) { cout << "inf" << endl; } else { cout << d[N - 1] << endl; } return 0; }
a.cc: In function 'int main()': a.cc:80:33: error: lvalue required as left operand of assignment 80 | if(d[e.from] != INF && d[e.to] = d[e.from] + e.cost) { | ~~~~~~~~~~~~~~~~~^~~~~~~~~~ a.cc:88:37: error: lvalue required as left operand of assignment 88 | if(d[e.from] != INF && d[e.to] = d[e.from] + e.cost) { | ~~~~~~~~~~~~~~~~~^~~~~~~~~~
s451880505
p03722
C++
#include <bits/stdc++.h> #define rep(i, n) for(int i = 0; i < (int)(n); i++) #define all(x) (x).begin(),(x).end() #define rall(x) (x).rbegin(),(x).rend() #define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() ); using namespace std; using ll = long long; using P = pair<int, int>; const ll INF = -1e17; int n, m; bool loop = false; struct edge { int from, to; ll cost; }; edge es[2001]; ll d[1001]; void serch(int s){ int cnt = 0; rep(i, n) d[i] = INF; d[s] = 0; while(true){ int update = -1; int flag = false; for(int i=0; i<m; i++){ edge e = es[i]; if(d[e.from] != INF && d[e.to] < d[e.from] + e.cost){ d[e.to] = d[e.from] + e.cost; update = e.to; } if(update == n-1) flag = true; } if(update == -1) break; v++; cnt += flag; if(cnt > m+1) { loop = true; break; } } } int main(){ cin >> n >> m; rep(i, m){ cin >> es[i].from >> es[i].to >> es[i].cost; es[i].from--; es[i].to--; } serch(0); if(loop) cout << "inf" << endl; else cout << d[n-1] << endl; }
a.cc: In function 'void serch(int)': a.cc:39:9: error: 'v' was not declared in this scope 39 | v++; | ^
s586422344
p03722
C++
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> pii; typedef pair<ll, ll> pll; #define INF 1007654321 #define PI 3.14159265358979 #define rep(i, n) for(int i = 0; i < (n); ++i) #define repp(i, s, e) for(int i = (s); i <= (e); ++i) #define sz(x) ((int)x.size()) #define all(x) x.begin(), x.end() #define FAST_IO() ios::sync_with_stdio(0); cin.tie(0) template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { for (auto x : v) os << x << " "; return os << "\n"; } const int MAXN = 2000; const ll _MAX_ = 1e17; int N, M; struct Edge { int u, v; ll c; }; vector<Edge> edges; ll dist[MAXN]; int main() { FAST_IO(); cin >> N >> M; rep(i, M) { Edge e; cin >> e.u >> e.v >> e.c; e.u--; e.v--; e.c = -e.c; edges.push_back(e); } // Bellman-Ford rep(i, N) dist[i] = _MAX_; dist[0] = 0; rep(i, N) { for(auto &e : edges) { ll tmp = dist[V-1]; if(dist[e.u] != _MAX_ && dist[e.v] > dist[e.u] + e.c) { dist[e.v] = dist[e.u] + e.c; if(i == N - 1 && dist[V - 1] < tmp) { cout << "inf\n"; return 0; } } } } cout << -dist[N-1] << "\n"; }
a.cc: In function 'int main()': a.cc:42:27: error: 'V' was not declared in this scope 42 | ll tmp = dist[V-1]; | ^
s368912760
p03722
C++
#include <bits/stdc++.h> int main(){ cout<<"inf"<<endl; }
a.cc: In function 'int main()': a.cc:3:3: error: 'cout' was not declared in this scope; did you mean 'std::cout'? 3 | cout<<"inf"<<endl; | ^~~~ | std::cout In file included from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:146, from a.cc:1: /usr/include/c++/14/iostream:63:18: note: 'std::cout' declared here 63 | extern ostream cout; ///< Linked to standard output | ^~~~ a.cc:3:16: error: 'endl' was not declared in this scope; did you mean 'std::endl'? 3 | cout<<"inf"<<endl; | ^~~~ | std::endl In file included from /usr/include/c++/14/istream:41, from /usr/include/c++/14/sstream:40, from /usr/include/c++/14/complex:45, from /usr/include/c++/14/ccomplex:39, from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:127: /usr/include/c++/14/ostream:744:5: note: 'std::endl' declared here 744 | endl(basic_ostream<_CharT, _Traits>& __os) | ^~~~
s298104935
p03722
C++
#include<iostream> int main(){ cout<<"inf"<<endl; }
a.cc: In function 'int main()': a.cc:3:3: error: 'cout' was not declared in this scope; did you mean 'std::cout'? 3 | cout<<"inf"<<endl; | ^~~~ | std::cout In file included from a.cc:1: /usr/include/c++/14/iostream:63:18: note: 'std::cout' declared here 63 | extern ostream cout; ///< Linked to standard output | ^~~~ a.cc:3:16: error: 'endl' was not declared in this scope; did you mean 'std::endl'? 3 | cout<<"inf"<<endl; | ^~~~ | std::endl In file included from /usr/include/c++/14/iostream:41: /usr/include/c++/14/ostream:744:5: note: 'std::endl' declared here 744 | endl(basic_ostream<_CharT, _Traits>& __os) | ^~~~
s760120489
p03722
C++
#include <iostream> #include <string> #include <queue> #include <utility> #include <algorithm> #include <numeric> #include <set> #include <climits> #include <map> using namespace std; vector <pair <int, long long> > edges[1000]; long long max_d[1000]; int main(){ int N; int M; cin >> N >> M; for(int i = 0; i < M; i++){ int a; int b; long long c; cin >> a >> b >> c; edges[a - 1].push_back(make_pair(b - 1, c)); } for(int i = 1; i < N; i++){ max_d[i] = LLONG_MIN; } bool updated_N = false; int update_num = 0; for(int k = 0; k < 2; k++){ update_num = 0; while(true){ for(int i = 0; i < N; i++){ for(int j = 0; j < edges[i].size(); j++){ if(max_d[dst] == LLONG_MIN){ continue; } int dst = edges[i][j].first; long long cost = edges[i][j].second; if(max_d[dst] < max_d[i] + cost){ max_d[dst] = max_d[i] + cost; if(dst == N - 1 && k == 1){ updated_N = true; } } } } update_num ++; if(update_num > N){ break; } } } if(!updated_N){ cout << max_d[N - 1] << endl; } else { cout << "inf" << endl; } return 0; }
a.cc: In function 'int main()': a.cc:40:20: error: 'dst' was not declared in this scope 40 | if(max_d[dst] == LLONG_MIN){ | ^~~
s933605788
p03722
C++
#include <bits/stdc++.h> using namespace std; using ll = long long; using db = double; #define fi first #define se second #define pb push_back #define all(v) (v).begin(),(v).end() #define siz(v) (ll)(v).size() #define rep(i,n) for(ll i=0;i<(ll)(n);i++) #define repn(i,n) for(ll i=0;i<=(ll)(n);i++) typedef pair<int,int> P; typedef pair<ll,ll> PL; const ll mod = 1000000007; const ll INF = 20000000000099; vector<ll> BF(ll s,vector<vector<ll>>& v ,ll V){//Vは頂点の数 vector<ll> d(V,INF); d[s]=0; int cnt=0; bool update=false; while(1){ update=false; for(int i=0;i < (ll)v.size();i++) { for(int j=0;j < (ll)v.size();j++) { if(v[i][j]<INF && d[i] < INF/*更新済みか */ && d[j]> d[i]+v[i][j]){ update=true; d[j]=d[i]+v[i][j]; } } } if(!update)break; cnt++; //cout<<cnt<<endl; if(100V+1<=cnt){ d=vector<ll>(V,INF); break; } } return d; } signed main(){ ll n,m;cin>>n>>m; vector<vector<ll>> G(n,vector<ll>(n,INF)); for(int i=0;i < m;i++) { ll a,b,c;cin>>a>>b>>c; G[a-1][b-1]=-c; } vector<ll> ans=BF(0,G,n); if(ans[n-1]==INF)cout<<"inf"<<endl; else cout<<-ans[n-1]<<endl; }
a.cc: In function 'std::vector<long long int> BF(ll, std::vector<std::vector<long long int> >&, ll)': a.cc:39:8: error: unable to find numeric literal operator 'operator""V' 39 | if(100V+1<=cnt){ | ^~~~
s128894224
p03722
C++
#include <bits/stdc++.h> #define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i) #define repp(i, m, n) for(int i = m, i##_len = (n); i < i##_len; ++i) #define all(x) (x).begin(), (x).end() #define clr(ar, val) memset(ar, val, sizeof(ar)) template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } int gcd(int a,int b){return b?gcd(b,a%b):a;} using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair <int,int> P; typedef long double ld; constexpr int N_MAX = 1001; constexpr ll INF = 1000000000000000000; int n, m; vector<tuple<int, int, ll> > g; vector<tuple<ll, int> > v; int main(void) { cin >> n >> m; rep(i, n + 1) { v.push_back(make_tuple(INF, -1)); } v[1] = 0; rep(i, m) { int a, b, c; cin >> a >> b >> c; g.push_back(make_tuple(a, b, (ll)-c)); } rep(i, n) { rep(j, m) { int s = get<0>(g[j]), t = get<1>(g[j]); ll w = get<2>(g[j]); if(get<0>(v[t]) > get<0>(v[s]) + w) { v[t] = make_tuple(v[s] + w, s); } } } int now = n; while(now != -1) { int prev = get<1>(v[now]); if(get<0>(v[now]) > get<0>(v[prev]) + w) { cout << -1 << endl; return 0; } } cout << -v[n] << endl; return 0; }
a.cc: In function 'int main()': a.cc:29:16: error: no match for 'operator=' (operand types are '__gnu_cxx::__alloc_traits<std::allocator<std::tuple<long long int, int> >, std::tuple<long long int, int> >::value_type' {aka 'std::tuple<long long int, int>'} and 'int') 29 | v[1] = 0; | ^ In file included from /usr/include/c++/14/bits/memory_resource.h:47, from /usr/include/c++/14/string:68, from /usr/include/c++/14/bitset:52, from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52, from a.cc:1: /usr/include/c++/14/tuple:2355:9: note: candidate: 'template<class _U1, class _U2> std::__enable_if_t<((bool)__assignable<const _U1&, const _U2&>()), std::tuple<_T1, _T2>&> std::tuple<_T1, _T2>::operator=(const std::tuple<_U1, _U2>&) [with _U2 = _U1; _T1 = long long int; _T2 = int]' 2355 | operator=(const tuple<_U1, _U2>& __in) | ^~~~~~~~ /usr/include/c++/14/tuple:2355:9: note: template argument deduction/substitution failed: a.cc:29:16: note: mismatched types 'const std::tuple<_T1, _T2>' and 'int' 29 | v[1] = 0; | ^ /usr/include/c++/14/tuple:2365:9: note: candidate: 'template<class _U1, class _U2> std::__enable_if_t<((bool)__assignable<_U1, _U2>()), std::tuple<_T1, _T2>&> std::tuple<_T1, _T2>::operator=(std::tuple<_U1, _U2>&&) [with _U2 = _U1; _T1 = long long int; _T2 = int]' 2365 | operator=(tuple<_U1, _U2>&& __in) | ^~~~~~~~ /usr/include/c++/14/tuple:2365:9: note: template argument deduction/substitution failed: a.cc:29:16: note: mismatched types 'std::tuple<_T1, _T2>' and 'int' 29 | v[1] = 0; | ^ /usr/include/c++/14/tuple:2375:9: note: candidate: 'template<class _U1, class _U2> std::__enable_if_t<((bool)__assignable<const _U1&, const _U2&>()), std::tuple<_T1, _T2>&> std::tuple<_T1, _T2>::operator=(const std::pair<_U1, _U2>&) [with _U2 = _U1; _T1 = long long int; _T2 = int]' 2375 | operator=(const pair<_U1, _U2>& __in) | ^~~~~~~~ /usr/include/c++/14/tuple:2375:9: note: template argument deduction/substitution failed: a.cc:29:16: note: mismatched types 'const std::pair<_T1, _T2>' and 'int' 29 | v[1] = 0; | ^ /usr/include/c++/14/tuple:2386:9: note: candidate: 'template<class _U1, class _U2> std::__enable_if_t<((bool)__assignable<_U1, _U2>()), std::tuple<_T1, _T2>&> std::tuple<_T1, _T2>::operator=(std::pair<_U1, _U2>&&) [with _U2 = _U1; _T1 = long long int; _T2 = int]' 2386 | operator=(pair<_U1, _U2>&& __in) | ^~~~~~~~ /usr/include/c++/14/tuple:2386:9: note: template argument deduction/substitution failed: a.cc:29:16: note: mismatched types 'std::pair<_T1, _T2>' and 'int' 29 | v[1] = 0; | ^ /usr/include/c++/14/tuple:2332:7: note: candidate: 'std::tuple<_T1, _T2>& std::tuple<_T1, _T2>::operator=(std::__conditional_t<((bool)__assignable<const _T1&, const _T2&>()), const std::tuple<_T1, _T2>&, const std::__nonesuch&>) [with _T1 = long long int; _T2 = int; std::__conditional_t<((bool)__assignable<const _T1&, const _T2&>()), const std::tuple<_T1, _T2>&, const std::__nonesuch&> = const std::tuple<long long int, int>&]' 2332 | operator=(__conditional_t<__assignable<const _T1&, const _T2&>(), | ^~~~~~~~ /usr/include/c++/14/tuple:2334:52: note: no known conversion for argument 1 from 'int' to 'std::__conditional_t<true, const std::tuple<long long int, int>&, const std::__nonesuch&>' {aka 'const std::tuple<long long int, int>&'} 2332 | operator=(__conditional_t<__assignable<const _T1&, const _T2&>(), | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 2333 | const tuple&, | ~~~~~~~~~~~~~ 2334 | const __nonesuch&> __in) | ~~~~~~~~~~~~~~~~~~~^~~~ /usr/include/c++/14/tuple:2343:7: note: candidate: 'std::tuple<_T1, _T2>& std::tuple<_T1, _T2>::operator=(std::__conditional_t<((bool)__assignable<_T1, _T2>()), std::tuple<_T1, _T2>&&, std::__nonesuch&&>) [with _T1 = long long int; _T2 = int; std::__conditional_t<((bool)__assignable<_T1, _T2>()), std::tuple<_T1, _T2>&&, std::__nonesuch&&> = std::tuple<long long int, int>&&]' 2343 | operator=(__conditional_t<__assignable<_T1, _T2>(), | ^~~~~~~~ /usr/include/c++/14/tuple:2345:47: note: no known conversion for argument 1 from 'int' to 'std::__conditional_t<true, std::tuple<long long int, int>&&, std::__nonesuch&&>' {aka 'std::tuple<long long int, int>&&'} 2343 | operator=(__conditional_t<__assignable<_T1, _T2>(), | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 2344 | tuple&&, | ~~~~~~~~ 2345 | __nonesuch&&> __in) | ~~~~~~~~~~~~~~^~~~ a.cc:40:56: error: no match for 'operator+' (operand types are '__gnu_cxx::__alloc_traits<std::allocator<std::tuple<long long int, int> >, std::tuple<long long int, int> >::value_type' {aka 'std::tuple<long long int, int>'} and 'll' {aka 'long long int'}) 40 | v[t] = make_tuple(v[s] + w, s); In file included from /usr/include/c++/14/bits/stl_algobase.h:67, from /usr/include/c++/14/algorithm:60, from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51: /usr/include/c++/14/bits/stl_iterator.h:627:5: note: candidate: 'template<class _Iterator> constexpr std::reverse_iterator<_Iterator> std::operator+(typename reverse_iterator<_Iterator>::difference_type, const reverse_iterator<_Iterator>&)' 627 | operator+(typename reverse_iterator<_Iterator>::difference_type __n, | ^~~~~~~~ /usr/include/c++/14/bits/stl_iterator.h:627:5: note: template argument deduction/substitution failed: a.cc:40:58: note: mismatched types 'const std::reverse_iterator<_Iterator>' and 'll' {aka 'long long int'} 40 | v[t] = make_tuple(v[s] + w, s); | ^ /usr/include/c++/14/bits/stl_iterator.h:1798:5: note: candidate: 'template<class _Iterator> constexpr std::move_iterator<_IteratorL> std::operator+(typename move_iterator<_IteratorL>::difference_type, const move_iterator<_IteratorL>&)' 1798 | operator+(typename move_iterator<_Iterator>::difference_type __n, | ^~~~~~~~ /usr/include/c++/14/bits/stl_iterator.h:1798:5: note: template argument deduction/substitution failed: a.cc:40:58: note: mismatched types 'const std::move_iterator<_IteratorL>' and 'll' {aka 'long long int'} 40 | v[t] = make_tuple(v[s] + w, s); | ^ In file included from /usr/include/c++/14/string:54: /usr/include/c++/14/bits/basic_string.h:3598:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(const __cxx11::basic_string<_CharT, _Traits, _Allocator>&, const __cxx11::basic_string<_CharT, _Traits, _Allocator>&)' 3598 | operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs, | ^~~~~~~~ /usr/include/c++/14/bits/basic_string.h:3598:5: note: template argument deduction/substitution failed: a.cc:40:58: note: '__gnu_cxx::__alloc_traits<std::allocator<std::tuple<long long int, int> >, std::tuple<long long int, int> >::value_type' {aka 'std::tuple<long long int, int>'} is not derived from 'const std::__cxx11::basic_string<_CharT, _Traits, _Allocator>' 40 | v[t] = make_tuple(v[s] + w, s); | ^ /usr/include/c++/14/bits/basic_string.h:3616:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(const _CharT*, const __cxx11::basic_string<_CharT, _Traits, _Allocator>&)' 3616 | operator+(const _CharT* __lhs, | ^~~~~~~~ /usr/include/c++/14/bits/basic_string.h:3616:5: note: template argument deduction/substitution failed: a.cc:40:58: note: mismatched types 'const _CharT*' and 'std::tuple<long long int, int>' 40 | v[t] = make_tuple(v[s] + w, s); | ^ /usr/include/c++/14/bits/basic_string.h:3635:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(_CharT, const __cxx11::basic_string<_CharT, _Traits, _Allocator>&)' 3635 | operator+(_CharT __lhs, const basic_string<_CharT,_Traits,_Alloc>& __rhs) | ^~~~~~~~ /usr/include/c++/14/bits/basic_string.h:3635:5: note: template argument deduction/substitution failed: a.cc:40:58: note: mismatched types 'const std::__cxx11::basic_string<_CharT, _Traits, _Allocator>' and 'll' {aka 'long long int'} 40 | v[t] = make_tuple(v[s] + w, s); | ^ /usr/include/c++/14/bits/basic_string.h:3652:5: note: candidate: 'template<class _CharT, class _Traits, class _Alloc> std::__cxx11::basic_string<_CharT, _Traits, _Allocator> std::operator+(const __cxx11::basic_string<_CharT, _Traits, _Allocator>&, const _CharT*)' 3652 | operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs, | ^~~~~~~~ /usr/include/c++/14/bits/basic_string.h:3652:5: note: template argument deduction/substitution failed: a.cc:40:58: note: '__gnu_cxx::__alloc_traits<std::allocator<std::tuple<long long int, int> >, std::tuple<long long int, int> >::value_type' {aka 'std::tuple<long long int, int>'} is not derived from 'const std::__cxx11::basic_string<_CharT, _Traits, _Allocator>' 40 | v[t] = make_tuple(v[s] + w, s); | ^ /usr/include/c++/14/bits/basic
s242479553
p03722
C++
#include <bits/stdc++.h> using namespace std; const long long MOD = 1000000007LL; const long long INF = 1e18; long long GCD(long long a, long long b){return b == 0 ? a : GCD(b, a % b);} long long fast_exp(long long base, long long exp, long long mod = MOD) { long long tot = 1; for(;exp > 0;exp >>= 1) { if((exp & 1) == 1) tot = tot * base % mod; base = base * base % mod; } return tot; } long long slow_mult(long long base, long long exp, long long mod = MOD) { long long tot = 0; for(;exp > 0;exp >>= 1){ if((exp & 1) == 1) tot = (tot + base) % mod; base = base * 2 % mod; } return tot; } long long best[1003], c[2003]; int a[2003], b[2003]; int main(){ cin.sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m; cin >> n >> m; for(int i = 1; i <= n; ++i) best[i] = -INF; for(int i = 0; i < m; ++i) cin >> a[i] >> b[i] >> c[i]; best[1] = 0; for(int i = 1; i < n; ++i){ for(int j = 0; j < m; ++j){ if(best[a[j]] == -INF) continue; best[b[j]] = max(best[b[j]], best[a[j]] + c[j]); } } for(int j = 0; j < m; ++j){ if(best[a[j]] == -INF) continue; if(best[a[j]] + c[j] > best[b[j]]){ if(i == n - 1 && b[j] == n){ cout << "inf"; return 0; } } } cout << best[n]; return 0; }
a.cc: In function 'int main()': a.cc:51:16: error: 'i' was not declared in this scope 51 | if(i == n - 1 && b[j] == n){ | ^
s683934168
p03722
C++
#include<bits/stdc++.h> using namespace std; typedef long long ll; const ll INF = 1LL << 60; ll N,M; vector<vector<pair<ll,ll>>> to ; vector<ll> dist; int main(){ cin >> N >> M; dist = vector<ll> (N,INF); to.resize( N + 10); for(ll i = 0; i < M; i++){ ll a,b,c; cin >> a >> b >> c; a--; b--; c *= -1; to[a].push_back(make_pair(b,c));} bool closed = false; dist[0] = 0; for(ll i = 1; i <= 2 * N - 2; i++){ for(ll v = 0; v < N; v++){ if( dist[v] == INF){ continue;}// else{ if( to[v].empty()){ continue;} for( ll k = 0; k < to[v].size(); k++){ ll p = to[v][k].first; //vから繋がる先 ll q = to[v][k].second; // v- p間のコスト if( dist[p] > dist[v] + q){ dist[p] = dist[v] + q; if( i >= N && p == N - 1){ closed = true;}} }} }}
a.cc: In function 'int main()': a.cc:39:7: error: expected '}' at end of input 39 | }} | ^ a.cc:13:11: note: to match this '{' 13 | int main(){ | ^
s541764178
p03722
C++
#include<iostream> #include<vector> using namespace std; typedef long long ll; const ll INF = 1LL << 60; int main(){ ll N,M; cin >> N >> M; vector<pair<ll,ll>> to[1001] for(ll i = 0; i < M; i++){ ll a,b,w; cin >> a >> b >> w; a--; b--; w *= - 1; to[a] = make_pair(b,w);} vector<ll> dist(N,INF); dist[0] = 0; bool closed = false; for(ll i = 0; i < 2*N; i++){ for(ll v = 0; v < N; v++){ if(dist[v] = INF){ continue;} else{ //to[v]に格納されている辺に着目する 辺が主語 ll b = to[v].first; if(dist[b] > dist[v] + to[v].second){ dist[b] = dist[v] + to[v].second; if(b == N - 1 && i >= N){//N回目以降にノードN-1が更新されていないかを確認 closed = true;} }}}} if(closed){ cout << "inf" << endl;} else{ cout << -dist[N-1] << endl; } return 0;}
a.cc: In function 'int main()': a.cc:13:3: error: expected initializer before 'for' 13 | for(ll i = 0; i < M; i++){ | ^~~ a.cc:13:17: error: 'i' was not declared in this scope 13 | for(ll i = 0; i < M; i++){ | ^ a.cc:25:18: error: 'to' was not declared in this scope; did you mean 'tm'? 25 | ll b = to[v].first; | ^~ | tm
s803475247
p03722
C++
#include <bits/stdc++.h> using namespace std; struct edge { int to, cost; }; vector<edge> G[1000]; int N; vector<bool> used(1000); bool dfs(int v, long long depth, vector<long long> &dist) { if (used.at(v) && dist.at(v) >= 0) return true; else if (used.at(v) && dist.at(v) == -1) return false; used.at(v) = true; if (v == N) { dist.at(v) = depth; return true; } bool ret = false; for (int i = 0; i < (int)G[v].size(); i++) { ret |= dfs(G[v].at(i).to, depth + 1, dist); } if (ret) dist.at(v) = depth; else dist.at(v) = -1; return ret; } int main() { int n, m; cin >> n >> m; N = n - 1; for (int i = 0; i < m; i++) { int a, b, c; cin >> a >> b >> c; a--; b--; G[a].push_back(edge{b, c}); } vector<long long> dist(n, 0); dfs(0, 0, dist); for (int i = 0; i < n; i++) { for (int j = 0; j < (int)G[i].size(); j++) { if (dist.at(i) == -1 || dist.at(G[i].at(j).to) == -1) G[i].at(j).to = -1; } } vector<long long> x(n); x.at(0) = 0; for (int i = 1; i < n; i++) { x.at(i) = -LLONG_MAX; } for (int l = 0; l < n; l++){ for (int i = 0; i < n; i++) { if (dist.at(i) == -1) continue; for (int j = 0; j < (int)G[i].size(); j++) { if (G[i].at(j).to == -1) continue; x.at(G[i].at(j).to) = max(x.at(G[i].at(j).to), x.at(i) + G[i].at(j).cost); if (x.at(G[i].at(j).to)) > 10'000'000'000'000) { cout << "inf" << endl; return 0; } } } } long long maximum = x.at(n - 1); for (int i = 0; i < n; i++) { if (dist.at(i) == -1) continue; for (int j = 0; j < (int)G[i].size(); j++) { if (G[i].at(j).to == -1) continue; x.at(G[i].at(j).to) = max(x.at(G[i].at(j).to), x.at(i) + G[i].at(j).cost); if (x.at(G[i].at(j).to)) > 10'000'000'000'000) { cout << "inf" << endl; return 0; } } } if (maximum < x.at(n - 1)) cout << "inf" << endl; else cout << maximum << endl; }
a.cc: In function 'int main()': a.cc:67:42: error: expected primary-expression before '>' token 67 | if (x.at(G[i].at(j).to)) > 10'000'000'000'000) { | ^ a.cc:84:38: error: expected primary-expression before '>' token 84 | if (x.at(G[i].at(j).to)) > 10'000'000'000'000) { | ^
s295498386
p03722
C++
#include <algorithm> #include <bits/stdc++.h> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> using namespace std; #define rep(X, S, E) for (int(X) = (S); (X) < (E); ++(X)) #define rrep(X, S, E) for (int(X) = (E)-1; (X) >= (S); --(X)) #define itrep(X, Y) for (auto(X) = (Y).begin(); (X) != (Y).end(); (X)++) #define all(X) (X).begin(), (X).end() #define pb push_back #define mp make_pair #define fi first #define sc second #define print(x) cout << x << endl typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<ll> vl; const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}; const ll INF = 9 * 1e15; const ll MOD = 1e9 + 7; class UnionFindTree { private: vector<int> par; vector<int> rnk; vector<int> siz; public: UnionFindTree(int n) { par.assign(n, -1); rnk.assign(n, -1); siz.assign(n, -1); for (int i = 0; i < n; ++i) { par[i] = i; rnk[i] = 0; siz[i] = 1; } } int find(int x) { if (par[x] == x) return x; else return par[x] = find(par[x]); } bool same(int x, int y) { return find(x) == find(y); } void unite(int x, int y) { x = find(x); y = find(y); if (x == y) return; if (rnk[x] < rnk[y]) { par[x] = y; siz[y] += siz[x]; } else { par[y] = x; siz[x] += siz[y]; if (rnk[x] == rnk[y]) ++rnk[x]; } } int size(int x) { x = find(x); return siz[x]; } }; class Edge { public: ll from; ll to; ll cost; Edge() {} Edge(ll from, ll to, ll cost) { this->from = from; this->to = to; this->cost = cost; } bool operator<(const Edge &edge) const { return cost < edge.cost; //昇順 } bool operator>(const Edge &edge) const { return cost > edge.cost; //降順(std::greater) } }; class Graph { public: ll nodes; // ノード数 vector<Edge> edges; Graph() {} Graph(ll nodes) { this->nodes = nodes; } void addEdge(ll from, ll to, ll cost) { this->edges.push_back(Edge(from, to, cost)); } }; class Kruskal { private: Graph graph; vector<Edge> MinimumSpanningTree; ll minimumCost; void Kruskal::searchMinimumSpanningTree() { UnionFindTree uf(graph.nodes); sort(all(graph.edges)); itrep(edge, graph.edges) { if (!uf.same(edge->from, edge->to)) { uf.unite(edge->from, edge->to); MinimumSpanningTree.push_back(*edge); } } } public: Kruskal::Kruskal(Graph graph) { this->graph = graph; } ll Kruskal::getMinimumSpanningTreeCost() { searchMinimumSpanningTree(); ll cost = 0; itrep(it, MinimumSpanningTree) { cost += it->cost; } return cost; } }; // ベルマンフォード O(|V||E|) class BellmanFord { private: Graph graph; // 閉路が含まれるかは個々のノードごとに管理する必要あり vector<bool> hasNegativeCycles; vector<ll> distances; public: BellmanFord(Graph graph) { this->graph = graph; this->distances = vector<ll>(this->graph.nodes + 1, INF); this->hasNegativeCycles = vector<bool>(this->graph.nodes, false); } void searchMinimumPath(ll src) { this->distances[src] = 0; for (ll i = 0; i < graph.nodes - 1; i++) { itrep(edge, graph.edges) { ll u = edge->from; ll v = edge->to; ll w = edge->cost; if (this->distances[u] + w < this->distances[v]) { this->distances[v] = this->distances[u] + w; } } } itrep(edge, graph.edges) { ll u = edge->from; ll v = edge->to; ll w = edge->cost; if (this->distances[u] + w < this->distances[v]) { this->hasNegativeCycles[v] = true; } if (this->hasNegativeCycles[u] == true) { this->hasNegativeCycles[v] = true; } } } ll getDistance(ll n) { return this->distances[n]; } bool hasNegativeCycle(ll n) { return this->hasNegativeCycles[n]; } }; void solve(long long N, long long M, std::vector<long long> a, std::vector<long long> b, std::vector<long long> c) { Graph g(N); rep(m, 0, M) { g.addEdge(a[m], b[m], -c[m]); } BellmanFord bellmanFord(g); bellmanFord.searchMinimumPath(1); if (!bellmanFord.hasNegativeCycle(N)) { print(-bellmanFord.getDistance(N)); } else { print("inf"); } } int main() { long long N; scanf("%lld", &N); long long M; scanf("%lld", &M); std::vector<long long> a(M); std::vector<long long> b(M); std::vector<long long> c(M); for (int i = 0; i < M; i++) { scanf("%lld", &a[i]); scanf("%lld", &b[i]); scanf("%lld", &c[i]); } solve(N, M, std::move(a), std::move(b), std::move(c)); return 0; }
a.cc:129:8: error: extra qualification 'Kruskal::' on member 'searchMinimumSpanningTree' [-fpermissive] 129 | void Kruskal::searchMinimumSpanningTree() { | ^~~~~~~ a.cc:141:3: error: extra qualification 'Kruskal::' on member 'Kruskal' [-fpermissive] 141 | Kruskal::Kruskal(Graph graph) { this->graph = graph; } | ^~~~~~~ a.cc:142:6: error: extra qualification 'Kruskal::' on member 'getMinimumSpanningTreeCost' [-fpermissive] 142 | ll Kruskal::getMinimumSpanningTreeCost() { | ^~~~~~~
s334110030
p03722
C++
#include <algorithm> #include <bits/stdc++.h> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> using namespace std; #define rep(X, S, E) for (int(X) = (S); (X) < (E); ++(X)) #define rrep(X, S, E) for (int(X) = (E)-1; (X) >= (S); --(X)) #define itrep(X, Y) for (auto(X) = (Y).begin(); (X) != (Y).end(); (X)++) #define all(X) (X).begin(), (X).end() #define pb push_back #define mp make_pair #define fi first #define sc second #define print(x) cout << x << endl typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<ll> vl; const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}; const ll INF = 9 * 1e15; const ll MOD = 1e9 + 7; class Edge { public: ll from; ll to; ll cost; Edge() {} Edge(ll from, ll to, ll cost) { this->from = from; this->to = to; this->cost = cost; } bool operator<(const Edge &edge) const { return cost < edge.cost; //昇順 } bool operator>(const Edge &edge) const { return cost > edge.cost; //降順(std::greater) } }; class Graph { public: ll nodes; // ノード数 vector<Edge> edges; Graph() {} Graph(ll nodes) { this->nodes = nodes; } void addEdge(ll from, ll to, ll cost) { this->edges.push_back(Edge(from, to, cost)); } }; class Kruskal { private: Graph graph; vector<Edge> MinimumSpanningTree; ll minimumCost; void Kruskal::searchMinimumSpanningTree() { UnionFindTree uf(graph.nodes); sort(all(graph.edges)); itrep(edge, graph.edges) { if (!uf.same(edge->from, edge->to)) { uf.unite(edge->from, edge->to); MinimumSpanningTree.push_back(*edge); } } } public: Kruskal::Kruskal(Graph graph) { this->graph = graph; } ll Kruskal::getMinimumSpanningTreeCost() { searchMinimumSpanningTree(); ll cost = 0; itrep(it, MinimumSpanningTree) { cost += it->cost; } return cost; } }; // ベルマンフォード O(|V||E|) class BellmanFord { private: Graph graph; // 閉路が含まれるかは個々のノードごとに管理する必要あり vector<bool> hasNegativeCycles; vector<ll> distances; public: BellmanFord(Graph graph) { this->graph = graph; this->distances = vector<ll>(this->graph.nodes + 1, INF); this->hasNegativeCycles = vector<bool>(this->graph.nodes, false); } void searchMinimumPath(ll src) { this->distances[src] = 0; for (ll i = 0; i < graph.nodes - 1; i++) { itrep(edge, graph.edges) { ll u = edge->from; ll v = edge->to; ll w = edge->cost; if (this->distances[u] + w < this->distances[v]) { this->distances[v] = this->distances[u] + w; } } } itrep(edge, graph.edges) { ll u = edge->from; ll v = edge->to; ll w = edge->cost; if (this->distances[u] + w < this->distances[v]) { this->hasNegativeCycles[v] = true; } if (this->hasNegativeCycles[u] == true) { this->hasNegativeCycles[v] = true; } } } ll getDistance(ll n) { return this->distances[n]; } bool hasNegativeCycle(ll n) { return this->hasNegativeCycles[n]; } }; void solve(long long N, long long M, std::vector<long long> a, std::vector<long long> b, std::vector<long long> c) { Graph g(N); rep(m, 0, M) { g.addEdge(a[m], b[m], -c[m]); } BellmanFord bellmanFord(g); bellmanFord.searchMinimumPath(1); if (!bellmanFord.hasNegativeCycle(N)) { print(-bellmanFord.getDistance(N)); } else { print("inf"); } } int main() { long long N; scanf("%lld", &N); long long M; scanf("%lld", &M); std::vector<long long> a(M); std::vector<long long> b(M); std::vector<long long> c(M); for (int i = 0; i < M; i++) { scanf("%lld", &a[i]); scanf("%lld", &b[i]); scanf("%lld", &c[i]); } solve(N, M, std::move(a), std::move(b), std::move(c)); return 0; }
a.cc:79:8: error: extra qualification 'Kruskal::' on member 'searchMinimumSpanningTree' [-fpermissive] 79 | void Kruskal::searchMinimumSpanningTree() { | ^~~~~~~ a.cc:91:3: error: extra qualification 'Kruskal::' on member 'Kruskal' [-fpermissive] 91 | Kruskal::Kruskal(Graph graph) { this->graph = graph; } | ^~~~~~~ a.cc:92:6: error: extra qualification 'Kruskal::' on member 'getMinimumSpanningTreeCost' [-fpermissive] 92 | ll Kruskal::getMinimumSpanningTreeCost() { | ^~~~~~~ a.cc: In member function 'void Kruskal::searchMinimumSpanningTree()': a.cc:80:5: error: 'UnionFindTree' was not declared in this scope 80 | UnionFindTree uf(graph.nodes); | ^~~~~~~~~~~~~ a.cc:83:12: error: 'uf' was not declared in this scope 83 | if (!uf.same(edge->from, edge->to)) { | ^~
s100488697
p03722
C++
INF = float('inf') #vは頂点数、eは辺数 #s番目の頂点から各頂点への最短距離を求める def Bellmanford(n, e, s): d = [INF]*n d[s] = 0 for i in range(n): print(i) for e_from, e_to, e_cost in e: if d[e_from] != INF and d[e_to] > d[e_from] + e_cost: print("aaa") d[e_to] = d[e_from] + e_cost if i == n-1: return 'inf' return -d[n-1] n,m = (int(x) for x in input().split()) edges = [None] * m for i in range(m): ai, bi, ci = map(int, input().split()) edges[i] = (ai-1, bi-1, -ci) ans = Bellmanford(n, edges, 0) print(ans)
a.cc:1:13: warning: multi-character character constant [-Wmultichar] 1 | INF = float('inf') | ^~~~~ a.cc:2:2: error: extended character 、 is not valid in an identifier 2 | #vは頂点数、eは辺数 | ^ a.cc:2:2: error: invalid preprocessing directive #v\U0000306f\U00009802\U000070b9\U00006570\U00003001e\U0000306f\U00008fba\U00006570 2 | #vは頂点数、eは辺数 | ^~~~~~~~~~~~~~~~~~ a.cc:3:2: error: invalid preprocessing directive #s\U0000756a\U000076ee\U0000306e\U00009802\U000070b9\U0000304b\U00003089\U00005404\U00009802\U000070b9\U00003078\U0000306e\U00006700\U000077ed\U00008ddd\U000096e2\U00003092\U00006c42\U00003081\U0000308b 3 | #s番目の頂点から各頂点への最短距離を求める | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ a.cc:14:18: warning: multi-character character constant [-Wmultichar] 14 | return 'inf' | ^~~~~ a.cc:1:1: error: 'INF' does not name a type 1 | INF = float('inf') | ^~~
s663090462
p03722
C++
#include <iostream> #include <vector> #include <queue> #include <string.h> #include <limits.h> using namespace std; typedef long long ll; ll INF=1e18; struct edge { ll from, to, cost; }; edge es[2005]; ll d[1005]; ll v, e; bool neg = false; void shortest_path(int s) { for (int i = 0; i < v; i++) d[i] = INF; d[s] = 0; int l; for (int i = 0; i < v; i++) { bool update = false; for (int j = 0; j < e; j++) { edge e = es[j]; if (d[e.from] != INF && d[e.to] > d[e.from] + e.cost) { d[e.to] = d[e.from] + e.cost; update = true; if (i == v - 1 && d[v - 1] != l;) { neg = true; } } } if (!update) break; l = d[v - 1]; } } int main(void){ cin >> v >> e; for (int i = 0; i < e; i++) { ll pt; cin >> es[i].from >> es[i].to >> pt; es[i].from--; es[i].to--; es[i].cost = -pt; } shortest_path(0); if (neg) cout << "inf" << endl; else { cout << -d[v - 1] << endl; } }
a.cc: In function 'void shortest_path(int)': a.cc:28:49: error: expected primary-expression before ')' token 28 | if (i == v - 1 && d[v - 1] != l;) { | ^
s478786395
p03722
C++
#include <bits/stdc++.h> using namespace std; #define _for(i,j,N) for(int i = (j);i < (N);i++) #define _rep(i,j,N) for(int i = (j);i <= (N);i++) #define ALL(x) x.begin(),x.end() #define pb push_back #define mk make_pair typedef long long LL; typedef pair<int,int> Interval; template<typename T> ostream& operator<<(ostream& os,const vector<T>& v) { _for(i,0,v.size()) os << v[i] << " "; return os; } template<typename T> ostream& operator<<(ostream& os,const set<T>& v){ for(typename set<T>::iterator it = v.begin();it != v.end();it++) os << *it <<" "; return os; } const int maxn = 1005; LL INF = 1e18; struct Edge{ int from,to,w; Edge(int u = 0,int v = 0,int w = 0):from(u),to(v),w(w){;} }; int inq[maxn]; int cnt[maxn]; LL d[maxn]; int N,M; vector<int> G[maxn]; vector<Edge> edges; bool bellman_ford(int s){ queue<int> Q; memset(inq,0,sizeof(inq)); memset(cnt,0,sizeof(cnt)); _rep(i,0,N) d[i] = INF; d[s] = 0; inq[s] = true; Q.push(s); while(!Q.empty()){ int u = Q.front();Q.pop(); inq[u] = false; for(int i = 0;i < G[u].size();i++){ Edge &e = edges[G[u][i]]; if(d[u] < INF && d[e.to] > d[u] + e.w){ d[e.to] = d[u] + e.w; } if(!inq[e.to]){ Q.push(e.to); inq[e.to] = true; if(++cnt[e.to] > N) return false; } } } return true; }
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/14/../../../x86_64-linux-gnu/Scrt1.o: in function `_start': (.text+0x17): undefined reference to `main' collect2: error: ld returned 1 exit status
s478617753
p03722
C++
#include <algorithm> #include <bits/stdc++.h> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> using namespace std; #define rep(X, S, E) for (int(X) = (S); (X) < (E); ++(X)) #define rrep(X, S, E) for (int(X) = (E)-1; (X) >= (S); --(X)) #define itrep(X, Y) for (auto(X) = (Y).begin(); (X) != (Y).end(); (X)++) #define all(X) (X).begin(), (X).end() #define pb push_back #define mp make_pair #define fi first #define sc second #define print(x) cout << x << endl typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<ll> vl; const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}; const ll INF = 9 * 1e15; const ll MOD = 1e9 + 7; // O(|V||E|) class Graph { private: ll V; // 0index vector<pair<ll, pll>> edges; vector<bool> hasNegativeCycles; vector<ll> dist; public: Graph(ll V); void addEdge(ll u, ll v, ll w); void bellmanFord(ll src); ll getDistance(ll n); bool hasNegativeCycle(ll n); }; Graph::Graph(ll V) { this->V = V; this->dist = vector<ll>(this->V, INF); this->hasNegativeCycles = vector<bool>(this->V, false); } void Graph::addEdge(ll u, ll v, ll w) { edges.push_back({w, {u, v}}); } void Graph::bellmanFord(ll src) { this->dist[src] = 0; vector<pair<ll, pair<ll, ll>>>::iterator it; for (ll i = 0; i < this->V - 1; i++) { for (it = edges.begin(); it != edges.end(); ++it) { ll u = it->second.first; ll v = it->second.second; ll w = it->first; if (this->dist[u] + w < this->dist[v]) { this->dist[v] = this->dist[u] + w; } } } for (it = edges.begin(); it != edges.end(); ++it) { ll u = it->second.first; ll v = it->second.second; ll w = it->first; if (this->dist[u] + w < this->dist[v]) { this->hasNegativeCycles[v] = true; } if (this->hasNegativeCycles[u] == true) { this->hasNegativeCycles[v] = true; } } } ll Graph::getDistance(ll n) { return this->dist[n]; } bool Graph::hasNegativeCycle(ll n) { return this->hasNegativeCycles[n]; } void solve(long long N, long long M, std::vector<long long> a, std::vector<long long> b, std::vector<long long> c) { Graph g(N); rep(m, 0, M) { g.addEdge(a[m] - 1, b[m] - 1, -c[m]); } g.bellmanFord(0); if (!g.hasNegativeCycle()) { print(-g.getDistance(N - 1)); } else { print("inf"); } } int main() { long long N; scanf("%lld", &N); long long M; scanf("%lld", &M); std::vector<long long> a(M); std::vector<long long> b(M); std::vector<long long> c(M); for (int i = 0; i < M; i++) { scanf("%lld", &a[i]); scanf("%lld", &b[i]); scanf("%lld", &c[i]); } solve(N, M, std::move(a), std::move(b), std::move(c)); return 0; }
a.cc: In function 'void solve(long long int, long long int, std::vector<long long int>, std::vector<long long int>, std::vector<long long int>)': a.cc:97:26: error: no matching function for call to 'Graph::hasNegativeCycle()' 97 | if (!g.hasNegativeCycle()) { | ~~~~~~~~~~~~~~~~~~^~ a.cc:89:6: note: candidate: 'bool Graph::hasNegativeCycle(ll)' 89 | bool Graph::hasNegativeCycle(ll n) { return this->hasNegativeCycles[n]; } | ^~~~~ a.cc:89:6: note: candidate expects 1 argument, 0 provided
s426845156
p03722
C++
#include <algorithm> #include <bits/stdc++.h> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> using namespace std; #define rep(X, S, E) for (int(X) = (S); (X) < (E); ++(X)) #define rrep(X, S, E) for (int(X) = (E)-1; (X) >= (S); --(X)) #define itrep(X, Y) for (auto(X) = (Y).begin(); (X) != (Y).end(); (X)++) #define all(X) (X).begin(), (X).end() #define pb push_back #define mp make_pair #define fi first #define sc second #define print(x) cout << x << endl typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<ll> vl; const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}; const ll INF = 9 * 1e18; const ll MOD = 1e9 + 7; ll goal; // O(|V||E|) class Graph { private: ll V; // 1index. 1-Vまで vector<pair<ll, pll>> edges; bool _hasNegativeCycle = false; vector<ll> dist; public: Graph(ll V); void addEdge(ll u, ll v, ll w); void bellmanFord(ll src); ll getDistance(ll n); bool hasNegativeCycle(); }; Graph::Graph(ll V) { this->V = V; this->dist = vector<ll>(this->V + 1, INF); } void Graph::addEdge(ll u, ll v, ll w) { edges.push_back({w, {u, v}}); } void Graph::bellmanFord(ll src) { this->dist[src] = 0; vector<pair<ll, pair<ll, ll>>>::iterator it; for (ll i = 1; i <= this->V; i++) { for (it = edges.begin(); it != edges.end(); ++it) { ll u = it->second.first; ll v = it->second.second; ll w = it->first; if (this->dist[u] + w < this->dist[v]) { this->dist[v] = this->dist[u] + w; } } } for (it = edges.begin(); it != edges.end(); ++it) { ll u = it->second.first; ll v = it->second.second; ll w = it->first; if (this->dist[u] + w < this->dist[v]) { this->_hasNegativeCycle = true; } } } ll Graph::getDistance(ll n) { return this->dist[n]; } bool Graph::hasNegativeCycle() { return this->_hasNegativeCycle; } void solve(long long N, long long M, std::vector<long long> a, std::vector<long long> b, std::vector<long long> c) { Graph g(N); rep(m, 0, M) { g.addEdge(a[m], b[m], -c[m]); } g.bellmanFord(1); if (!g.hasNegativeCycle()) { print(-g.getDistance[N]); } else { print("inf"); } } int main() { long long N; scanf("%lld", &N); long long M; scanf("%lld", &M); std::vector<long long> a(M); std::vector<long long> b(M); std::vector<long long> c(M); for (int i = 0; i < M; i++) { scanf("%lld", &a[i]); scanf("%lld", &b[i]); scanf("%lld", &c[i]); } solve(N, M, std::move(a), std::move(b), std::move(c)); return 0; }
a.cc: In function 'void solve(long long int, long long int, std::vector<long long int>, std::vector<long long int>, std::vector<long long int>)': a.cc:96:25: error: invalid types '<unresolved overloaded function type>[long long int]' for array subscript 96 | print(-g.getDistance[N]); | ^ a.cc:28:26: note: in definition of macro 'print' 28 | #define print(x) cout << x << endl | ^
s759833275
p03722
C++
#include <algorithm> #include <bits/stdc++.h> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> using namespace std; #define rep(X, S, E) for (int(X) = (S); (X) < (E); ++(X)) #define rrep(X, S, E) for (int(X) = (E)-1; (X) >= (S); --(X)) #define itrep(X, Y) for (auto(X) = (Y).begin(); (X) != (Y).end(); (X)++) #define all(X) (X).begin(), (X).end() #define pb push_back #define mp make_pair #define fi first #define sc second #define print(x) cout << x << endl typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<ll> vl; const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}; const ll INF = 9 * 1e18; const ll MOD = 1e9 + 7; ll goal; // O(|V||E|) class Graph { private: ll V; // 1index. 1-Vまで vector<pair<ll, pll>> edges; bool _hasNegativeCycle = false; vector<ll> dist; public: Graph(ll V); void addEdge(ll u, ll v, ll w); void bellmanFord(ll src); ll getDistance(ll n); bool hasNegativeCycle(); }; Graph::Graph(ll V) { this->V = V; this->dist = vector<ll>(this->V, INF); } void Graph::addEdge(ll u, ll v, ll w) { edges.push_back({w, {u, v}}); } void Graph::bellmanFord(ll src) { this->dist[src] = 0; vector<pair<ll, pair<ll, ll>>>::iterator it; for (ll i = 1; i <= this->V; i++) { for (it = edges.begin(); it != edges.end(); ++it) { ll u = it->second.first; ll v = it->second.second; ll w = it->first; if (this->dist[u] + w < this->dist[v]) { this->dist[v] = this->dist[u] + w; } } } for (it = edges.begin(); it != edges.end(); ++it) { ll u = it->second.first; ll v = it->second.second; ll w = it->first; if (this->dist[u] + w < this->dist[v]) { this->_hasNegativeCycle = true; } } } ll Graph::getDistance(ll n) { return this->dist[n]; } bool Graph::hasNegativeCycle() { return this->_hasNegativeCycle; } void solve(long long N, long long M, std::vector<long long> a, std::vector<long long> b, std::vector<long long> c) { Graph g(N); rep(m, 0, M) { g.addEdge(a[m], b[m], -c[m]); } g.bellmanFord(1); if (!g.hasNegativeCycle()) { print(-g.getDistance[N]); } else { print("inf"); } } int main() { long long N; scanf("%lld", &N); long long M; scanf("%lld", &M); std::vector<long long> a(M); std::vector<long long> b(M); std::vector<long long> c(M); for (int i = 0; i < M; i++) { scanf("%lld", &a[i]); scanf("%lld", &b[i]); scanf("%lld", &c[i]); } solve(N, M, std::move(a), std::move(b), std::move(c)); return 0; }
a.cc: In function 'void solve(long long int, long long int, std::vector<long long int>, std::vector<long long int>, std::vector<long long int>)': a.cc:96:25: error: invalid types '<unresolved overloaded function type>[long long int]' for array subscript 96 | print(-g.getDistance[N]); | ^ a.cc:28:26: note: in definition of macro 'print' 28 | #define print(x) cout << x << endl | ^
s525846353
p03722
C++
#include <algorithm> #include <bits/stdc++.h> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> using namespace std; #define rep(X, S, E) for (int(X) = (S); (X) < (E); ++(X)) #define rrep(X, S, E) for (int(X) = (E)-1; (X) >= (S); --(X)) #define itrep(X, Y) for (auto(X) = (Y).begin(); (X) != (Y).end(); (X)++) #define all(X) (X).begin(), (X).end() #define pb push_back #define mp make_pair #define fi first #define sc second #define print(x) cout << x << endl typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<ll> vl; const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}; const ll INF = 9 * 1e18; const ll MOD = 1e9 + 7; ll goal; // O(|V||E|) class Graph { private: ll V; // 1index. 1-Vまで vector<pair<ll, pll>> edges; bool _hasNegativeCycle = false; vector<ll> dist(this->V, INF); public: Graph(ll V); void addEdge(ll u, ll v, ll w); void bellmanFord(ll src); ll getDistance(ll n); bool hasNegativeCycle(); }; Graph::Graph(ll V) { this->V = V; } void Graph::addEdge(ll u, ll v, ll w) { edges.push_back({w, {u, v}}); } void Graph::bellmanFord(ll src) { this->dist[src] = 0; vector<pair<ll, pair<ll, ll>>>::iterator it; for (ll i = 1; i <= this->V; i++) { for (it = edges.begin(); it != edges.end(); ++it) { ll u = it->second.first; ll v = it->second.second; ll w = it->first; if (this->dist[u] + w < this->dist[v]) { this->dist[v] = this->dist[u] + w; } } } for (it = edges.begin(); it != edges.end(); ++it) { ll u = it->second.first; ll v = it->second.second; ll w = it->first; if (this->dist[u] + w < this->dist[v]) { this->_hasNegativeCycle = true; } } } ll Graph::getDistance(ll n) { return this->dist[n]; } bool Graph::hasNegativeCycle() { return this->_hasNegativeCycle; } void solve(long long N, long long M, std::vector<long long> a, std::vector<long long> b, std::vector<long long> c) { Graph g(N); rep(m, 0, M) { g.addEdge(a[m], b[m], -c[m]); } g.bellmanFord(1); if (!g.hasNegativeCycle()) { print(-g.getDistance[N]); } else { print("inf"); } } int main() { long long N; scanf("%lld", &N); long long M; scanf("%lld", &M); std::vector<long long> a(M); std::vector<long long> b(M); std::vector<long long> c(M); for (int i = 0; i < M; i++) { scanf("%lld", &a[i]); scanf("%lld", &b[i]); scanf("%lld", &c[i]); } solve(N, M, std::move(a), std::move(b), std::move(c)); return 0; }
a.cc:48:23: error: expected identifier before '->' token 48 | vector<ll> dist(this->V, INF); | ^~ a.cc:48:23: error: expected ',' or '...' before '->' token a.cc:48:19: warning: explicit object member function only available with '-std=c++23' or '-std=gnu++23' [-Wc++23-extensions] 48 | vector<ll> dist(this->V, INF); | ^~~~~~ a.cc: In member function 'void Graph::bellmanFord(ll)': a.cc:60:13: error: invalid types '<unresolved overloaded function type>[ll {aka long long int}]' for array subscript 60 | this->dist[src] = 0; | ^ a.cc:68:21: error: invalid types '<unresolved overloaded function type>[ll {aka long long int}]' for array subscript 68 | if (this->dist[u] + w < this->dist[v]) { | ^ a.cc:68:41: error: invalid types '<unresolved overloaded function type>[ll {aka long long int}]' for array subscript 68 | if (this->dist[u] + w < this->dist[v]) { | ^ a.cc:69:19: error: invalid types '<unresolved overloaded function type>[ll {aka long long int}]' for array subscript 69 | this->dist[v] = this->dist[u] + w; | ^ a.cc:69:35: error: invalid types '<unresolved overloaded function type>[ll {aka long long int}]' for array subscript 69 | this->dist[v] = this->dist[u] + w; | ^ a.cc:78:19: error: invalid types '<unresolved overloaded function type>[ll {aka long long int}]' for array subscript 78 | if (this->dist[u] + w < this->dist[v]) { | ^ a.cc:78:39: error: invalid types '<unresolved overloaded function type>[ll {aka long long int}]' for array subscript 78 | if (this->dist[u] + w < this->dist[v]) { | ^ a.cc: In member function 'll Graph::getDistance(ll)': a.cc:83:48: error: invalid types '<unresolved overloaded function type>[ll {aka long long int}]' for array subscript 83 | ll Graph::getDistance(ll n) { return this->dist[n]; } | ^ a.cc: In function 'void solve(long long int, long long int, std::vector<long long int>, std::vector<long long int>, std::vector<long long int>)': a.cc:93:25: error: invalid types '<unresolved overloaded function type>[long long int]' for array subscript 93 | print(-g.getDistance[N]); | ^ a.cc:28:26: note: in definition of macro 'print' 28 | #define print(x) cout << x << endl | ^
s242974999
p03722
C++
#include<bits/stdc++.h> using namespace std; long long INF = - 1'000'000'000'000'000'000; int main(){ int n, m; cin >> n >> m; struct edge { long long from, to, cost; }; vector<edge> es(m); for (int i = 0; i < m; i++){ cin >> es[i].from >> es[i].to >> es[i].cost; } vector<long long> distance(n, INF); distance[0] = 0; int cnt = 0; while (1){ bool flag = false; for (int i = 0; i < m; i++){ bool up = false; edge e = es[i]; if (distance[e.from - 1] != INF && distance[e.to - 1] < distance[e.from - 1] + e.cost){ distance[e.to - 1] = distance[e.from - 1] + e.cost; flag = true; if (cnt >= n - 1){ cout << "inf" << endl; exit(0); } } } cnt++; if (flag == false) break; } if (distance[i - 1] == INF) cout << distance[100000000] << endl; cout << distance[n - 1] << endl; }
a.cc: In function 'int main()': a.cc:41:18: error: 'i' was not declared in this scope 41 | if (distance[i - 1] == INF) cout << distance[100000000] << endl; | ^
s814464477
p03722
C++
#include<bits/stdc++.h> using namespace std; long long INF = - 1'000'000'000'000'000'000; int main(){ int n, m; cin >> n >> m; struct edge { long long from, to, cost; }; vector<edge> es(m); for (int i = 0; i < m; i++){ cin >> es[i].from >> es[i].to >> es[i].cost; } vector<long long> distance(n, INF); distance[0] = 0; int cnt = 0; while (1){ bool flag = false; for (int i = 0; i < m; i++){ bool up = false; edge e = es[i]; if (distance[e.from - 1] != INF && distance[e.to - 1] < distance[e.from - 1] + e.cost){ distance[e.to - 1] = distance[e.from - 1] + e.cost; flag = true; if (cnt >= n - 1){ cout << "inf" << endl; exit(0); } } } cnt++; if (flag == false) break; } if (distance[i - 1] == INF) cout << distance[INF] << endl; cout << distance[n - 1] << endl; }
a.cc: In function 'int main()': a.cc:41:18: error: 'i' was not declared in this scope 41 | if (distance[i - 1] == INF) cout << distance[INF] << endl; | ^
s641300947
p03722
C++
#include <bits/stdc++.h> #define REP(i, n) for(ll i = 0; i < (ll)n; i++) #define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++) #define ALL(obj) (obj).begin(), (obj).end() #define INF 1000000000000000 using namespace std; typedef long long ll; typedef double db; typedef string str; typedef pair<ll, ll> p; constexpr int MOD = 1000000007; template <class T> inline bool chmin(T &a, T b) { if(a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if(a < b) { a = b; return true; } return false; } void print(const std::vector<int> &v) { std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; }); std::cout << std::endl; } // http://drken1215.hatenablog.com/entry/2019/02/16/075900 using Edge = pair<int, long long>; int N, M; vector<vector<Edge>> G; int main() { int N, M; cin >> N >> M; G.resize(N); REP(i, M) { int a, b; long long w; cin >> a >> b >> w; a--; b--; G[a].push_back(Edge(b, -w)); } vector<long long> dist(N, INF); bool negative = false; dist[0] = 0; for(int iter = 0; iter <= N * 2; iter++) { for(int v = 0; v < N; v++) { // vertex if(dist[v] >= INF / 2) { continue; } //なんで for(auto e : G[v]) { if(chmin(dist[e.first], dist[v] + e.second)) { if(e.first == N - 1 and iter == N * 2) { negation = true; //壊れてる } } } } } if(!negative) { cout << -dist[N - 1] << endl; } else { cout << "inf" << endl; } }
a.cc: In function 'int main()': a.cc:60:34: error: expected unqualified-id before '=' token 60 | negation = true; //壊れてる | ^
s212895333
p03722
C++
#include "bits/stdc++.h" using namespace std; #define rep(i,a,n) for(ll i=a;i<n;i++) #define ALL(s) s.begin(),s.end() #define P pair<int,int> #define vi vector<int> #define vl vector<ll> #define vvi vector<vector<int>> #define vvl vector<vector<ll>> #define print(n) cout<<n<<endl const int M=100010; const int MOD=1000000007; const int inf=1000000007; const long long INF=1000000000000000007; using ll=long long; int main(){ ll n,m,a,b,c; ll,dp[1010][1010]={}; cin>>n>>m; rep(i,1,n+1)rep(j,1,n+1){ if(i!=j)dp[i][j]=-INF; } rep(i,0,m)cin>>a>>b>>c,dp[a][b]=c; rep(k,1,n+1)rep(i,1,n+1){ if(dp[i][k]==-INF)continue; rep(j,1,n+1)if(dp[i][k]+dp[k][j]>dp[i][j]) dp[i][j]=dp[i][k]+dp[k][j]; } dp[1][1]>0?print("inf"):print(dp[1][n]); return 0; }
a.cc: In function 'int main()': a.cc:20:11: error: expected unqualified-id before ',' token 20 | ll,dp[1010][1010]={}; | ^
s027594756
p03722
C++
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define rep1(i, n) for (ll i = 1; i < (ll)(n); i++) const ll mo = 1000000007; const ll INF = 1LL << 60; //MAX 9223372036854775807 ll ans = 0; int main() { ll n,m; cin >> n>>m; vector<pair<ll,ll> > G[n+1]; ll maxa=0; rep(i, m) { ll a,b,c; cin >> a>>b>>c; G[a].push_back(pair<ll,ll>(b, c)); maxa+=c } ll cost[n+1]; rep(i,n+1){ cost[i]=INF; } queue<ll> qq; qq.push(1); cost[1]=0; ll cou=0; while(!qq.empty()){ ll p = qq.front(); qq.pop(); rep(i,G[p].size()){ if(cost[G[p][i].first]==INF){ cost[G[p][i].first]=G[p][i].second+cost[p]; qq.push(G[p][i].first); } else{ if(G[p][i].second+cost[p]>cost[G[p][i].first]){ cost[G[p][i].first]=G[p][i].second+cost[p]; if(cost[G[p][i].first]<maxa)qq.push(G[p][i].first); if(G[p][i].first==n)cou++; } if(n<cou){ cout << "inf" << endl; return 0; } } } } cout << cost[n] << endl; return 0; }
a.cc: In function 'int main()': a.cc:21:12: error: expected ';' before '}' token 21 | maxa+=c | ^ | ; 22 | } | ~
s031665523
p03722
C++
#include "bits/stdc++.h" using namespace std; #define rep(i,a,n) for(ll i=a;i<n;i++) #define ALL(s) s.begin(),s.end() #define P pair<int,int> #define vi vector<int> #define vl vector<ll> #define vvi vector<vector<int>> #define vvl vector<vector<ll>> #define print(n) cout<<n<<endl const int M=100010; const int MOD=1000000007; const int INF=1000000007; using ll=long long; bool used[1010]={}; ll dist[1010]; int n,m,a,b,c; vvl g(1010,vl(1010)); ll ans=0; void dfs(int cur){ used[cur]=true; rep(i,1,n+1){ if(g[cur][i]){ if(!used[i]){ dist[i]=dist[cur]+g[cur][i]; used[i]=true; dfs(i); }else{ // if(dist[cur]+g[cur][i]>dist[i]){ dist[n]=-1; return; } } } } } int main(){ cin>>n>>m; rep(i,0,m){ cin>>a>>b>>c; g[a][b]=c; } rep(i,1,n+1)dist[i]=INF; dist[1]=0; dfs(1); if(dist[n]==-1)print("inf"); else print(dist[n]); }
a.cc:38:1: error: expected declaration before '}' token 38 | } | ^
s557864408
p03722
C++
#include<bits/stdc++.h> using namespace std; const long long INF=1e12; struct edge{int from,to,cost;}; edge es[2000]; long long d[1000]; int V,E; void shortest_path(int s){ for(int i=0;i<V;i++) d[i]=INF; d[s]=0; for(int i=0;i<V;i++) for(int j=0;j<E;j++){ edge e=es[j]; if(d[e.from]!=INF&&d[e.to]>d[e.from]+e.cost) d[e.to]=d[e.from]+e.cost; } } } bool find_negative_loop(){ memset(d,0,sizeof(d)); for(int i=0;i<2*V;i++){ for(int j=0;j<E;j++){ edge e=es[i]; if(d[e.to]>d[e.from]+e.cost){ d[e.to]=d[e.from]+e.cost; if(i>=V-1&&e.to==V-1) return true; } } } return false; } int main(){ cin>>V>>E; int a,b,c; for(int i=0;i<E;i++){ cin>>a>>b>>c; es[i]=(edge){a-1,b-1,-c}; } if(find_negative_loop()){ cout<<"inf"<<endl; return 0; } shortest_path(0); cout<<-d[V-1]<<endl; }
a.cc:19:1: error: expected declaration before '}' token 19 | } | ^
s387021747
p03722
C++
#include<bits/stdc++.h> using namespace std; const long long INF=1e12; struct edge{long long from,to,cost;}; edge es[2000]; long long d[1000]; long long V,E; void shortest_path(long long s){ for(long long i=0;i<V;i++) d[i]=INF; d[s]=0; while(true){ bool update=false; for(long long i=0;i<E;i++){ edge e=es[i]; if(d[e.from]!=INF&&d[e.to]>d[e.from]+e.cost){ d[e.to]=d[e.from]+e.cost; update=true; } } if(!update) break; } } bool find_negative_loop(){ memset(d,0,sizeof(d)); for(long long i=0;i<2*V;i++){ for(long long j=0;j<E;j++){ edge e=es[i]; if(d[e.to]>d[e.from]+e.cost){ d[e.to]=d[e.from]+e.cost; if(i=>V-1&&e.to==V-1) return true; } } } return false; } int main(){ cin>>V>>E; long long a,b,c; for(long long i=0;i<E;i++){ cin>>a>>b>>c; es[i]=(edge){a-1,b-1,-c}; } if(find_negative_loop()){ cout<<"inf"<<endl; return 0; } shortest_path(0); cout<<-d[V-1]<<endl; }
a.cc: In function 'bool find_negative_loop()': a.cc:32:38: error: expected primary-expression before '>' token 32 | if(i=>V-1&&e.to==V-1) | ^
s953981976
p03722
C++
#include<bits/stdc++.h> using namespace std; const long long INF=1e12; struct edge{long long from,to,cost;}; edge es[2000]; long long d[1000]; long long V,E; void shortest_path(long long s){ for(long long i=0;i<V;i++) d[i]=INF; d[s]=0; while(true){ bool update=false; for(long long i=0;i<E;i++){ edge e=es[i]; if(d[e.from]!=INF&&d[e.to]>d[e.from]+e.cost){ d[e.to]=d[e.from]+e.cost; update=true; } } if(!update) break; } } bool find_negative_loop(){ memset(d,0,sizeof(d)); for(long long i=0;i<V;i++){ for(long long j=0;j<E;j++){ edge e=es[i]; if(d[e.to]>d[e.from]+e.cost){ d[e.to]=d[e.from]+e.cost; if(i==V-1) return true; } } } return false; } long long main(){ cin>>V>>E; long long a,b,c; for(long long i=0;i<E;i++){ cin>>a>>b>>c; es[i]=(edge){a-1,b-1,-c}; } if(find_negative_loop()){ cout<<"inf"<<endl; return 0; } shortest_path(0); cout<<-d[V-1]<<endl; }
cc1plus: error: '::main' must return 'int'
s181171751
p03722
C++
#include <bits/stdc++.h> using namespace std; //#define int long long //TEMPLATE START---------------8<---------------8<---------------8<---------------8<---------------// typedef long long ll; typedef long double ld; typedef pair<int,int> pii; typedef pair<ll,ll> pll; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<string> vst; typedef vector<bool> vb; typedef vector<ld> vld; typedef vector<pii> vpii; typedef vector<pll> vpll; typedef vector<vector<int> > vvi; const int INF = (0x7FFFFFFFL); const ll INFF = (0x7FFFFFFFFFFFFFFFL); const string ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; const int MOD = 1e9 + 7; const int MODD = 998244353; const string alphabet = "abcdefghijklmnopqrstuvwxyz"; const double PI = acos(-1.0); const double EPS = 1e-9; const string Alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; int dx[9] = { 1, 0, -1, 0, 1, -1, -1, 1, 0 }; int dy[9] = { 0, 1, 0, -1, -1, -1, 1, 1, 0 }; #define ln '\n' #define scnaf scanf #define sacnf scanf #define sancf scanf #define SS(type, ...)type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__); template<typename T> void MACRO_VAR_Scan(T& t){cin >> t;}template<typename First, typename...Rest> void MACRO_VAR_Scan(First& first, Rest&...rest){cin >> first;MACRO_VAR_Scan(rest...);} #define SV(type,c,n) vector<type> c(n);for(auto& i:c)cin >> i; #define SVV(type,c,n,m) vector<vector<type>> c(n,vector<type>(m));for(auto& r:c)for(auto& i:r)cin >> i; template<class T,class U>ostream &operator<<(ostream &o,const pair<T,U>&j){o<<"{"<<j.first<<", "<<j.second<<"}";return o;} template<class T,class U>ostream &operator<<(ostream &o,const map<T,U>&j){o<<"{";for(auto t=j.begin();t!=j.end();++t)o<<(t!=j.begin()?", ":"")<<*t;o<<"}";return o;} template<class T>ostream &operator<<(ostream &o,const set<T>&j){o<<"{";for(auto t=j.begin();t!=j.end();++t)o<<(t!=j.begin()?", ":"")<<*t;o<<"}";return o;} template<class T>ostream &operator<<(ostream &o,const vector<T>&j){o<<"{";for(int i=0;i<(int)j.size();++i)o<<(i>0?", ":"")<<j[i];o<<"}";return o;} inline int print(void){cout << endl; return 0;} template<class Head> int print(Head&& head){cout << head;print();return 0;} template<class Head,class... Tail> int print(Head&& head,Tail&&... tail){cout<<head<<" ";print(forward<Tail>(tail)...);return 0;} inline int debug(void){cerr << endl; return 0;} template<class Head> int debug(Head&& head){cerr << head;debug();return 0;} template<class Head,class... Tail> int debug(Head&& head,Tail&&... tail){cerr<<head<<" ";debug(forward<Tail>(tail)...);return 0;} template<typename T> void PA(T &a){int ASIZE=sizeof(a)/sizeof(a[0]);for(int ii=0;ii<ASIZE;++ii){cout<<a[ii]<<" \n"[ii==ASIZE-1];}} template<typename T> void PV(T &v){int VSIZE=v.size();for(int ii=0;ii<VSIZE;++ii){cout<<v[ii]<<" \n"[ii==VSIZE-1];}} #define ER(x) cerr << #x << " = " << (x) << endl; #define ERV(v) {cerr << #v << " : ";for(const auto& xxx : v){cerr << xxx << " ";}cerr << "\n";} inline int YES(bool x){cout<<((x)?"YES":"NO")<<endl;return 0;} inline int Yes(bool x){cout<<((x)?"Yes":"No")<<endl;return 0;} inline int yes(bool x){cout<<((x)?"yes":"no")<<endl;return 0;} inline int yES(bool x){cout<<((x)?"yES":"nO")<<endl;return 0;} inline int Yay(bool x){cout<<((x)?"Yay!":":(")<<endl;return 0;} template<typename A,typename B> void sankou(bool x,A a,B b){cout<<((x)?(a):(b))<<endl;} #define _overload3(_1,_2,_3,name,...) name #define _REP(i,n) REPI(i,0,n) #define REPI(i,a,b) for(ll i=ll(a);i<ll(b);++i) #define REP(...) _overload3(__VA_ARGS__,REPI,_REP,)(__VA_ARGS__) #define _RREP(i,n) RREPI(i,n,0) #define RREPI(i,a,b) for(ll i=ll(a);i>=ll(b);--i) #define RREP(...) _overload3(__VA_ARGS__,RREPI,_RREP,)(__VA_ARGS__) #define EACH(e,v) for(auto& e : v) #define PERM(v) sort((v).begin(),(v).end());for(bool c##p=1;c##p;c##p=next_permutation((v).begin(),(v).end())) #define ADD(a,b) a=(a+ll(b))%MOD #define MUL(a,b) a=(a*ll(b))%MOD inline ll MOP(ll x,ll n,ll m=MOD){ll r=1;while(n>0){if(n&1)(r*=x)%=m;(x*=x)%=m;n>>=1;}return r;} inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}inline ll lcm(ll a,ll b){return a*b/gcd(a,b);}inline ll POW(ll a,ll b){ll c=1ll;do{if(b&1)c*=1ll*a;a*=1ll*a;}while(b>>=1);return c;} template<typename T,typename A,typename B> inline bool between(T x,A a,B b) {return ((a<=x)&&(x<b));}template<class T> inline T sqr(T x){return x*x;} template<typename A,typename B> inline bool chmax(A &a,const B &b){if(a<b){a=b;return 1;}return 0;} template<typename A,typename B> inline bool chmin(A &a,const B &b){if(a>b){a=b;return 1;}return 0;} #define tmax(x,y,z) max((x),max((y),(z))) #define tmin(x,y,z) min((x),min((y),(z))) #define PB push_back #define MP make_pair #define MT make_tuple #define all(v) (v).begin(),(v).end() #define rall(v) (v).rbegin(),(v).rend() #define SORT(v) sort((v).begin(),(v).end()) #define RSORT(v) sort((v).rbegin(),(v).rend()) #define EXIST(s,e) (find((s).begin(),(s).end(),(e))!=(s).end()) #define EXISTST(s,c) (((s).find(c))!=string::npos) #define POSL(x,val) (lower_bound(x.begin(),x.end(),val)-x.begin()) #define POSU(x,val) (upper_bound(x.begin(),x.end(),val)-x.begin()) #define GEQ(x,val) (int)(x).size() - POSL((x),(val)) #define GREATER(x,val) (int)(x).size() - POSU((x),(val)) #define LEQ(x,val) POSU((x),(val)) #define LESS(x,val) POSL((x),(val)) #define SZV(a) int((a).size()) #define SZA(a) sizeof(a)/sizeof(a[0]) #define ZERO(a) memset(a,0,sizeof(a)) #define MINUS(a) memset(a,0xff,sizeof(a)) #define MEMINF(a) memset(a,0x3f,sizeof(a)) #define FILL(a,b) memset(a,b,sizeof(a)) #define UNIQUE(v) sort((v).begin(),(v).end());(v).erase(unique((v).begin(),(v).end()),(v).end()) struct abracadabra{ abracadabra(){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(20); cerr << fixed << setprecision(5); }; } ABRACADABRA; //TEMPLATE END---------------8<---------------8<---------------8<---------------8<---------------// /* ・グラフ > Dijkstra > BellmanFord > Warshall-Floyd > Kruskal [応用] 単一終点最短路問題は, すべての有向辺を逆向きに張り替えると, 単一始点最短路問題に帰着できる. [使用例] Graph<int> g(N); // 頂点数N, 重さの型がintのグラフを宣言 add_edge(g,a,b,c); // グラフgに, aからbへの重さcの無向辺を追加 add_arc(g,a,b,c); // グラフgに, aからbへの重さcの有向辺を追加 add_to_edges(edges,a,b,c); // 辺集合edgesに, 始点a, 終点b, 重さcの辺を追加 */ template<typename T> struct Edge { int from, to; T weight; Edge() : from(0), to(0), weight(0) {} Edge(int f, int t, T w) : from(f), to(t), weight(w) {} }; template<typename T> using Edges = vector< Edge< T > >; template<typename T> using Graph = vector< Edges< T > >; template<typename T> void add_edge(Graph< T > &g, int from, int to, T w = 1) { g[from].emplace_back(from,to,w); g[to].emplace_back(to,from,w); } template<typename T> void add_arc(Graph< T > &g, int from, int to, T w = 1) { g[from].emplace_back(from,to,w); } template<typename T> void add_to_edges(Edges< T > &e, int from, int to, T w = 1) { e.emplace_back(from,to,w); } /* ・BellmanFord > O(EV) [E:辺の数, V:頂点の数] [備考] グラフ(負辺が存在してもよい)に対する単一始点全点間最短路を求めるアルゴリズム 負閉路が存在しているかの判定も可能 -> 存在していたら空列を返す [注意] 結果を足し合わせる際, INFの大きさに注意 [使用例] Edges<int> edges; // 全ての辺 (重さ: int) add_to_edges(edges,a,b,c); // 辺集合edgesに, 始点a, 終点b, 重さcの辺を追加 auto bf = BellmanFord(edges,V,s); // 辺edges, 頂点数Vのグラフにおける, 始点sからの最短路 */ template<typename T> vector< T > BellmanFord(Edges< T > &edges, int vertex, int from) { const auto INF = numeric_limits< T >::max()/10; vector< T > dist(vertex, INF); dist[from] = 0; for (int i = 0; i < vertex - 1; ++i) { for (auto &e : edges) { if (dist[e.from] == INF) continue; dist[e.to] = min(dist[e.to], dist[e.from] + e.weight); } } for (auto &e : edges) { if (dist[e.from] == INF) continue; if (dist[e.from] + e.weight < dist[e.to]) return vector< T >(); } return dist; } signed main() { SS(int, N, M); Edges<ll> edge(N); REP(i, M) { SS(ll, a, b, c); --a, --b; c *= -1; add_to_edges(edge, a, b, c); } auto bf = BellmanFord(edge, N, 0); if (bf.size() == 0) return print("inf"); print(-bf[N - 1]); }#include <bits/stdc++.h> using namespace std; //#define int long long //TEMPLATE START---------------8<---------------8<---------------8<---------------8<---------------// typedef long long ll; typedef long double ld; typedef pair<int,int> pii; typedef pair<ll,ll> pll; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<string> vst; typedef vector<bool> vb; typedef vector<ld> vld; typedef vector<pii> vpii; typedef vector<pll> vpll; typedef vector<vector<int> > vvi; const int INF = (0x7FFFFFFFL); const ll INFF = (0x7FFFFFFFFFFFFFFFL); const string ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; const int MOD = 1e9 + 7; const int MODD = 998244353; const string alphabet = "abcdefghijklmnopqrstuvwxyz"; const double PI = acos(-1.0); const double EPS = 1e-9; const string Alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; int dx[9] = { 1, 0, -1, 0, 1, -1, -1, 1, 0 }; int dy[9] = { 0, 1, 0, -1, -1, -1, 1, 1, 0 }; #define ln '\n' #define scnaf scanf #define sacnf scanf #define sancf scanf #define SS(type, ...)type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__); template<typename T> void MACRO_VAR_Scan(T& t){cin >> t;}template<typename First, typename...Rest> void MACRO_VAR_Scan(First& first, Rest&...rest){cin >> first;MACRO_VAR_Scan(rest...);} #define SV(type,c,n) vector<type> c(n);for(auto& i:c)cin >> i; #define SVV(type,c,n,m) vector<vector<type>> c(n,vector<type>(m));for(auto& r:c)for(auto& i:r)cin >> i; template<class T,class U>ostream &operator<<(ostream &o,const pair<T,U>&j){o<<"{"<<j.first<<", "<<j.second<<"}";return o;} template<class T,class U>ostream &operator<<(ostream &o,const map<T,U>&j){o<<"{";for(auto t=j.begin();t!=j.end();++t)o<<(t!=j.begin()?", ":"")<<*t;o<<"}";return o;} template<class T>ostream &operator<<(ostream &o,const set<T>&j){o<<"{";for(auto t=j.begin();t!=j.end();++t)o<<(t!=j.begin()?", ":"")<<*t;o<<"}";return o;} template<class T>ostream &operator<<(ostream &o,const vector<T>&j){o<<"{";for(int i=0;i<(int)j.size();++i)o<<(i>0?", ":"")<<j[i];o<<"}";return o;} inline int print(void){cout << endl; return 0;} template<class Head> int print(Head&& head){cout << head;print();return 0;} template<class Head,class... Tail> int print(Head&& head,Tail&&... tail){cout<<head<<" ";print(forward<Tail>(tail)...);return 0;} inline int debug(void){cerr << endl; return 0;} template<class Head> int debug(Head&& head){cerr << head;debug();return 0;} template<class Head,class... Tail> int debug(Head&& head,Tail&&... tail){cerr<<head<<" ";debug(forward<Tail>(tail)...);return 0;} template<typename T> void PA(T &a){int ASIZE=sizeof(a)/sizeof(a[0]);for(int ii=0;ii<ASIZE;++ii){cout<<a[ii]<<" \n"[ii==ASIZE-1];}} template<typename T> void PV(T &v){int VSIZE=v.size();for(int ii=0;ii<VSIZE;++ii){cout<<v[ii]<<" \n"[ii==VSIZE-1];}} #define ER(x) cerr << #x << " = " << (x) << endl; #define ERV(v) {cerr << #v << " : ";for(const auto& xxx : v){cerr << xxx << " ";}cerr << "\n";} inline int YES(bool x){cout<<((x)?"YES":"NO")<<endl;return 0;} inline int Yes(bool x){cout<<((x)?"Yes":"No")<<endl;return 0;} inline int yes(bool x){cout<<((x)?"yes":"no")<<endl;return 0;} inline int yES(bool x){cout<<((x)?"yES":"nO")<<endl;return 0;} inline int Yay(bool x){cout<<((x)?"Yay!":":(")<<endl;return 0;} template<typename A,typename B> void sankou(bool x,A a,B b){cout<<((x)?(a):(b))<<endl;} #define _overload3(_1,_2,_3,name,...) name #define _REP(i,n) REPI(i,0,n) #define REPI(i,a,b) for(ll i=ll(a);i<ll(b);++i) #define REP(...) _overload3(__VA_ARGS__,REPI,_REP,)(__VA_ARGS__) #define _RREP(i,n) RREPI(i,n,0) #define RREPI(i,a,b) for(ll i=ll(a);i>=ll(b);--i) #define RREP(...) _overload3(__VA_ARGS__,RREPI,_RREP,)(__VA_ARGS__) #define EACH(e,v) for(auto& e : v) #define PERM(v) sort((v).begin(),(v).end());for(bool c##p=1;c##p;c##p=next_permutation((v).begin(),(v).end())) #define ADD(a,b) a=(a+ll(b))%MOD #define MUL(a,b) a=(a*ll(b))%MOD inline ll MOP(ll x,ll n,ll m=MOD){ll r=1;while(n>0){if(n&1)(r*=x)%=m;(x*=x)%=m;n>>=1;}return r;} inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}inline ll lcm(ll a,ll b){return a*b/gcd(a,b);}inline ll POW(ll a,ll b){ll c=1ll;do{if(b&1)c*=1ll*a;a*=1ll*a;}while(b>>=1);return c;} template<typename T,typename A,typename B> inline bool between(T x,A a,B b) {return ((a<=x)&&(x<b));}template<class T> inline T sqr(T x){return x*x;} template<typename A,typename B> inline bool chmax(A &a,const B &b){if(a<b){a=b;return 1;}return 0;} template<typename A,typename B> inline bool chmin(A &a,const B &b){if(a>b){a=b;return 1;}return 0;} #define tmax(x,y,z) max((x),max((y),(z))) #define tmin(x,y,z) min((x),min((y),(z))) #define PB push_back #define MP make_pair #define MT make_tuple #define all(v) (v).begin(),(v).end() #define rall(v) (v).rbegin(),(v).rend() #define SORT(v) sort((v).begin(),(v).end()) #define RSORT(v) sort((v).rbegin(),(v).rend()) #define EXIST(s,e) (find((s).begin(),(s).end(),(e))!=(s).end()) #define EXISTST(s,c) (((s).find(c))!=string::npos) #define POSL(x,val) (lower_bound(x.begin(),x.end(),val)-x.begin()) #define POSU(x,val) (upper_bound(x.begin(),x.end(),val)-x.begin()) #define GEQ(x,val) (int)(x).size() - POSL((x),(val)) #define GREATER(x,val) (int)(x).size() - POSU((x),(val)) #define LEQ(x,val) POSU((x),(val)) #define LESS(x,val) POSL((x),(val)) #define SZV(a) int((a).size()) #define SZA(a) sizeof(a)/sizeof(a[0]) #define ZERO(a) memset(a,0,sizeof(a)) #define MINUS(a) memset(a,0xff,sizeof(a)) #define MEMINF(a) memset(a,0x3f,sizeof(a)) #define FILL(a,b) memset(a,b,sizeof(a)) #define UNIQUE(v) sort((v).begin(),(v).end());(v).erase(unique((v).begin(),(v).end()),(v).end()) struct abracadabra{ abracadabra(){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(20); cerr << fixed << setprecision(5); }; } ABRACADABRA; //TEMPLATE END---------------8<---------------8<---------------8<---------------8<---------------// /* ・グラフ > Dijkstra > BellmanFord > Warshall-Floyd > Kruskal [応用] 単一終点最短路問題は, すべての有向辺を逆向きに張り替えると, 単一始点最短路問題に帰着できる. [使用例] Graph<int> g(N); // 頂点数N, 重さの型がintのグラフを宣言 add_edge(g,a,b,c); // グラフgに, aからbへの重さcの無向辺を追加 add_arc(g,a,b,c); // グラフgに, aからbへの重さcの有向辺を追加 add_to_edges(edges,a,b,c); // 辺集合edgesに, 始点a, 終点b, 重さcの辺を追加 */ template<typename T> struct Edge { int from, to; T weight; Edge() : from(0), to(0), weight(0) {} Edge(int f, int t, T w) : from(f), to(t), weight(w) {} }; template<typename T> using Edges = vector< Edge< T > >; template<typename T> using Graph = vector< Edges< T > >; template<typename T> void add_edge(Graph< T > &g, int from, int to, T w = 1) { g[from].emplace_back(from,to,w); g[to].emplace_back(to,from,w); } template<typename T> void add_arc(Graph< T > &g, int from, int to, T w = 1) { g[from].emplace_back(from,to,w); } template<typename T> void add_to_edges(Edges< T > &e, int from, int to, T w = 1) { e.emplace_back(from,to,w); } /* ・BellmanFord > O(EV) [E:辺の数, V:頂点の数] [備考] グラフ(負辺が存在してもよい)に対する単一始点全点間最短路を求めるアルゴリズム 負閉路が存在しているかの判定も可能 -> 存在していたら空列を返す [注意] 結果を足し合わせる際, INFの大きさに注意 [使用例] Edges<int> edges; // 全ての辺 (重さ: int) add_to_edges(edges,a,b,c); // 辺集合edgesに, 始点a, 終点b, 重さcの辺を追加 auto bf = BellmanFord(edges,V,s); // 辺edges, 頂点数Vのグラフにおける, 始点sからの最短路 */ template<typename T> vector< T > BellmanFord(Edges< T > &edges, int vertex, int from) { const auto INF = numeric_limits< T >::max()/10; vector< T > dist(vertex, INF); dist[from] = 0; for (int i = 0; i < vertex - 1; ++i) { for (auto &e : edges) { if (dist[e.from] == INF) continue; dist[e.to] = min(dist[e.to], dist[e.from] + e.weight); } } for (auto &e : edges) { if (dist[e.from] == INF) continue; if (dist[e.from] + e.weight < dist[e.to]) return vector< T >(); } return dist; } signed main() { SS(int, N, M); Edges<ll> edge(N); REP(i, M) { SS(ll, a, b, c); --a, --b; c *= -1; add_to_edges(edge, a, b, c); } auto bf = BellmanFord(edge, N, 0); if (bf.size() == 0) return print("inf"); print(-bf[N - 1]); }
a.cc:159:2: error: stray '#' in program 159 | }#include <bits/stdc++.h> | ^ a.cc:159:3: error: 'include' does not name a type 159 | }#include <bits/stdc++.h> | ^~~~~~~ a.cc:165:11: error: redefinition of 'const int INF' 165 | const int INF = (0x7FFFFFFFL); const ll INFF = (0x7FFFFFFFFFFFFFFFL); const string ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; | ^~~ a.cc:7:11: note: 'const int INF' previously defined here 7 | const int INF = (0x7FFFFFFFL); const ll INFF = (0x7FFFFFFFFFFFFFFFL); const string ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; | ^~~ a.cc:165:41: error: redefinition of 'const ll INFF' 165 | const int INF = (0x7FFFFFFFL); const ll INFF = (0x7FFFFFFFFFFFFFFFL); const string ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; | ^~~~ a.cc:7:41: note: 'const ll INFF' previously defined here 7 | const int INF = (0x7FFFFFFFL); const ll INFF = (0x7FFFFFFFFFFFFFFFL); const string ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; | ^~~~ a.cc:165:84: error: redefinition of 'const std::string ALPHABET' 165 | const int INF = (0x7FFFFFFFL); const ll INFF = (0x7FFFFFFFFFFFFFFFL); const string ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; | ^~~~~~~~ a.cc:7:84: note: 'const std::string ALPHABET' previously declared here 7 | const int INF = (0x7FFFFFFFL); const ll INFF = (0x7FFFFFFFFFFFFFFFL); const string ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; | ^~~~~~~~ a.cc:166:11: error: redefinition of 'const int MOD' 166 | const int MOD = 1e9 + 7; const int MODD = 998244353; const string alphabet = "abcdefghijklmnopqrstuvwxyz"; | ^~~ a.cc:8:11: note: 'const int MOD' previously defined here 8 | const int MOD = 1e9 + 7; const int MODD = 998244353; const string alphabet = "abcdefghijklmnopqrstuvwxyz"; | ^~~ a.cc:166:42: error: redefinition of 'const int MODD' 166 | const int MOD = 1e9 + 7; const int MODD = 998244353; const string alphabet = "abcdefghijklmnopqrstuvwxyz"; | ^~~~ a.cc:8:42: note: 'const int MODD' previously defined here 8 | const int MOD = 1e9 + 7; const int MODD = 998244353; const string alphabet = "abcdefghijklmnopqrstuvwxyz"; | ^~~~ a.cc:166:84: error: redefinition of 'const std::string alphabet' 166 | const int MOD = 1e9 + 7; const int MODD = 998244353; const string alphabet = "abcdefghijklmnopqrstuvwxyz"; | ^~~~~~~~ a.cc:8:84: note: 'const std::string alphabet' previously declared here 8 | const int MOD = 1e9 + 7; const int MODD = 998244353; const string alphabet = "abcdefghijklmnopqrstuvwxyz"; | ^~~~~~~~ a.cc:167:14: error: redefinition of 'const double PI' 167 | const double PI = acos(-1.0); const double EPS = 1e-9; const string Alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; | ^~ a.cc:9:14: note: 'const double PI' previously defined here 9 | const double PI = acos(-1.0); const double EPS = 1e-9; const string Alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; | ^~ a.cc:167:45: error: redefinition of 'const double EPS' 167 | const double PI = acos(-1.0); const double EPS = 1e-9; const string Alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; | ^~~ a.cc:9:45: note: 'const double EPS' previously defined here 9 | const double PI = acos(-1.0); const double EPS = 1e-9; const string Alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; | ^~~ a.cc:167:84: error: redefinition of 'const std::string Alphabet' 167 | const double PI = acos(-1.0); const double EPS = 1e-9; const string Alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; | ^~~~~~~~ a.cc:9:84: note: 'const std::string Alphabet' previously declared here 9 | const double PI = acos(-1.0); const double EPS = 1e-9; const string Alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; | ^~~~~~~~ a.cc:168:5: error: redefinition of 'int dx [9]' 168 | int dx[9] = { 1, 0, -1, 0, 1, -1, -1, 1, 0 }; | ^~ a.cc:10:5: note: 'int dx [9]' previously defined here 10 | int dx[9] = { 1, 0, -1, 0, 1, -1, -1, 1, 0 }; | ^~ a.cc:169:5: error: redefinition of 'int dy [9]' 169 | int dy[9] = { 0, 1, 0, -1, -1, -1, 1, 1, 0 }; | ^~ a.cc:11:5: note: 'int dy [9]' previously defined here 11 | int dy[9] = { 0, 1, 0, -1, -1, -1, 1, 1, 0 }; | ^~ a.cc:175:27: error: redefinition of 'template<class T> void MACRO_VAR_Scan(T&)' 175 | template<typename T> void MACRO_VAR_Scan(T& t){cin >> t;}template<typename First, typename...Rest> void MACRO_VAR_Scan(First& first, Rest&...rest){cin >> first;MACRO_VAR_Scan(rest...);} | ^~~~~~~~~~~~~~ a.cc:17:27: note: 'template<class T> void MACRO_VAR_Scan(T&)' previously declared here 17 | template<typename T> void MACRO_VAR_Scan(T& t){cin >> t;}template<typename First, typename...Rest> void MACRO_VAR_Scan(First& first, Rest&...rest){cin >> first;MACRO_VAR_Scan(rest...);} | ^~~~~~~~~~~~~~ a.cc:175:105: error: redefinition of 'template<class First, class ... Rest> void MACRO_VAR_Scan(First&, Rest& ...)' 175 | template<typename T> void MACRO_VAR_Scan(T& t){cin >> t;}template<typename First, typename...Rest> void MACRO_VAR_Scan(First& first, Rest&...rest){cin >> first;MACRO_VAR_Scan(rest...);} | ^~~~~~~~~~~~~~ a.cc:17:105: note: 'template<class First, class ... Rest> void MACRO_VAR_Scan(First&, Rest& ...)' previously declared here 17 | template<typename T> void MACRO_VAR_Scan(T& t){cin >> t;}template<typename First, typename...Rest> void MACRO_VAR_Scan(First& first, Rest&...rest){cin >> first;MACRO_VAR_Scan(rest...);} | ^~~~~~~~~~~~~~ a.cc:178:35: error: redefinition of 'template<class T, class U> std::ostream& operator<<(std::ostream&, const std::pair<_T1, _T2>&)' 178 | template<class T,class U>ostream &operator<<(ostream &o,const pair<T,U>&j){o<<"{"<<j.first<<", "<<j.second<<"}";return o;} | ^~~~~~~~ a.cc:20:35: note: 'template<class T, class U> std::ostream& operator<<(std::ostream&, const std::pair<_T1, _T2>&)' previously declared here 20 | template<class T,class U>ostream &operator<<(ostream &o,const pair<T,U>&j){o<<"{"<<j.first<<", "<<j.second<<"}";return o;} | ^~~~~~~~ a.cc:179:35: error: redefinition of 'template<class T, class U> std::ostream& operator<<(std::ostream&, const std::map<T, U>&)' 179 | template<class T,class U>ostream &operator<<(ostream &o,const map<T,U>&j){o<<"{";for(auto t=j.begin();t!=j.end();++t)o<<(t!=j.begin()?", ":"")<<*t;o<<"}";return o;} | ^~~~~~~~ a.cc:21:35: note: 'template<class T, class U> std::ostream& operator<<(std::ostream&, const std::map<T, U>&)' previously declared here 21 | template<class T,class U>ostream &operator<<(ostream &o,const map<T,U>&j){o<<"{";for(auto t=j.begin();t!=j.end();++t)o<<(t!=j.begin()?", ":"")<<*t;o<<"}";return o;} | ^~~~~~~~ a.cc:180:27: error: redefinition of 'template<class T> std::ostream& operator<<(std::ostream&, const std::set<T>&)' 180 | template<class T>ostream &operator<<(ostream &o,const set<T>&j){o<<"{";for(auto t=j.begin();t!=j.end();++t)o<<(t!=j.begin()?", ":"")<<*t;o<<"}";return o;} | ^~~~~~~~ a.cc:22:27: note: 'template<class T> std::ostream& operator<<(std::ostream&, const std::set<T>&)' previously declared here 22 | template<class T>ostream &operator<<(ostream &o,const set<T>&j){o<<"{";for(auto t=j.begin();t!=j.end();++t)o<<(t!=j.begin()?", ":"")<<*t;o<<"}";return o;} | ^~~~~~~~ a.cc:181:27: error: redefinition of 'template<class T> std::ostream& operator<<(std::ostream&, const std::vector<_Tp>&)' 181 | template<class T>ostream &operator<<(ostream &o,const vector<T>&j){o<<"{";for(int i=0;i<(int)j.size();++i)o<<(i>0?", ":"")<<j[i];o<<"}";return o;} | ^~~~~~~~ a.cc:23:27: note: 'template<class T> std::ostream& operator<<(std::ostream&, const std::vector<_Tp>&)' previously declared here 23 | template<class T>ostream &operator<<(ostream &o,const vector<T>&j){o<<"{";for(int i=0;i<(int)j.size();++i)o<<(i>0?", ":"")<<j[i];o<<"}";return o;} | ^~~~~~~~ a.cc:182:12: error: redefinition of 'int print()' 182 | inline int print(void){cout << endl; return 0;} | ^~~~~ a.cc:24:12: note: 'int print()' previously defined here 24 | inline int print(void){cout << endl; return 0;} | ^~~~~ a.cc:183:26: error: redefinition of 'template<class Head> int print(Head&&)' 183 | template<class Head> int print(Head&& head){cout << head;print();return 0;} template<class Head,class... Tail> int print(Head&& head,Tail&&... tail){cout<<head<<" ";print(forward<Tail>(tail)...);return 0;} | ^~~~~ a.cc:25:26: note: 'template<class Head> int print(Head&&)' previously declared here 25 | template<class Head> int print
s823874928
p03722
C++
#include <iostream> #include <numeric> #include <vector> using namespace std; using Weight = long long; class Edge { public: int src, dst; Weight w; Edge(): src(0), dst(0), w(0) {} Edge(int src, int dst, Weight w): src(src), dst(dst), w(w) {} }; using Edges = vector < Edge >; using Graph = vector < Edges >; void addArc(Graph &g, int a, int b, Weight w = 1) { g[a].emplace_back(a, b, w); } void BellmanFord(const Graph&g, int s) { const Weight INF = numeric_limits<Weight>::max() / 4; Edges edges; for (auto& es: g) for (auto& e: es) edges.emplace_back(e); vector < Weight > dist(g.size(), -INF); dist[s] = 0; for (int i = 0; i <= 2 * g.size(); ++i) { for (auto& e: edges) { if (dist[e.src] != INF && dist[e.dst] < dist[e.src] + e.w) { if (i > g.size() && e.dst == g.size() - 1) { cout << "inf" << endl; return; } dist[e.dst] = dist[e.src] + e.w; } } } cout << dist[g.size() - 1] << endl; } int main() { int n, m; cin >> n >> m; Graph g(n); for (int i = 0; i < m; ++i) { int a, b, c; cin >> a >> b >> c; a--, b--; addArc(g, a, b, c); } BellmanFord(g, 0); return 0; }
a.cc: In function 'void BellmanFord(const Graph&, int)': a.cc:25:22: error: 'numeric_limits' was not declared in this scope 25 | const Weight INF = numeric_limits<Weight>::max() / 4; | ^~~~~~~~~~~~~~ a.cc:25:43: error: expected primary-expression before '>' token 25 | const Weight INF = numeric_limits<Weight>::max() / 4; | ^ a.cc:25:49: error: no matching function for call to 'max()' 25 | const Weight INF = numeric_limits<Weight>::max() / 4; | ~~~~~^~ In file included from /usr/include/c++/14/string:51, from /usr/include/c++/14/bits/locale_classes.h:40, from /usr/include/c++/14/bits/ios_base.h:41, from /usr/include/c++/14/ios:44, from /usr/include/c++/14/ostream:40, from /usr/include/c++/14/iostream:41, from a.cc:1: /usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)' 257 | max(const _Tp& __a, const _Tp& __b) | ^~~ /usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate expects 2 arguments, 0 provided /usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)' 303 | max(const _Tp& __a, const _Tp& __b, _Compare __comp) | ^~~ /usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate expects 3 arguments, 0 provided
s576788163
p03722
C++
#include "/Users/daikikodama/Desktop/stdc++.h" //#include <bits/stdc++.h> #define rep(i,n) for(int i=0; i<(n); i++) #define int long long #define double long double #define mod 1000000007 #define F first #define S second #define P pair<long long,long long> #define all(a) a.begin(),a.end() #define INF 10000000000000000 #define endl '\n' template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } using namespace std; int N,M; int dist[1010]; bool negative[1010]; struct edge{int from,to,cost;}; edge G[2010]; signed main(void){ cin>>N>>M; rep(i,M){ edge e; cin>>e.from>>e.to>>e.cost; e.from--; e.to--; e.cost=-e.cost; G[i]=e; } fill(dist,dist+N,INF); dist[0]=0; rep(i,N-1){ rep(j,M){ if(dist[G[j].from]==INF)continue; if(dist[G[j].to]>dist[G[j].from]+G[j].cost){ dist[G[j].to]=dist[G[j].from]+G[j].cost; } } } rep(i,N){ rep(j,M){ if(dist[G[j].from]==INF)continue; if(dist[G[j].to]>dist[G[j].from]+G[j].cost){ dist[G[j].to]=dist[G[j].from]+G[j].cost; negative[G[j].to]=true; } if(negative[G[j].from])negative[G[j].from]=true; } } int ans=-dist[N-1]; if(negative[N-1])cout<<"inf\n"; else cout<<ans<<endl; }
a.cc:1:10: fatal error: /Users/daikikodama/Desktop/stdc++.h: No such file or directory 1 | #include "/Users/daikikodama/Desktop/stdc++.h" | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ compilation terminated.
s941021324
p03722
C++
#include <iostream> #include <vector> using namespace std; typedef long long ll; int N, M; struct edge { ll from, to, cost; }; static const ll INF = 1000000000000; edge es[2000]; ll d[1000]; bool find_negative_loop(int s){ int cnt = 0; for(int i = 0; i < N; i++){ d[i] = INF; } d[s] = 0; while(true){ bool update = false; cnt++; for(int i = 0; i < M; i++){ edge e = es[i]; if(d[e.from] != INF && d[e.to] > d[e.from] + e.cost){ d[e.to] = d[e.from] + e.cost; update = true; if(cnt == N && e.to = N - 1){ return true; } else if(cnt == N){ return false; } } } if(!update){ break; } } return false; } int main(void){ // Your code here! cin >> N >> M; ll a, b, c; for(int i = 0; i < M; i++){ cin >> a >> b >> c; es[i].from = a - 1; es[i].to = b - 1; es[i].cost = -c; } if(find_negative_loop(0)){ cout << "inf" << endl; } else { cout << -d[N-1] << endl; } }
a.cc: In function 'bool find_negative_loop(int)': a.cc:29:29: error: lvalue required as left operand of assignment 29 | if(cnt == N && e.to = N - 1){ | ~~~~~~~~~^~~~~~~