submission_id stringlengths 10 10 | problem_id stringlengths 6 6 | language stringclasses 3
values | code stringlengths 1 522k | compiler_output stringlengths 43 10.2k |
|---|---|---|---|---|
s742852096 | p03722 | C++ | include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX_M=20000;
ll N, M;
ll cost[1011][1011];
int main(){
cin>>N>>M;
for(int i=1;i<=N;i++){
for(int j=1;j<=N;j++){
if(i==j){
cost[i][j]=0;
}
else{
cost[i][j]=-1000000000000000;
}
}
}
for(int i=0;i<M;i++){
ll from, to, cst;
cin>>from>>to>>cst;
cost[from][to]=cst;
}
for(ll k=1;k<=N;k++){
for(ll i=1;i<=N;i++){
for(ll j=1;j<=N;j++){
cost[i][j]=max(cost[i][j], cost[i][k]+cost[k][j]);
}
}
}
if(cost[1][1]>0){
cout<<"inf"<<endl;
}
else{
cout<<cost[1][N]<<endl;
}
return 0;
}
| a.cc:1:1: error: 'include' does not name a type
1 | include<bits/stdc++.h>
| ^~~~~~~
a.cc: In function 'int main()':
a.cc:13:9: error: 'cin' was not declared in this scope
13 | cin>>N>>M;
| ^~~
a.cc:33:44: error: 'max' was not declared in this scope
33 | cost[i][j]=max(cost[i][j], cost[i][k]+cost[k][j]);
| ^~~
a.cc:38:17: error: 'cout' was not declared in this scope; did you mean 'cost'?
38 | cout<<"inf"<<endl;
| ^~~~
| cost
a.cc:38:30: error: 'endl' was not declared in this scope
38 | cout<<"inf"<<endl;
| ^~~~
a.cc:41:17: error: 'cout' was not declared in this scope; did you mean 'cost'?
41 | cout<<cost[1][N]<<endl;
| ^~~~
| cost
a.cc:41:35: error: 'endl' was not declared in this scope
41 | cout<<cost[1][N]<<endl;
| ^~~~
|
s480673670 | p03722 | Java | import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
int M = sc.nextInt();
final int NMAX = 1000;
final int MMAX = 2000;
final long INF = Long.MAX_VALUE;
int[] a = new int[MMAX];
int[] b = new int[MMAX];
long[] c = new long[MMAX];
for (int i = 0; i < M; i++) {
a[i] = sc.nextInt();
b[i] = sc.nextInt();
c[i] = sc.nextLong();
c[i] = -c[i]; //スコア逆
}
long ans = bellmanFord(a,b,c,N,M);
if(ans == -INF) System.out.println("inf");
else System.out.println(-ans);
}
public static long bellmanFord(int[] a, int[] b, long[]c, int N, int M){
final long INF = Long.MAX_VALUE;
long[] dist = new long[N];
for (int i = 0; i < N; i++) {
dist[i] = INF; //初期化
}
dist[0] = 0L;
for(int loop = 0; loop < N - 1; loop++) {
for (int i = 0; i < M; i++) {
if(dist[a[i] - 1] == INF) continue;
if(dist[b[i] - 1] > dist[a[i] - 1] + c[i]) {
dist[b[i] - 1] = dist[a[i] - 1] + c[i];
}
}
}
long ans = dist[N - 1];
boolean[] negative = new boolean[NMAX];
for(int i = 0; i < N; i++) {
negative[i] = false;
}
for (int loop = 0; loop < N; loop++) {
for (int i = 0; i < M; i++) {
if (dist[a[i] - 1] == INF) continue;
if (dist[b[i] - 1] > dist[a[i] - 1] + c[i]) {
dist[b[i] - 1] = dist[a[i] - 1] + c[i];
negative[b[i] - 1] = true;
}
if (negative[a[i] - 1] == true) {
negative[b[i] - 1] = true;
}
}
}
if (negative[N - 1]) return -INF;
else return ans;
}
}
| Main.java:50: error: cannot find symbol
boolean[] negative = new boolean[NMAX];
^
symbol: variable NMAX
location: class Main
1 error
|
s785606702 | p03722 | C++ | #include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define reps(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define all(c) begin(c),end(c)
const ll INF = 1e18;
struct edge { ll from, to, cost; };
edge es[2000];
ll d[1000];
bool flag = false;;
int V, E; //頂点、辺数
//頂点sからの最短d
void bellmanford(int s) {
int count = 0;
rep(i, V)d[i] = INF;
d[s] = 0;
while (count<n) {
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;
count++;
}
if (count == V)flag = true;
}
//負の閉路->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;
if (i == V - 1)return true;
}
}
}
return false;
}
int main() {
cin.sync_with_stdio(false);
cin >> V >> E;
rep(i, E) {
int a, b, c;
cin >> a >> b >> c;
a--; b--; c = -c;
es[i].from = a; es[i].to = b; es[i].cost = c;
}
bellmanford(0);
if (flag) {
cout << "inf" << endl;
return 0;
}
bellmanford(0);
cout << -d[V - 1] << endl;
return 0;
} | a.cc: In function 'void bellmanford(int)':
a.cc:21:22: error: 'n' was not declared in this scope
21 | while (count<n) {
| ^
|
s435184531 | p03722 | C++ | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,x) for(int i=0;i<x;++i)
struct edge{
int from, to, cost;
edge(int from, int to, int cost) : from(from), to(to), cost(cost) {};
};
vector<edge> edges;
const int MAX_N = 100000;
int N, M;
int dist[MAX_N];
void bf(int s)
{
rep(i, N) dist[i] = LLONG_MAX / 2;
dist[s] = 0;
rep(i, N) {
for (edge& e : edges) {
if (dist[e.to] > dist[e.from] + e.cost) {
dist[e.to] = dist[e.from] + e.cost;
}
}
}
for (edge& e : edges) {
if (dist[e.to] > dist[e.from] + e.cost) {
dist[e.to] = dist[e.from] + e.cost
if (e.to == N - 1) {
cout << "inf" << endl; exit(0);
}
}
}
}
signed main()
{
cin >> N >> M;
rep(i, M) {
int a, b, c;
cin >> a >> b >> c;
--a, --b;
edges.emplace_back(edge(a, b, -c));
}
bf(0);
cout << -dist[N - 1] << endl;
} | a.cc: In function 'void bf(long long int)':
a.cc:35:51: error: expected ';' before 'if'
35 | dist[e.to] = dist[e.from] + e.cost
| ^
| ;
36 | if (e.to == N - 1) {
| ~~
|
s229287314 | p03722 | C++ | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,x) for(int i=0;i<x;++i)
struct edge{
int from, to, cost;
edge(int from, int to, int cost) : from(from), to(to), cost(cost) {};
};
vector<edge> edges;
const int MAX_N = 100000;
int N, M;
int dist[MAX_N];
void bf(int s)
{
rep(i, N) dist[i] = LLONG_MAX / 2;
dist[s] = 0;
rep(i, N) {
for (edge& e : edges) {
if (dist[e.to] > dist[e.from] + e.cost) {
dist[e.to] = dist[e.from] + e.cost;
}
}
}
}
signed main()
{
cin >> N >> M;
rep(i, M) {
int a, b, c;
cin >> a >> b >> c;
--a, --b;
edges.emplace_back(edge(a, b, -c));
}
bf(0);
for (edge &e : edges) {
dist[e.to] = dist[e.from] + e.cost;
if (e.to == n - 1) {
cout << "inf" << endl;
return 0;
}
}
cout << -dist[N - 1] << endl;
} | a.cc: In function 'int main()':
a.cc:50:25: error: 'n' was not declared in this scope
50 | if (e.to == n - 1) {
| ^
|
s286168019 | p03722 | C++ | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,x) for(int i=0;i<x;++i)
struct edge{
int from, to, cost;
edge(int from, int to, int cost) : from(from), to(to), cost(cost) {};
};
vector<edge> edges;
const int MAX_N = 100000;
int N, M;
int dist[MAX_N];
void bf(int s)
{
rep(i, N) dist[i] = LLONG_MAX / 2;
dist[s] = 0;
rep(i, N - 1) {
for (edge& e : edges) {
if (dist[e.to] > dist[e.from] + e.cost) {
dist[e.to] = dist[e.from] + e.cost;
}
}
}
for (edge& e : edges) if (dist[e.to] > dist[e.from] + e.cost) {
if (e.to == n - 1) { cout << "inf" << endl; exit(0); }
}
}
signed main()
{
cin >> N >> M;
rep(i, M) {
int a, b, c;
cin >> a >> b >> c;
--a, --b;
edges.emplace_back(edge(a, b, -c));
}
bf(0);
cout << -dist[N - 1] << endl;
}
| a.cc: In function 'void bf(long long int)':
a.cc:35:21: error: 'n' was not declared in this scope
35 | if (e.to == n - 1) { cout << "inf" << endl; exit(0); }
| ^
|
s049230185 | p03722 | C++ | #include<iostream>
#include<algorithm>
#include<functional>
#include <string>
#include<cstdio>
#include<math.h>
#include<stack>
#include<queue>
#include<cstring>
#include<vector>
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define EREP(i,n) for(int i=(n-1);i>=0;--i)
#define D(n,retu) REP(i,n){cin>>retu[i];}
#define mod 1000000007
#define MIN -93193111451418101
#define INF 931931114518101
using namespace std;
typedef long long int ll;
template<typename T>
void fill_all(T& arr, const T& v) {
arr = v;
}
template<typename T, typename ARR>
void fill_all(ARR& arr, const T& v) {
for (auto& i : arr) { fill_all(i, v); }
}
//------------------変数-----------------------//
ll n, m;
typedef pair<ll, ll> P;
ll dp[20][100000] = {};//vコメの頂点のとき、どの頂点に行ったか
ll maxa = 0, moto = 0;
queue <ll>q;
ll bitmax = 0;
//-------------------関数----------------------//
struct G {
ll from;
ll to;
ll cost;
};
G g[10001];
ll weight[10001];
int main() {
fill_all(weight,(ll) MIN);
weight[0] = 0;
cin >> n >> m;
REP(i, m) {
ll a, b, c; cin >> a >> b >> c; a--; b--;
g[i].from = a; g[i].to = b; g[i].cost = c;
}
ll j = 0;
while(true){
j++;
if (j == 103831) { cout << "inf" << endl; return 0; }
bool flag = true;
REP(i, m) {
G a = g[i];
if (weight[a.from] != MIN&&weight[a.to]<weight[a.from]+a.cost) {
flag = false;
weight[a.to] = weight[a.from] + a.cost;
}
}
if (flag) { break; }
}
cout << weight[n - 1] << endl;
return 0;
| a.cc: In function 'int main()':
a.cc:69:18: error: expected '}' at end of input
69 | return 0;
| ^
a.cc:46:12: note: to match this '{'
46 | int main() {
| ^
|
s439909860 | p03722 | C++ | #include<iostream>
#include<algorithm>
#include<functional>
#include <string>
#include<cstdio>
#include<math.h>
#include<stack>
#include<queue>
#include<cstring>
#include<vector>
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define EREP(i,n) for(int i=(n-1);i>=0;--i)
#define D(n,retu) REP(i,n){cin>>retu[i];}
#define mod 1000000007
#define MIN -93193111451418101
#define INF 931931114518101
using namespace std;
typedef long long int ll;
template<typename T>
void fill_all(T& arr, const T& v) {
arr = v;
}
template<typename T, typename ARR>
void fill_all(ARR& arr, const T& v) {
for (auto& i : arr) { fill_all(i, v); }
}
//------------------変数-----------------------//
ll n, m;
typedef pair<ll, ll> P;
ll dp[20][100000] = {};//vコメの頂点のとき、どの頂点に行ったか
ll maxa = 0, moto = 0;
queue <ll>q;
ll bitmax = 0;
//-------------------関数----------------------//
struct G {
ll from;
ll to;
ll cost;
};
G g[1001];
ll weight[1001];
int main() {
fill_all(weight, MIN);
weight[0] = 0;
cin >> n >> m;
REP(i, m) {
ll a, b, c; cin >> a >> b >> c; a--; b--;
g[i].from = a; g[i].to = b; g[i].cost = c;
}
ll j = 0;
while(true){
j++;
if (j == 9319831) { cout << "inf" << endl; return 0; }
bool flag = true;
REP(i, m) {
G a = g[i];
if (weight[a.from] != MIN&&weight[a.to]<weight[a.from]+a.cost) {
flag = false;
weight[a.to] = weight[a.from] + a.cost;
}
}
if (flag) { break; }
}
cout << weight[n - 1] << endl;
return 0;
} | a.cc: In instantiation of 'void fill_all(ARR&, const T&) [with T = long int; ARR = long long int]':
a.cc:26:32: required from 'void fill_all(ARR&, const T&) [with T = long int; ARR = long long int [1001]]'
26 | for (auto& i : arr) { fill_all(i, v); }
| ~~~~~~~~^~~~~~
a.cc:47:10: required from here
47 | fill_all(weight, MIN);
| ~~~~~~~~^~~~~~~~~~~~~
a.cc:26:9: error: 'begin' was not declared in this scope; did you mean 'std::begin'?
26 | for (auto& i : arr) { fill_all(i, v); }
| ^~~
| std::begin
In file included from /usr/include/c++/14/string:53,
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/range_access.h:114:37: note: 'std::begin' declared here
114 | template<typename _Tp> const _Tp* begin(const valarray<_Tp>&) noexcept;
| ^~~~~
a.cc:26:9: error: 'end' was not declared in this scope; did you mean 'std::end'?
26 | for (auto& i : arr) { fill_all(i, v); }
| ^~~
| std::end
/usr/include/c++/14/bits/range_access.h:116:37: note: 'std::end' declared here
116 | template<typename _Tp> const _Tp* end(const valarray<_Tp>&) noexcept;
| ^~~
|
s069379887 | p03722 | C++ | #include <bits/stdc++.h>
using namespace std;
using lint = long long;
struct edge {
int to, cost;
edge() {}
edge(int a, int b) :to(a), cost(b) {}
};
const lint inf = 1001001001001001001;
vector<vector<edge>> G;
vector<lint> d;
bool bellman_ford(int n, int s = 0) {
d = vector<lint>(n, inf);
d[s] = 0;
for (int i = 0; i < n; ++i) {
for (int v = 0; v < n; ++v) {
for (int j = 0; j < G[v].size(); ++j) {
edge e = G[v][j];
if (d[e.to] > d[v] + e.cost) {
d[e.to] = d[v] + e.cost;
if (i == n - 1) return true;
}
}
}
}
return false;
}
int main() {
int n, m;
cin >> n >> m;
G.resize(n);
for (int i = 0; i < m; ++i) {
int a, b, c;
cin >> a >> b >> c;
a--; b--;
G[a].push_back(edge(b, -c));
}
//if (bellman_ford(n)) puts("inf");
bellman_ford(n);
else cout << -d.back() << endl;
}
| a.cc: In function 'int main()':
a.cc:51:3: error: 'else' without a previous 'if'
51 | else cout << -d.back() << endl;
| ^~~~
|
s936577687 | p03722 | C++ | #include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <utility>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;
#define INF_LL (ll)1e18
#define INF (int)1e9
#define REP(i, n) for(int i = 0;i < (n);i++)
#define FOR(i, a, b) for(int i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
using ll = long long;
using PII = pair<int, int>;
const double eps = 1e-10;
template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}
class Union_find{
private:
vector<int> par;
vector<int> rank;
vector<int> sz;
int n;
public:
Union_find(int a){
n = a;
for(int i = 0;i < n;i++){
par.push_back(i);
rank.push_back(0);
sz.push_back(1);
}
}
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;
sz[y] += sz[x];
}else{
par[y] = x;
sz[x] += sz[y];
if(rank[x] == rank[y]) rank[x]++;
}
}
bool same(int x, int y){
return find(x) == find(y);
}
int size(int x){
return sz[find(x)];
}
};
class LazySegTree{
private:
int n;
vector<ll> node, lazy;
vector<bool> lazyFlag;
public:
LazySegTree(vector<ll> v){
int sz = v.size();
n = 1; while(n < sz) n *= 2;
node.resize(2*n-1, 0);
lazy.resize(2*n-1, 0);
lazyFlag.resize(2*n-1, false);
REP(i, sz) node[i+n-1] = v[i];
for(int i = n-2;i >= 0;i--) node[i] = node[2*i+1]+node[2*i+2];
}
void eval(int k, int l, int r){
if(lazyFlag[k]){
node[k] += lazy[k] * (r-l);
if(r-l > 1){
lazy[2*k+1] += lazy[k];
lazy[2*k+2] += lazy[k];
lazyFlag[2*k+1] = lazyFlag[2*k+2] = true;
}
lazy[k] = 0;
lazyFlag[k] = false;
}
}
void add(int a, int b, ll x, int k=0, int l=0, int r=-1){
if(r < 0) r = n;
eval(k, l, r);
if(b <= l || r <= a) return;
if(a <= l && r <= b){
lazy[k] += x;
lazyFlag[k] = true;
eval(k, l, r);
}else{
add(a, b, x, k*2+1, l, (l+r)/2);
add(a, b, x, k*2+2, (l+r)/2, r);
node[k] = node[k*2+1] + node[k*2+2];
}
}
ll query(int a, int b, int k=0, int l=0, int r=-1){
if(r < 0) r = n;
eval(k, l, r);
if(b <= l || r <= a) return 0;
if(a <= l && r <= b) return node[k];
return query(a, b, k*2+1, l, (l+r)/2) + query(a, b, k*2+2, (l+r)/2, r);
}
};
class Bucket{
private:
int n, bs, bn;
vector<ll> data;
vector<ll> bucket, lazy;
vector<bool> lazyFlag;
public:
Bucket(vector<ll> v, int sz){
data = v;
n = v.size();
bs = sz;
bn = (n + bs - 1) / bs;
data.resize(bn*bs, INF_LL);
bucket.assign(bn, INF_LL);
lazy.assign(bn, 0);
lazyFlag.assign(bn, 0);
REP(i, bn){
ll minx = INF_LL;
REP(j, bs){
chmin(minx, data[i*bs+j]);
}
bucket[i] = minx;
}
}
void eval(int k){
if(lazyFlag[k]){
lazyFlag[k] = false;
FOR(i, bs*k, bs*(k+1)){
data[i] = lazy[k];
}
lazy[k] = 0;
}
}
void update(int s, int t, int x){
REP(k, bn){
int l = k*bs, r = (k+1)*bs;
if(r <= s || t <= l) continue;
if(s <= l && r <= t){
lazyFlag[k] = true;
bucket[k] = x;
lazy[k] = x;
}else{
eval(k);
FOR(i, max(s, l), min(t, r)){
data[i] = x;
}
bucket[k] = INF_LL;
FOR(i, l, r){
chmin(bucket[k], data[i]);
}
}
}
}
ll query(int s, int t){
ll res = INF_LL;
REP(k, bn){
int l = k*bs, r = (k+1)*bs;
if(r <= s || t <= l) continue;
if(s <= l && r <= t){
chmin(res, bucket[k]);
}else{
eval(k);
FOR(i, max(s, l), min(t, r)){
chmin(res, data[i]);
}
}
}
return res;
}
};
const ll mod = 1e9+7;
#define fst first
#define snd second
/*
int N, M;
vector<int> G[20];
int main(void){
cin >> N >> M;
REP(i, M){
int a, b;
cin >> a >> b; a--; b--;
G[a].push_back(b);
}
}
*/
struct edge{int u, v, c;};
int N, M;
vector<PII> G2[1010];
edge es[2020];
int main(void){
cin >> N >> M;
REP(i, M){
int a, b, c;
cin >> a >> b >> c; a--; b--;
es[i] = {a, b, -c};
G2[b].push_back({1, a});
}
ll point[1010] = {};
fill(point, point+N, INF_LL);
point[0] = 0;
vector<int> v;
bool f = false;
REP(i, N){
REP(j, M){
edge e = es[j];
if(point[e.v] > point[e.u]+e.c){
point[e.v] = point[e.u]+e.c;
if(i == N-1){
v.push_back(e.v);
f = true;
}
}
}
}
if(!f){
cout << -point[N-1] << endl;
return 0;
}
ll d[1010] = {};
fill(d, d+N, INF_LL);
d[N-1] = 0;
priority_queue<PII, vector<PII>, greater<PII> > pq;
pq.push({0, N-1});
while(pq.size()){
PII p = pq.top(); pq.pop();
if(p.fst > d[p.snd]) continue;
REP(i, G2[p.snd].size()){
if(G2[p.snd][i].fst + d[p.snd] < d[G2[p.snd][i].snd]){
d[G2[p.snd][i].snd] = G2[p.snd][i].fst + d[p.snd];
pq.push({d[G2[p.snd][i].snd], G2[p.snd][i].snd});
}
}
}
REP(i, v.size()){
if(d[v] != INF_LL){
cout << "inf" << endl;
return 0;
}
}
cout << -point[N-1] << endl;
return 0;
}
| a.cc: In function 'int main()':
a.cc:279:21: error: no match for 'operator[]' (operand types are 'll [1010]' {aka 'long long int [1010]'} and 'std::vector<int>')
279 | if(d[v] != INF_LL){
| ^
|
s564691489 | p03722 | C++ |
#include <iostream>
#include <vector>
using namespace std;
#define rep(i, n) REP(i, 0, n)
#define REP(i, a, n) for(int i = a ; i < (int)n ; i++)
#define pb push_back
#define N_MAX 1000
#define INF -1000000000000;
typedef long long ll;
struct Edge{
int from, to;
ll cost;
Edge(int f, int t, ll c) : from(f), to(t), cost(c) {}
};
int n, m;
vector<Edge> edges;
ll d[N_MAX+1];
bool bellman_ford(){
rep(i, N_MAX+1) d[i] =-INF;
d[0] = 0;
rep(i, 2*n+1){
for(auto &edge:edges){
if(d[edge.from] != INF && d[edge.to] < d[edge.from] + edge.cost){
d[edge.to] = d[edge.from] + edge.cost;
if(i == n-1) return true;
}
}
}
return false;
}
signed main(){
int f, t;
ll c;
cin >> n >> m;
rep(i, m){
cin >> f >> t >> c;
f--; t--;
edges.emplace_back(f, t, c);
}
if(bellman_ford()){
cout << "inf" << endl;
}else{
cout << d[n-1] << endl;
}
}
| a.cc: In function 'bool bellman_ford()':
a.cc:31:34: error: expected ')' before '[' token
31 | if(d[edge.from] != INF && d[edge.to] < d[edge.from] + edge.cost){
| ~ ^
| )
a.cc:31:33: error: label 'd' used but not defined
31 | if(d[edge.from] != INF && d[edge.to] < d[edge.from] + edge.cost){
| ^
|
s403750224 | p03722 | C++ | #include "bits/stdc++.h"
#define MOD 1000000007
#define INF 11234567890
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;
LL N, M, a[2123], b[2123], c[2123];
LL ans;
struct edge { LL from, to, cost; };
edge G[2123];
LL d[1123];
bool negative[1123];
// s 番目の頂点から各頂点への最短距離を求める
void bellman_ford(LL s)
{
std::fill_n(d, N + 1, INF);
d[s] = 0;
rep(i, N - 1)
{
rep(j, M)
{
auto e = G[j];
if (d[e.from] == INF) { continue; }
d[e.to] = std::min(d[e.to], d[e.from] + e.cost); (d[e.from] != INF) { }
}
}
}
// negative[N] == true なら負の閉路が存在する
void find_negative_loop()
{
memset(negative, false, sizeof(false));
rep(i, N)
{
rep(j, M)
{
auto e = G[j];
if (d[e.from] == INF) { continue; }
if (d[e.to] > d[e.from] + e.cost)
{
d[e.to] = d[e.from] + e.cost;
negative[e.to] = true;
}
if (negative[e.from]) { negative[e.to] = true; }
}
}
}
int main()
{
in >> N >> M;
rep(i, M)
{
in >> a[i] >> b[i] >> c[i];
G[i] = { a[i],b[i],-c[i] };
}
bellman_ford(1);
ans = d[N];
find_negative_loop();
if (negative[N]) { out << "inf" << std::endl; }
else { out << -ans << std::endl; }
return 0;
} | a.cc: In function 'void bellman_ford(LL)':
a.cc:28:92: error: expected ';' before '{' token
28 | d[e.to] = std::min(d[e.to], d[e.from] + e.cost); (d[e.from] != INF) { }
| ^~
| ;
|
s072221412 | p03722 | C++ | #define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <climits>
#include <cstdlib>
#include <vector>
#include <queue>
#include <unordered_map>
#include <iomanip>
#include <random>
#include <future>
#include <thread>
#include <utility>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define INF (INT_MAX/3)
#define INF_L (LLONG_MAX/3)
#define PSB push_back
#define PN 1000000007
typedef long long LL;
#define int long long
// booooooooooooost
// #include <boost/multiprecision/cpp_int.hpp>
// #include <boost/multiprecision/cpp_dec_float.hpp>
// namespace mp = boost::multiprecision; //多倍長整数(mp::cpp_int), 多倍長小数(mp::cpp_dec_float_100)
signed main() {
int N, M;
struct edge { int from, to, cost; };
vector<edge> es;
vector<int> d;
cin >> N >> M;
for (int i = 0; i < M; ++i) {
int a, b, c;
cin >> a >> b >> c;
es.push_back(edge{ a - 1, b - 1, -c });
}
d.assign(N, INF_L);
d[0] = 0;
for (int v = 0; v < N; ++v) {
/* // 負閉路検出
if (v == N - 1) {
d[N - 1] = -INF_L;
break;
} */
bool update = false;
for (int i = 0; i < M; ++i) {
edge e = es[i];
if (d[e.from] != INF_L && d[e.to] > d[e.from] + e.cost) {
d[e.to] = d[e.from] + e.cost;
update = true;
}
}
if (!update) break;
}
int ans = d[N - 1];
/* bool negative[1000];
for (int i = 0; i < N; ++i) {
negative[i] = false;
}
for (int loop = 0; loop < N; ++loop) {
for (int i = 0; i < M; ++i) {
edge e = es[i];
if (d[e.from] != INF_L && d[e.to] > d[e.from] + e.cost) {
d[e.to] = d[e.from] + e.cost;
negative[e.to] = true;
}
if (negative[e.from] == true) {
negative[e.to] = true;
}
}
} */
int ans = d[N - 1];
bool negative = false;
for (int i = 0; i < N; ++i) d[i] = 0;
for (int i = 0; i < N; ++i) {
for (int j = 0; j < M; ++j) {
edge e = es[j];
if (d[e.to] > d[e.from] + e.cost) {
d[e.to] = d[e.from] + e.cost;
if (i == N - 1) negative = true;
}
}
}
cout << (negative ? "inf" : to_string(-ans)) << endl;
return 0;
} | a.cc: In function 'int main()':
a.cc:91:13: error: redeclaration of 'long long int ans'
91 | int ans = d[N - 1];
| ^~~
a.cc:71:13: note: 'long long int ans' previously declared here
71 | int ans = d[N - 1];
| ^~~
|
s348824202 | p03722 | C++ | #include <stdlib.h>
#include <iostream>
using ll = long long;
const ll INF = 1ll << 50;
int main(void){
int N, M;
std::cin >> N >> M;
const int NMAX = 1000;
const int MMAX = 2000;
int a[MMAX], b[MMAX];
ll c[MMAX];
for (int i = 0; i < M; ++ i){
std::cin >> a[i] >> b[i] >> c[i];
c[i] = -c[i];
}
//printf("%d \n", f);
ll dist[NMAX];
dist[0] = 0;
for (int loop = 0; loop < N - 1; ++ loop) {
for (int i = 0; i < M; ++ i) {
if (dist[a[i] - 1] == INF) continue;
if (dist[b[i] - 1] > dist[a[i] - 1] + c[i]) {
dist[b[i] - 1] = dist[a[i] - 1] + c[i];
}
}
}
ll ans = dist[N - 1];
bool negative[NMAX];
for (int i = 0; i < N; ++ i) {
negative[i] = false;
}
for (int loop = 0; loop < N; ++ loop) {
for (int i = 0; i < M; ++ i) {
if (dist[a[i] - 1] == INF) continue;
if (dist[b[i] - 1] > dist[a[i] - 1] + c[i]) {
dist[b[i] - 1] = dist[a[i] - 1] + c[i];
negative[b[i] - 1] = true;
}
if (negative[a[i] - 1] == true) {
negative[b[i] - 1] = true;
}
}
}
if (negative[N - 1])
std::cout << "inf" << std::endl;
else
std::cout << -ans << std::endl;
return 0;
| a.cc: In function 'int main()':
a.cc:62:12: error: expected '}' at end of input
62 | return 0;
| ^
a.cc:7:15: note: to match this '{'
7 | int main(void){
| ^
|
s987061241 | p03722 | C++ | #include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <limits>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
typedef long long ll;
int main(void) {
ll N,M;
cin >> N >> M;
vector<ll> a(M), b(M), c(M);
REP(i, M) {
cin >> a[i] >> b[i] >> c[i];
}
ll d[1010];
d[0] = 0;
FOR(i, 1, 1010) d[i] = -LLONG_MAX;
ll count = 0;
ll temp;
while (count < N*2+1) {
if (count == N) {
temp = d[N - 1];
}
FOR(i, 0, M){
d[b[i]-1] = max(d[b[i]-1], d[a[i]-1]+c[i]);
}
if (count == (N*2)) {
break;
}
count++;
}
if (d[N - 1] > temp) {
cout << "inf" << endl;
}
else {
cout << d[N - 1] << endl;
}
return 0;
} | a.cc: In function 'int main()':
a.cc:24:33: error: 'LLONG_MAX' was not declared in this scope
24 | FOR(i, 1, 1010) d[i] = -LLONG_MAX;
| ^~~~~~~~~
a.cc:6:1: note: 'LLONG_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
5 | #include <limits>
+++ |+#include <climits>
6 | using namespace std;
|
s788246530 | p03722 | C++ | #include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <limits>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
typedef long long ll;
int main(void) {
ll N,M;
cin >> N >> M;
vector<ll> a(M), b(M), c(M);
REP(i, M) {
cin >> a[i] >> b[i] >> c[i];
}
ll d[1010];
d[0] = 0;
FOR(i, 1, 1010) d[i] = -LLONG_MAX;
ll count = 0;
ll temp;
while (count < N*3) {
if (count == N) {
temp = d[N - 1];
}
FOR(i, 0, M){
d[b[i]-1] = max(d[b[i]-1], d[a[i]-1]+c[i]);
}
if (count == (N*2)) {
break;
}
count++;
}
if (d[N - 1] > temp) {
cout << "inf" << endl;
}
else {
cout << d[N - 1] << endl;
}
return 0;
} | a.cc: In function 'int main()':
a.cc:24:33: error: 'LLONG_MAX' was not declared in this scope
24 | FOR(i, 1, 1010) d[i] = -LLONG_MAX;
| ^~~~~~~~~
a.cc:6:1: note: 'LLONG_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
5 | #include <limits>
+++ |+#include <climits>
6 | using namespace std;
|
s970953213 | p03722 | C++ | #include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <limits>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
typedef long long ll;
int main(void) {
int N,M;
cin >> N >> M;
vector<int> a(M), b(M), c(M);
REP(i, M) {
cin >> a[i] >> b[i] >> c[i];
}
ll d[1010];
d[0] = 0;
FOR(i, 1, 1010) d[i] = -LLONG_MAX;
ll count = 0;
ll temp;
while (count < N*3) {
if (count == N) {
temp = d[N - 1];
}
FOR(i, 0, M){
d[b[i]-1] = max(d[b[i]-1], d[a[i]-1]+c[i]);
}
if (count == (N*2)) {
break;
}
count++;
}
if (d[N - 1] > temp) {
cout << "inf" << endl;
}
else {
cout << d[N - 1] << endl;
}
return 0;
} | a.cc: In function 'int main()':
a.cc:25:33: error: 'LLONG_MAX' was not declared in this scope
25 | FOR(i, 1, 1010) d[i] = -LLONG_MAX;
| ^~~~~~~~~
a.cc:6:1: note: 'LLONG_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
5 | #include <limits>
+++ |+#include <climits>
6 | using namespace std;
|
s172238202 | p03722 | C++ | #include <bits/stdc++.h>
#define MAXN 1000
std::vector < std::pair <int,int> > g[MAXN+1];
long long dist[MAXN+1];
int main(){
int i,n,m,a,b,c,j;
long long aux;
cin >> n >> m;
for(i=1;i<=m;i++){
cin >> a >> b >> c;
g[a].push_back(std::make_pair(b,c));
}
for(i=1;i<=n;i++)
dist[i]=-(1LL<<62);
long long aux=dist[n];
for(i=0;i<n+1;i++){
for(j=1;j<=n;j++)
for(auto it:g[j])
if(dist[j]+it.second>dist[it.first])
dist[it.first]=dist[j]+it.second;
if(dist[n]!=aux&&i==n){
cout << inf << "\n";
return 0;
}
aux=dist[n];
}
cout << dist[n] << "\n";
} | a.cc: In function 'int main()':
a.cc:8:6: error: 'cin' was not declared in this scope; did you mean 'std::cin'?
8 | cin >> n >> m;
| ^~~
| std::cin
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:62:18: note: 'std::cin' declared here
62 | extern istream cin; ///< Linked to standard input
| ^~~
a.cc:15:14: error: redeclaration of 'long long int aux'
15 | long long aux=dist[n];
| ^~~
a.cc:7:16: note: 'long long int aux' previously declared here
7 | long long aux;
| ^~~
a.cc:22:19: error: 'cout' was not declared in this scope; did you mean 'std::cout'?
22 | cout << inf << "\n";
| ^~~~
| std::cout
/usr/include/c++/14/iostream:63:18: note: 'std::cout' declared here
63 | extern ostream cout; ///< Linked to standard output
| ^~~~
a.cc:22:27: error: 'inf' was not declared in this scope; did you mean 'ynf'?
22 | cout << inf << "\n";
| ^~~
| ynf
a.cc:27:4: error: 'cout' was not declared in this scope; did you mean 'std::cout'?
27 | cout << dist[n] << "\n";
| ^~~~
| std::cout
/usr/include/c++/14/iostream:63:18: note: 'std::cout' declared here
63 | extern ostream cout; ///< Linked to standard output
| ^~~~
|
s788108766 | p03722 | C++ | #include<bits/stdc++.h>
#define rep(i,start,lim) for(lld i=start;i<lim;i++)
#define repd(i,start,lim) for(lld i=start;i>=lim;i--)
#define scan(x) scanf("%lld",&x)
#define print(x) printf("%lld ",x)
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define br printf("\n")
#define sz(a) lld((a).size())
#define YES printf("YES\n")
#define NO printf("NO\n")
#define all(c) (c).begin(),(c).end()
using namespace std;
#define INF 1011111111
#define LLINF 1000111000111000111LL
#define EPS (double)1e-10
#define MOD 1000000007
#define PI 3.14159265358979323
using namespace std;
typedef long double ldb;
typedef long long lld;
lld powm(lld base,lld exp,lld mod=MOD) {lld ans=1;while(exp){if(exp&1) ans=(ans*base)%mod;exp>>=1,base=(base*base)%mod;}return ans;}
typedef vector<lld> vlld;
typedef pair<lld,lld> plld;
typedef map<lld,lld> mlld;
typedef set<lld> slld;
#define N 100005
lld a[N],b[N],c[N],dis[N],neg[N];
int main()
{
lld n,m;
cin>>n>>m,dis[1]=0;
rep(i,2,n+1) dis[i]=LLINF,neg[i]=0;
rep(i,1,m+1) cin>>a[i]>>b[i]>>c[i],c[i]*=-1;
rep(i,1,n) rep(j,1,m+1) if(dis[a[j]]!=LLINF and dis[b[j]]>dis[a[j]]+c[j]) dis[b[j]]=dis[a[j]]+c[j];
rep(j,1,m+1) if(dis[a[j]]!=LLINF and dis[b[j]]>dis[a[j]]+c[j]) neg[b[j]]=1; else if(neg[a[i]]) neg[b[i]]=1;
if(!neg[n]) print(-dis[n]);
else printf("inf\n");
return 0;
}
| a.cc: In function 'int main()':
a.cc:38:99: error: 'i' was not declared in this scope
38 | rep(j,1,m+1) if(dis[a[j]]!=LLINF and dis[b[j]]>dis[a[j]]+c[j]) neg[b[j]]=1; else if(neg[a[i]]) neg[b[i]]=1;
| ^
|
s656698210 | p03722 | C | #include<stdio.h>
#define INF -1000000000000000000
#define ll long long
int main() {
int n, m, f;
int i, j;
ll score[1010] = {};
scanf("%d %d", &n, &m);
ll a[2010] = {};
ll b[2010] = {};
ll c[2010] = {};
for (i = 1; i < m+1; i++) {
scanf("%lld %lld %lld", &a[i], &b[i], &c[i]);
}
for (i = 2; i < n+1; i++) {
score[i] = INF;
}
for (i = 1; i < n+1; i++) {
f = 0;
for (j = 1; j < m+1; j++) {
int from = a[j];
int to = b[j];
/*基本的に、修正が入ったらf=1
*/
if (score[to] < score[from] + c[j]) {
score[to] = score[from] + c[j];
f = 1;
}
}
}
/*修正が入らなくなれば(f==0)そこで終わり*/
if (f == 0) {
break;
}
/*修正が入り続け、最後も修正が起こればinf*/
if (i == n) {
printf("inf\n");
return 0;
}
}
printf("%lld\n", score[n]);
return 0;
}
| main.c: In function 'main':
main.c:34:7: error: break statement not within loop or switch
34 | break;
| ^~~~~
main.c: At top level:
main.c:42:10: error: expected declaration specifiers or '...' before string constant
42 | printf("%lld\n", score[n]);
| ^~~~~~~~
main.c:42:20: error: unknown type name 'score'
42 | printf("%lld\n", score[n]);
| ^~~~~
main.c:43:3: error: expected identifier or '(' before 'return'
43 | return 0;
| ^~~~~~
main.c:44:1: error: expected identifier or '(' before '}' token
44 | }
| ^
|
s433297641 | p03722 | C++ | #include <cstdio>
#include <iostream>
#include <algorithm>
#include <queue>
#include <cstring>
using namespace std;
int to[2010],len[2010],findnext[2010],head[1010],num,Numpath,Numdot,Inqueue[1010];
long long Shortpath[1010];
void add(int from,int go,int length)
{
to[++num]=go;
len[num]=length;
findnext[num]=head[from];
head[from]=num;
}
int checked[1010],times[1010];
int Checkspfa(int source)
{
memset(Shortpath,0xf7,sizeof(Shortpath));
memset(Inqueue,0,sizeof(Inqueue));
queue<int>unwork;
unwork.push(source),Inqueue[source]=1,Shortpath[source]=0,checked[source]=1;
while(unwork.size())
{
int first,substitute;
first=unwork.front(),unwork.pop(),Inqueue[first]=0;
for(int i=head[first];i;i=findnext[i])
{
substitute=to[i];
checked[substitute]=1;
if(Shortpath[substitute]<Shortpath[first]+len[i])
{
Shortpath[substitute]=Shortpath[first]+len[i];
times[substitute]++;
unwork.push(substitute);
if(times[substitute]>Numdot)
return 0;
}
}
}
return 1;
}
void Workspfa(int source)
{
memset(Shortpath,0xf7,sizeof(Shortpath));
memset(Inqueue,0,sizeof(Inqueue));
queue<int >unwork;
unwork.push(source),Inqueue[source]=1,Shortpath[source]=0;
while(unwork.size())
{
int first;
first=unwork.front(),unwork.pop(),Inqueue[first]=0;
for(int i=head[first];i;i=findnext[i])
if(Shortpath[to[i]]<Shortpath[first]+len[i])
{
Shortpath[to[i]]=Shortpath[first]+len[i];
if(Inqueue[to[i]]==0)
Inqueue[to[i]]=1,unwork.push(to[i]);
}
}
}
int main()
{
cin>>Numdot>>Numpath;
for(int i=1;i<=Numpath;i++)
{
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
add(a,b,c);
}
if(Checkspfa(1)==0)
{
cout<<"inf";
return 0;
}
Workspfa(1);
while(1)
{
long long q++;
}
//printf("%lld\n",Shortpath[Numdot]);
return 0;
} | a.cc: In function 'int main()':
a.cc:79:28: error: expected initializer before '++' token
79 | long long q++;
| ^~
|
s885543872 | p03722 | C++ | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<pair<ll, ll> > vp;
#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define out(n) cout << (n) << endl;
__attribute__((constructor))
void initial() {
cin.tie(0);
ios::sync_with_stdio(false);
}
vector<vp> a(1001);
vi ma(1001, -1e10);
ll n, m, ans = -1e10;
bool inf;
int tansaku(ll score, int node, vp load, bool kinf) {
if(inf) return 0;
if(node == n) {
if(ans > score) return 0;
ans = score;
}
rep(i, 0, a[node].size()) {
ll x = a[node][i].first;
if(load[x].first >= 2) return 0;
if(load[x].first && load[x].second < score) kinf = true;
if(kinf && x == n) {
inf = true;
return 0;
}
if(kinf || ma[x] < score) {
if(!kinf)ma[x] = load[x].second = score;
load[x].first++;
tansaku(score + a[node][i].second, x, load, kinf);
}
}
}
int main() {
cin >> n >> m;
ll na, nb, nc;
vp load(1001);
load[1].second = true;
rep(i, 0, m) {
cin >> na >> nb >> nc;
a[na].pb(make_pair(nb, nc));
}
if(a[1].first != 0) {
while(1) {
}
}
tansaku(0, 1, load, false);
if(inf) out("inf")
else out(ans)
}
| a.cc: In function 'int main()':
a.cc:60:11: error: '__gnu_cxx::__alloc_traits<std::allocator<std::vector<std::pair<long long int, long long int> > >, std::vector<std::pair<long long int, long long int> > >::value_type' {aka 'class std::vector<std::pair<long long int, long long int> >'} has no member named 'first'
60 | if(a[1].first != 0) {
| ^~~~~
a.cc: In function 'int tansaku(ll, int, vp, bool)':
a.cc:47:1: warning: control reaches end of non-void function [-Wreturn-type]
47 | }
| ^
|
s966226386 | p03722 | C++ | // ProgramingExcerciseA.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
using namespace std;
typedef long long LL;
/*
Edge class
*/
struct Edge {
int to;
LL cost;
Edge(int to, LL cost) : to(to), cost(cost) {}
};
// node and edge
/*
data structure
graph[0], graph[1], graph[2], ...... => initial vertex
|_ Edge(t0,c0)
|_ Edge(t1,c1) => terminal vertex and consumed cost
|_ Edge(t2,c2)
|
:
*/
typedef vector<vector<Edge> > AdjList;
AdjList graph;
// limitataion of cost
const LL INF = -99999999999;
// the minimum path
vector<LL> dist;
void debug_log(int n) {
cout << "progress..." << endl;
for (int i = 0; i < n; i++)
{
if (dist[i] != INF)
cout << dist[i] << " -> ";
else
cout << "INF -> ";
}
cout << endl;
}
/*
Bellman-Ford Algortithm.
argument n is number of vertex, and s is index of initial vertex.
*/
bool bellman_ford(int n, int s) {
dist = vector<LL>(n, INF); // n node are initialize with int value - INF
dist[s] = 0; // first node (default - 0)
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]; // a edge
if (dist[v] != INF && dist[e.to]<(dist[v] + e.cost)) {
dist[e.to] = dist[v] + e.cost;
//debug_log(n);
if (i == (n - 1))
return true;
}
}
}
}
return false;
}
int main(int argc, char const *argv[]) {
// n is number of vertex, m is number of edge
int n, m;
bool loop_flag;
cin >> n >> m;
// create graph where n vertex are puted
graph = AdjList(n);
for (int i = 0; i<m; i++) {
int from, to;
LL cost;
cin >> from >> to >> cost;
graph[from - 1].push_back(Edge(to - 1, cost));
}
// start Bellman-Ford algorithm
loop_flag = bellman_ford(n, 0);
// output result
if (loop_flag) {
cout << "inf" << endl;
}
else
{
cout << dist[n - 1] << endl;
}
return 0;
}
| a.cc:4:10: fatal error: stdafx.h: No such file or directory
4 | #include "stdafx.h"
| ^~~~~~~~~~
compilation terminated.
|
s766607412 | p03722 | C++ | #include <stdio.h>
#include <map>
#include <vector>
struct edge {long long from,long long to,long long cost;};
edge es[20000];
long long d[1100];
int over[1252];
int n,m;
using namespace std;
int main(){
scanf("%d%d",&n,&m);
for(int i=0;i<m;i++){
long long a,b,c;
scanf("%ld%ld%ld", &a,&b,&c);
es[i].from = a-1;
es[i].to = b-1;
es[i].cost = c;
}
for(int i = 0; i < n; i++)d[i] = -1000000000;
d[0] = 0;
for(int k=0;k<=2*n;k++){
for(int i=0;i<m;i++){
if(d[es[i].from] != -1000000000 && d[es[i].to] < d[es[i].from] + es[i].cost){
d[es[i].to] = d[es[i].from] + es[i].cost;
if(k == 2*n){
over[es[i].to] = 1;
}
}
}
}
if(over[n-1])printf("inf\n");
else printf("%ld", d[n-1]);
}
| a.cc:4:29: error: expected unqualified-id before 'long'
4 | struct edge {long long from,long long to,long long cost;};
| ^~~~
a.cc: In function 'int main()':
a.cc:18:11: error: 'struct edge' has no member named 'to'
18 | es[i].to = b-1;
| ^~
a.cc:19:11: error: 'struct edge' has no member named 'cost'
19 | es[i].cost = c;
| ^~~~
a.cc:25:50: error: 'struct edge' has no member named 'to'
25 | if(d[es[i].from] != -1000000000 && d[es[i].to] < d[es[i].from] + es[i].cost){
| ^~
a.cc:25:78: error: 'struct edge' has no member named 'cost'
25 | if(d[es[i].from] != -1000000000 && d[es[i].to] < d[es[i].from] + es[i].cost){
| ^~~~
a.cc:26:17: error: 'struct edge' has no member named 'to'
26 | d[es[i].to] = d[es[i].from] + es[i].cost;
| ^~
a.cc:26:45: error: 'struct edge' has no member named 'cost'
26 | d[es[i].to] = d[es[i].from] + es[i].cost;
| ^~~~
a.cc:28:22: error: 'struct edge' has no member named 'to'
28 | over[es[i].to] = 1;
| ^~
|
s690724323 | p03722 | C++ | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<pair<int, int> > vp;
#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define out(n) cout << (n) << endl;
__attribute__((constructor))
void initial() {
cin.tie(0);
ios::sync_with_stdio(false);
}
vector<vp> a(1001);
vi ma(1001, -1e10);
ll n, m, ans = -1e10;
bool inf;
int tansaku(ll score, int node, vi load, ll flag, ll kinf) {
if(inf) return 0;
if(node == n) {
ans = max(ans, score);
ma[n] = ans;
}
rep(i, 0, a[node].size()) {
ll x = a[node][i].first;
if(load[n] && kinf) inf = true;
if(flag || ma[x] < score && !load[x]) {
if(x == flag) {
if(score <= 0) flag = false;
else kinf = true;
return 0;
}
if(!flag) ma[x] = score, load[x] = true;
tansaku(score + a[node][i].second, a[node][i].first, load, flag, kinf);
}else if(load[x]) {
flag = x;
score = 0;
tansaku(score + a[node][i].second, a[node][i].first, load, flag, kinf);
return 0;
}
}
}
int main() {
cin >> n >> m;
ll na, nb, nc;
vi load(1001);
load[1] = true;
rep(i, 0, m) {
cin >> na >> nb >> nc;
a[na].pb(make_pair(nb, nc));
}
tansaku(0, 1, load, false);
if(inf) out("inf")
else out(ans)
}
| a.cc: In function 'int main()':
a.cc:64:10: error: too few arguments to function 'int tansaku(ll, int, vi, ll, ll)'
64 | tansaku(0, 1, load, false);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~
a.cc:26:5: note: declared here
26 | int tansaku(ll score, int node, vi load, ll flag, ll kinf) {
| ^~~~~~~
a.cc: In function 'int tansaku(ll, int, vi, ll, ll)':
a.cc:51:1: warning: control reaches end of non-void function [-Wreturn-type]
51 | }
| ^
|
s885507861 | p03722 | C | #include <stdio.h>
#define INF 2300000000000000000L
long long dist[1001][1001];
int main(){
int V,E,i,j;long long k;
scanf("%d%d",&V,&E);
for(i=0;i<V;i++){
for(j=0;j<i;j++)dist[i][j]=INF;
dist[i][j++]=0;
for(;j<V;j++)dist[i][j]=INF;
}
for(;E--;)scanf("%d%d%lld",&i,&j,&k),dist[i-1][j-1]=-k;
for(k=0;k<V;k++)for(i=0;i<V;i++)for(j=0;j<V;j++)
if(dist[i][k]<INF && dist[k][j]<INF && dist[i][j]>dist[i]k]+dist[k][j])
dist[i][j]=dist[i][k]+dist[k][j];
for(i=0;i<V;i++)if(dist[i][i]<0){puts("inf");return 0;}
printf("%lld",-dist[0][V-1]);
return 0;
} | main.c: In function 'main':
main.c:14:66: warning: comparison between pointer and integer
14 | if(dist[i][k]<INF && dist[k][j]<INF && dist[i][j]>dist[i]k]+dist[k][j])
| ^
main.c:14:74: error: expected ')' before 'k'
14 | if(dist[i][k]<INF && dist[k][j]<INF && dist[i][j]>dist[i]k]+dist[k][j])
| ~ ^
| )
main.c:14:75: error: expected statement before ']' token
14 | if(dist[i][k]<INF && dist[k][j]<INF && dist[i][j]>dist[i]k]+dist[k][j])
| ^
main.c:14:87: error: expected ';' before ')' token
14 | if(dist[i][k]<INF && dist[k][j]<INF && dist[i][j]>dist[i]k]+dist[k][j])
| ^
| ;
main.c:14:87: error: expected statement before ')' token
|
s097393316 | p03722 | C | #include <stdio.h>
#define INF 2100000000
int dist[1001][1001];
int main(){
int V,E,i,j,k;
scanf("%d%d",&V,&E);
for(i=0;i<V;i++){
for(j=0;j<i;j++)dist[i][j]=INF;
dist[i][j++]=0;
for(;j<V;j++)dist[i][j]=INF;
}
for(;E--;)scanf("%d%d%d",&i,&j,&k),dist[i-1][j-1]=k;
for(k=0;k<V;k++)for(i=0;i<V;i++)for(j=0;j<V;j++)
if(dist[i][k]<INF && dist[k][j]<INF && dist[i][j]>dist[i][k]+dist[k][j])
dist[i][j]=dist[i][k]+dist[k][j];
for(i=0;i<V;i++)if(dist[i][i]<0){puts("inf");return 0;}
printf("%d",dist[0][n-1]);
return 0;
} | main.c: In function 'main':
main.c:17:25: error: 'n' undeclared (first use in this function)
17 | printf("%d",dist[0][n-1]);
| ^
main.c:17:25: note: each undeclared identifier is reported only once for each function it appears in
|
s586744071 | p03722 | C++ | #include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
void DFS(vector<vector<int>> &graph, vector<bool> visited, int k, long long sum, long long &ret)
{
if (ret == -1) return;
int N = visited.size();
if (k == N - 1)
{
ret = max(sum, ret);
}
for (int i = 0; i < N; ++i)
{
if (graph[k][i] != 0)
{
if (visited[i])
{
ret = -1; return;
}
else {
visited[i] = true;
DFS(graph, visited, i, sum + graph[k][i], ret);
visited[i] = false;
}
}
}
}
int main()
{
int N, M;
cin >> N >> M;
vector<vector<int>> graph(N, vector<int>(N, 0));
for (int i = 0; i < M; ++i)
{
int a, b, c;
cin >> a >> b >> c;
graph[a - 1][b - 1] = c;
}
vector<bool> visited(N, false);
long long ret = LLONG_MIN;
DFS(graph, visited, 0, 0, ret);
if (ret == -1)
{
cout << "inf" << endl;
}
else {
cout << ret << endl;
}
return 0;
} | a.cc: In function 'int main()':
a.cc:44:25: error: 'LLONG_MIN' was not declared in this scope
44 | long long ret = LLONG_MIN;
| ^~~~~~~~~
a.cc:5:1: note: 'LLONG_MIN' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
4 | #include <algorithm>
+++ |+#include <climits>
5 | using namespace std;
|
s287831776 | p03722 | C++ | public class Main{
public static void main(String[] args) {
java.util.Scanner scanner = new java.util.Scanner (System.in);
int N=scanner.nextInt() ;
int K=scanner.nextInt() ;
int a[]=new int[N+1];
int b[]=new int[N+1];
for(int i=1;i<=N;i++){
a[i]=scanner.nextInt();
b[i]=scanner.nextInt();
}
int array[]=new int[100000+1];
for(int i=0;i<=100000;i++){
array[i]=0;
}
for(int i=1;i<=N;i++){
array[a[i]]+=b[i];
}
int count=0;
for(int i=1;i<=N;i++){
count+=array[i];
if(count>=K){
System.out.println(a[i]);
break;
}
}
}
} | a.cc:1:1: error: expected unqualified-id before 'public'
1 | public class Main{
| ^~~~~~
|
s253895838 | p03722 | C++ | #include<iostream>
#include<cstdio>
#include<algorithm>
#include<math.h>
#include<vector>
#include<map>
#include<string.h>
#define int long long
using namespace std;
int mincost[1000][1000];
signed main() {
int a, b; scanf("%lld%lld", &a, &b);
for (int c = 0; c < a; c++) {
for (int d = 0; d < a; d++) {
mincost[c][d] = LLONG_MAX;
}
mincost[c][c] = 0;
}
for (int c = 0; c < b; c++) {
int d, e, f; scanf("%lld%lld%lld", &d, &e, &f);
mincost[d - 1][e - 1] = -f;
}
for (int x = 0; x < a; x++) {
for (int y = 0; y < a; y++) {
for (int z = 0; z < a; z++) {
if (mincost[y][x] != LLONG_MAX&& mincost[x][z] != LLONG_MAX) {
mincost[y][z] = min(mincost[y][z], mincost[y][x] + mincost[x][z]);
}
}
}
}
if (mincost[a - 1][a - 1] < 0) { puts("inf"); }
else {
printf("%lld\n", -mincost[0][a - 1]);
}
} | a.cc: In function 'int main()':
a.cc:16:41: error: 'LLONG_MAX' was not declared in this scope
16 | mincost[c][d] = LLONG_MAX;
| ^~~~~~~~~
a.cc:8:1: note: 'LLONG_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
7 | #include<string.h>
+++ |+#include <climits>
8 | #define int long long
a.cc:27:54: error: 'LLONG_MAX' was not declared in this scope
27 | if (mincost[y][x] != LLONG_MAX&& mincost[x][z] != LLONG_MAX) {
| ^~~~~~~~~
a.cc:27:54: note: 'LLONG_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
|
s320382130 | p03722 | C++ | #include<iostream>
#include<cstdio>
#include<algorithm>
#include<math.h>
#include<vector>
#include<map>
#define int long long
using namespace std;
int mincost[1000][1000];
signed main() {
int a, b; scanf("%lld%lld", &a, &b);
for (int c = 0; c < a; c++) {
for (int d = 0; d < a; d++) {
mincost[c][d] = LLONG_MAX;
}
mincost[c][c] = 0;
}
for (int c = 0; c < b; c++) {
int d, e, f; scanf("%lld%lld%lld", &d, &e, &f);
mincost[d - 1][e - 1] = -f;
}
for (int x = 0; x < a; x++) {
for (int y = 0; y < a; y++) {
for (int z = 0; z < a; z++) {
if (mincost[y][x] != LLONG_MAX&& mincost[x][z] != LLONG_MAX) {
mincost[y][z] = min(mincost[y][z], mincost[y][x] + mincost[x][z]);
}
}
}
}
if (mincost[a - 1][a - 1] < 0) { puts("inf"); }
else {
printf("%lld\n", -mincost[0][a - 1]);
}
} | a.cc: In function 'int main()':
a.cc:15:41: error: 'LLONG_MAX' was not declared in this scope
15 | mincost[c][d] = LLONG_MAX;
| ^~~~~~~~~
a.cc:7:1: note: 'LLONG_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
6 | #include<map>
+++ |+#include <climits>
7 | #define int long long
a.cc:26:54: error: 'LLONG_MAX' was not declared in this scope
26 | if (mincost[y][x] != LLONG_MAX&& mincost[x][z] != LLONG_MAX) {
| ^~~~~~~~~
a.cc:26:54: note: 'LLONG_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
|
s732076205 | p03722 | C++ | #include <iostream>
using namespace std;
#define MAX_E 2010 // max M
#define MAX_V 1010 // max N
// #define INF 9223372036854775800
#define INF (1LL << 59)
struct edge {
int from;
int to;
long long cost;
};
edge es[MAX_E];
long long d[MAX_V];
bool negative[MAX_V];
int V, E;
int main() {
cin >> V >> E;
for (int i = 1; i < MAX_V; i++) d[i] = INF;
for (int i = 1; i < MAX_V; i++) negative[i] = false;
for (int i = 1; i <= E; i++) {
int a, b;
long long c;
cin >> a >> b >> c;
es[i].from = a;
es[i].to = b;
es[i].cost = c * -1;
}
d[1] = 0;
for (int i = 0; i < V - 1; i++) {
for (int j = 1; 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;
}
}
}
long long ans = d[N] * -1;
for (int i = 0; i < V; i++) {
for (int j = 1; 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;
negative[i] = true;
}
}
}
if (negative[V]) {
cout << "inf" << endl;
} else {
cout << ans << endl;
}
return 0;
}
| a.cc: In function 'int main()':
a.cc:42:21: error: 'N' was not declared in this scope
42 | long long ans = d[N] * -1;
| ^
|
s714223881 | p03722 | C++ | #include <iostream>
using namespace std;
#define MAX_E 2010 // max M
#define MAX_V 1010 // max N
// #define INF 9223372036854775800
#define INF (1LL << 59)
struct edge {
int from;
int to;
long long cost;
};
edge es[MAX_E];
long long d[MAX_V];
bool negative[MAX_V];
int V, E;
int main() {
cin >> V >> E;
for (int i = 1; i < MAX_V; i++) d[i] = INF;
for (int i = 1; i < MAX_V; i++) negative[i] = false;
for (int i = 1; i <= E; i++) {
int a, b;
long long c;
cin >> a >> b >> c;
es[i].from = a;
es[i].to = b;
es[i].cost = c * -1;
}
d[1] = 0;
for (int i = 0; i < V - 1; i++) {
for (int j = 1; 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;
}
}
}
for (int i = 0; i < V; i++) {
for (int j = 1; 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;
negative[i] = true;
}
}
}
if (negative[N]) {
cout << "inf" << endl;
} else {
cout << d[V] * -1 << endl;
}
return 0;
}
| a.cc: In function 'int main()':
a.cc:53:16: error: 'N' was not declared in this scope
53 | if (negative[N]) {
| ^
|
s934726270 | p03722 | C++ | #include <bits/stdc++.h>
using namespace std;
int N, M;
bool heiro;
struct edge{
int to;
ll cost;
edge(int t, ll c) : to(t), cost(c) {}
};
vector<edge> G[1001];
typedef long long ll;
ll dist[1001];
const ll INF = 1e12;
int main() {
cin >> N >> M;
for(int i = 0; i < M; i++) {
int a, b, c;
cin >> a >> b >> c;
a--; b--;
G[a].push_back(edge(b,-c));
}
fill(dist,dist+N,INF);
dist[0] = 0;
for(int i = 0; i < N; i++) {
for(int j = 0; j < N; j++) {
for(int k = 0; k < G[j].size(); k++) {
edge u = G[j][k];
if(dist[u.to] > dist[j] + u.cost) {
dist[u.to] = dist[j] + u.cost;
if(i == N-1) heiro = true;
}
}
}
}
if(heiro) {
cout << "inf" <<endl;
return 0;
}
cout << -dist[N-1] <<endl;
}
| a.cc:9:3: error: 'll' does not name a type
9 | ll cost;
| ^~
a.cc:10:15: error: 'll' has not been declared
10 | edge(int t, ll c) : to(t), cost(c) {}
| ^~
a.cc: In constructor 'edge::edge(int, int)':
a.cc:10:30: error: class 'edge' does not have any field named 'cost'
10 | edge(int t, ll c) : to(t), cost(c) {}
| ^~~~
a.cc: In function 'int main()':
a.cc:34:37: error: 'struct edge' has no member named 'cost'
34 | if(dist[u.to] > dist[j] + u.cost) {
| ^~~~
a.cc:35:36: error: 'struct edge' has no member named 'cost'
35 | dist[u.to] = dist[j] + u.cost;
| ^~~~
|
s130048924 | p03722 | C++ | #include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#define CH(N,A,B) (A<=N&&N<B)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define RREP(i,a,b) for(int i=(b-1);a<=i;i--)
#define F first
#define S second
using namespace std;
const long long INF = 1LL<<50;
int N,M;
long long a[2010], b[2010], c[2010];
int main() {
cin>>N>>M;
REP(i,0,M){
cin>>a[i]>>b[i]>>c[i];
c[i] = (-1)*c[i];
}
//BF
long long d[1010];
REP(i,0,N) d[i] = INF;
d[0] = 0;
REP(i,0,N-1){
REP(j,0,M){
if(d[a[j]-1]==INF) continue; /*0から到達不可能な起点は除外*/
long long t;
if(d[a[j]-1]+c[j] <= (-1)*INF) t = (-1)*INF;
else t = d[a[j]-1]+c[j];
d[b[j]-1] = min(d[b[j]-1], t);
}
}
long long ans = d[N-1];
REP(i,0,N) negative[i] = false;
REP(i,0,2*N){
REP(j,0,M){
if(d[a[j]-1]==INF) continue;
long long t;
if(d[a[j]-1]+c[j] <= (-1)*INF) t = (-1)*INF;
else t = d[a[j]-1]+c[j];
d[b[j]-1] = min(d[b[j]-1], t);
}
}
/*d[N-1]が更新される => 0->N-1 の経路のどっかで正の閉路が存在する
(2回めの更新はN回回すだけでいいのか?)*/
if(ans != d[N-1]) cout<<"inf"<<endl;
else cout<<(-1)*ans<<endl;
return 0;
}
| a.cc: In function 'int main()':
a.cc:51:14: error: 'negative' was not declared in this scope
51 | REP(i,0,N) negative[i] = false;
| ^~~~~~~~
|
s146392016 | p03722 | C++ | #include<cstdio>#include<cstring>#include<cmath>#include<string>#include<iostream>#include<algorithm>#include<map>#include<queue>#include<set>#include<vector>using namespace std;typedef long long ll;const int N=2005;const ll INF=1e11+7;#define de(x) cout<<#x<<" = "<<x<<endl;#define pb push_back#define fi first#define se second#define mp make_pair#define pii pair<int,int>//--------------------------------------//int cnt,last[N];void init() { cnt=0; memset(last,-1,sizeof last);}struct edge { int to,pre,cost;}es[2*N];void addEdge(int u,int v,int w) { edge e={v,last[u],w}; es[++cnt]=e; last[u]=cnt;}bool vis[N];ll dis[N];int cntt[N];bool SPFA(int s,int n) { memset(cntt,0,sizeof cnt); memset(vis,false,sizeof vis); for(int i=1;i<=n;++i) dis[i]=-INF; vis[s]=true; dis[s]=0; queue<int> que; que.push(s); while(!que.empty()) { int u=que.front(); que.pop(); vis[u]=false; for(int i=last[u];i!=-1;i=es[i].pre) { int v=es[i].to; if(dis[u]+es[i].cost>dis[v]) { dis[v]=dis[u]+es[i].cost; if(!vis[v]) { vis[v]=true; que.push(v); if(++cntt[v]>n) return false;//存在环 } } } } return true;}int main() { int n,m,a,b,c; while(~scanf("%d%d",&n,&m)) { init(); for(int i=1;i<=m;++i) { scanf("%d%d%d",&a,&b,&c); addEdge(a,b,c); } if(SPFA(1,n)) { printf("%I64d\n",dis[n]); } else puts("inf"); } return 0;} | a.cc:1:17: warning: extra tokens at end of #include directive
1 | #include<cstdio>#include<cstring>#include<cmath>#include<string>#include<iostream>#include<algorithm>#include<map>#include<queue>#include<set>#include<vector>using namespace std;typedef long long ll;const int N=2005;const ll INF=1e11+7;#define de(x) cout<<#x<<" = "<<x<<endl;#define pb push_back#define fi first#define se second#define mp make_pair#define pii pair<int,int>//--------------------------------------//int cnt,last[N];void init() { cnt=0; memset(last,-1,sizeof last);}struct edge { int to,pre,cost;}es[2*N];void addEdge(int u,int v,int w) { edge e={v,last[u],w}; es[++cnt]=e; last[u]=cnt;}bool vis[N];ll dis[N];int cntt[N];bool SPFA(int s,int n) { memset(cntt,0,sizeof cnt); memset(vis,false,sizeof vis); for(int i=1;i<=n;++i) dis[i]=-INF; vis[s]=true; dis[s]=0; queue<int> que; que.push(s); while(!que.empty()) { int u=que.front(); que.pop(); vis[u]=false; for(int i=last[u];i!=-1;i=es[i].pre) { int v=es[i].to; if(dis[u]+es[i].cost>dis[v]) { dis[v]=dis[u]+es[i].cost; if(!vis[v]) { vis[v]=true; que.push(v); if(++cntt[v]>n) return false;//存在环 } } } } return true;}int main() { int n,m,a,b,c; while(~scanf("%d%d",&n,&m)) { init(); for(int i=1;i<=m;++i) { scanf("%d%d%d",&a,&b,&c); addEdge(a,b,c); } if(SPFA(1,n)) { printf("%I64d\n",dis[n]); } else puts("inf"); } return 0;}
| ^
/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
|
s877180205 | p03722 | C++ | #include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <functional>
#include <set>
#include <sstream>
#include <cctype>
#include <stack>
#include <queue>
#include <cstring>
#include <map>
#include <list>
#include <cassert>
using namespace std;
struct edge{
int from,to;
__int128 cost;
edge(int from_,int to_,__int128 cost_){
from=from_;
to=to_;
cost=cost_;
}
};
int n,m;
vector<edge> e;
vector<__int128> d;
const __int128 INF=1e18;
bool bf(int s){
for(int i=0;i<n;i++) d[i]=INF;
d[s]=0;
int cnt=0;
while(true){
bool update=false;
for(int i=0;i<m;i++){
edge ed=e[i];
if(d[ed.from]!=INF && d[ed.to]>d[ed.from]+ed.cost){
d[ed.to]=d[ed.from]+ed.cost;
update=true;
}
}
if(!update) break;
if(cnt==n+1) return false;
cnt++;
}
return true;
}
int main(){
cin>>n>>m;
d=vector<__int128>(n);
for(int i=0;i<m;i++){
int a,b;
__int128 c;
cin>>a>>b>>c;
e.push_back(edge(a-1,b-1,-c));
}
if(bf(0)) cout<<(-d[n-1])<<endl;
else cout<<"inf"<<endl;
return 0;
} | a.cc: In function 'int main()':
a.cc:70:26: error: no match for 'operator>>' (operand types are 'std::basic_istream<char>::__istream_type' {aka 'std::basic_istream<char>'} and '__int128')
70 | cin>>a>>b>>c;
| ~~~~~~~~~^~~
| | |
| | __int128
| std::basic_istream<char>::__istream_type {aka std::basic_istream<char>}
In file included from /usr/include/c++/14/iostream:42,
from a.cc:1:
/usr/include/c++/14/istream:170:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(bool&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' (near match)
170 | operator>>(bool& __n)
| ^~~~~~~~
/usr/include/c++/14/istream:170:7: note: conversion of argument 1 would be ill-formed:
a.cc:70:28: error: cannot bind non-const lvalue reference of type 'bool&' to a value of type '__int128'
70 | cin>>a>>b>>c;
| ^
/usr/include/c++/14/istream:174:7: note: candidate: 'std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(short int&) [with _CharT = char; _Traits = std::char_traits<char>]' (near match)
174 | operator>>(short& __n);
| ^~~~~~~~
/usr/include/c++/14/istream:174:7: note: conversion of argument 1 would be ill-formed:
a.cc:70:28: error: cannot bind non-const lvalue reference of type 'short int&' to a value of type '__int128'
70 | cin>>a>>b>>c;
| ^
/usr/include/c++/14/istream:177:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(short unsigned int&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' (near match)
177 | operator>>(unsigned short& __n)
| ^~~~~~~~
/usr/include/c++/14/istream:177:7: note: conversion of argument 1 would be ill-formed:
a.cc:70:28: error: cannot bind non-const lvalue reference of type 'short unsigned int&' to a value of type '__int128'
70 | cin>>a>>b>>c;
| ^
/usr/include/c++/14/istream:181:7: note: candidate: 'std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(int&) [with _CharT = char; _Traits = std::char_traits<char>]' (near match)
181 | operator>>(int& __n);
| ^~~~~~~~
/usr/include/c++/14/istream:181:7: note: conversion of argument 1 would be ill-formed:
a.cc:70:28: error: cannot bind non-const lvalue reference of type 'int&' to a value of type '__int128'
70 | cin>>a>>b>>c;
| ^
/usr/include/c++/14/istream:184:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(unsigned int&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' (near match)
184 | operator>>(unsigned int& __n)
| ^~~~~~~~
/usr/include/c++/14/istream:184:7: note: conversion of argument 1 would be ill-formed:
a.cc:70:28: error: cannot bind non-const lvalue reference of type 'unsigned int&' to a value of type '__int128'
70 | cin>>a>>b>>c;
| ^
/usr/include/c++/14/istream:188:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(long int&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' (near match)
188 | operator>>(long& __n)
| ^~~~~~~~
/usr/include/c++/14/istream:188:7: note: conversion of argument 1 would be ill-formed:
a.cc:70:28: error: cannot bind non-const lvalue reference of type 'long int&' to a value of type '__int128'
70 | cin>>a>>b>>c;
| ^
/usr/include/c++/14/istream:192:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(long unsigned int&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' (near match)
192 | operator>>(unsigned long& __n)
| ^~~~~~~~
/usr/include/c++/14/istream:192:7: note: conversion of argument 1 would be ill-formed:
a.cc:70:28: error: cannot bind non-const lvalue reference of type 'long unsigned int&' to a value of type '__int128'
70 | cin>>a>>b>>c;
| ^
/usr/include/c++/14/istream:199:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(long long int&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' (near match)
199 | operator>>(long long& __n)
| ^~~~~~~~
/usr/include/c++/14/istream:199:7: note: conversion of argument 1 would be ill-formed:
a.cc:70:28: error: cannot bind non-const lvalue reference of type 'long long int&' to a value of type '__int128'
70 | cin>>a>>b>>c;
| ^
/usr/include/c++/14/istream:203:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(long long unsigned int&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' (near match)
203 | operator>>(unsigned long long& __n)
| ^~~~~~~~
/usr/include/c++/14/istream:203:7: note: conversion of argument 1 would be ill-formed:
a.cc:70:28: error: cannot bind non-const lvalue reference of type 'long long unsigned int&' to a value of type '__int128'
70 | cin>>a>>b>>c;
| ^
/usr/include/c++/14/istream:219:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(float&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' (near match)
219 | operator>>(float& __f)
| ^~~~~~~~
/usr/include/c++/14/istream:219:7: note: conversion of argument 1 would be ill-formed:
a.cc:70:28: error: cannot bind non-const lvalue reference of type 'float&' to a value of type '__int128'
70 | cin>>a>>b>>c;
| ^
/usr/include/c++/14/istream:223:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(double&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' (near match)
223 | operator>>(double& __f)
| ^~~~~~~~
/usr/include/c++/14/istream:223:7: note: conversion of argument 1 would be ill-formed:
a.cc:70:28: error: cannot bind non-const lvalue reference of type 'double&' to a value of type '__int128'
70 | cin>>a>>b>>c;
| ^
/usr/include/c++/14/istream:227:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(long double&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' (near match)
227 | operator>>(long double& __f)
| ^~~~~~~~
/usr/include/c++/14/istream:227:7: note: conversion of argument 1 would be ill-formed:
a.cc:70:28: error: cannot bind non-const lvalue reference of type 'long double&' to a value of type '__int128'
70 | cin>>a>>b>>c;
| ^
/usr/include/c++/14/istream:328:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(void*&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' (near match)
328 | operator>>(void*& __p)
| ^~~~~~~~
/usr/include/c++/14/istream:328:7: note: conversion of argument 1 would be ill-formed:
a.cc:70:28: error: invalid conversion from '__int128' to 'void*' [-fpermissive]
70 | cin>>a>>b>>c;
| ^
| |
| __int128
a.cc:70:28: error: cannot bind rvalue '(void*)((long int)c)' to 'void*&'
/usr/include/c++/14/istream:122:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(__istream_type& (*)(__istream_type&)) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]' (near match)
122 | operator>>(__istream_type& (*__pf)(__istream_type&))
| ^~~~~~~~
/usr/include/c++/14/istream:122:7: note: conversion of argument 1 would be ill-formed:
a.cc:70:28: error: invalid conversion from '__int128' to 'std::basic_istream<char>::__istream_type& (*)(std::basic_istream<char>::__istream_type&)' {aka 'std::basic_istream<char>& (*)(std::basic_istream<char>&)'} [-fpermissive]
70 | cin>>a>>b>>c;
| ^
| |
| __int128
/usr/include/c++/14/istream:126:7: note: candidate: 'std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(__ios_type& (*)(__ios_type&)) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>; __ios_type = std::basic_ios<char>]' (near match)
126 | operator>>(__ios_type& (*__pf)(__ios_type&))
| ^~~~~~~~
/usr/include/c++/14/istream:126:7: note: conversion of argument 1 would be ill-formed:
a.cc:70:28: error: invalid conversion from '__int128' to 'std::basic_istream<char>::__ios_type& (*)(std::basic_istream<char>::__ios_type&)' {aka 'std::basic_ios<char>& (*)(std::basic_ios<char>&)'} [-fpermissive]
70 | cin>>a>>b>>c;
| ^
| |
s391094066 | p03722 | C++ | #include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <functional>
#include <set>
#include <sstream>
#include <cctype>
#include <stack>
#include <queue>
#include <cstring>
#include <map>
#include <list>
#include <cassert>
using namespace std;
struct edge{
int from,to;
int128_t cost;
edge(int from_,int to_,int128_t cost_){
from=from_;
to=to_;
cost=cost_;
}
};
int n,m;
vector<edge> e;
vector<int128_t> d;
const int128_t INF=1e18;
bool bf(int s){
for(int i=0;i<n;i++) d[i]=INF;
d[s]=0;
int cnt=0;
while(true){
bool update=false;
for(int i=0;i<m;i++){
edge ed=e[i];
if(d[ed.from]!=INF && d[ed.to]>d[ed.from]+ed.cost){
d[ed.to]=d[ed.from]+ed.cost;
update=true;
}
}
if(!update) break;
if(cnt==n+1) return false;
cnt++;
}
return true;
}
int main(){
cin>>n>>m;
d=vector<long long>(n);
for(int i=0;i<m;i++){
int a,b;
int128_t c;
cin>>a>>b>>c;
e.push_back(edge(a-1,b-1,-c));
}
if(bf(0)) cout<<-d[n-1]<<endl;
else cout<<"inf"<<endl;
return 0;
} | a.cc:24:9: error: 'int128_t' does not name a type; did you mean 'int8_t'?
24 | int128_t cost;
| ^~~~~~~~
| int8_t
a.cc:25:32: error: 'int128_t' has not been declared
25 | edge(int from_,int to_,int128_t cost_){
| ^~~~~~~~
a.cc: In constructor 'edge::edge(int, int, int)':
a.cc:28:17: error: 'cost' was not declared in this scope; did you mean 'cosl'?
28 | cost=cost_;
| ^~~~
| cosl
a.cc: At global scope:
a.cc:34:8: error: 'int128_t' was not declared in this scope; did you mean 'int8_t'?
34 | vector<int128_t> d;
| ^~~~~~~~
| int8_t
a.cc:34:16: error: template argument 1 is invalid
34 | vector<int128_t> d;
| ^
a.cc:34:16: error: template argument 2 is invalid
a.cc:35:7: error: 'int128_t' does not name a type; did you mean 'int8_t'?
35 | const int128_t INF=1e18;
| ^~~~~~~~
| int8_t
a.cc: In function 'bool bf(int)':
a.cc:38:31: error: invalid types 'int[int]' for array subscript
38 | for(int i=0;i<n;i++) d[i]=INF;
| ^
a.cc:38:35: error: 'INF' was not declared in this scope
38 | for(int i=0;i<n;i++) d[i]=INF;
| ^~~
a.cc:39:10: error: invalid types 'int[int]' for array subscript
39 | d[s]=0;
| ^
a.cc:47:29: error: invalid types 'int[int]' for array subscript
47 | if(d[ed.from]!=INF && d[ed.to]>d[ed.from]+ed.cost){
| ^
a.cc:47:40: error: 'INF' was not declared in this scope
47 | if(d[ed.from]!=INF && d[ed.to]>d[ed.from]+ed.cost){
| ^~~
a.cc:47:48: error: invalid types 'int[int]' for array subscript
47 | if(d[ed.from]!=INF && d[ed.to]>d[ed.from]+ed.cost){
| ^
a.cc:47:57: error: invalid types 'int[int]' for array subscript
47 | if(d[ed.from]!=INF && d[ed.to]>d[ed.from]+ed.cost){
| ^
a.cc:47:70: error: 'struct edge' has no member named 'cost'
47 | if(d[ed.from]!=INF && d[ed.to]>d[ed.from]+ed.cost){
| ^~~~
a.cc:48:34: error: invalid types 'int[int]' for array subscript
48 | d[ed.to]=d[ed.from]+ed.cost;
| ^
a.cc:48:43: error: invalid types 'int[int]' for array subscript
48 | d[ed.to]=d[ed.from]+ed.cost;
| ^
a.cc:48:56: error: 'struct edge' has no member named 'cost'
48 | d[ed.to]=d[ed.from]+ed.cost;
| ^~~~
a.cc: In function 'int main()':
a.cc:66:11: error: cannot convert 'std::vector<long long int>' to 'int' in assignment
66 | d=vector<long long>(n);
| ^~~~~~~~~~~~~~~~~~~~
| |
| std::vector<long long int>
a.cc:69:17: error: 'int128_t' was not declared in this scope; did you mean 'int8_t'?
69 | int128_t c;
| ^~~~~~~~
| int8_t
a.cc:70:28: error: 'c' was not declared in this scope
70 | cin>>a>>b>>c;
| ^
a.cc:74:27: error: invalid types 'int[int]' for array subscript
74 | if(bf(0)) cout<<-d[n-1]<<endl;
| ^
|
s982063444 | p03722 | C++ | #include <cstdio>
#include <cstdlib>
#include <vector>
using namespace std;
struct edge {
int from;
int to;
long long cost;
};
edge es[2000];
long long d[1000];
int num[1000];
int N,M;
long long INF = 1LL << 50;
bool est_path(int s);
//bool find_n_loop();
int main(){
scanf("%d %d",&N,&M);
for(int i=0;i<M;i++){
int a,b;
long long c;
scanf("%d %d %lld",&a,&b,&c);
struct edge e;
e.from = a-1;
e.to = b-1;
e.cost = -1*c;
es[i] = e;
}
if(largest_path(0)){
printf("inf\n");
}else{
//printf("%d\n",num[N-1]);
printf("%lld\n",-d[N-1]);
}
/*
for(int i=0;i<N;i++){
printf("%lld\n",d[i]);
}
*/
return 0;
}
//
bool largest_path(int s){
for(int i=0;i<N;i++) d[i] = INF;
d[s] = 0;
for(int j=0;j<N-1;j++){
//bool update = 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 = true;
}
}
//if(!update) break;
}
bool negative[MAX_N];
for (int i = 0; i < N; ++i) {
negative[i] = false;
}
for (int loop = 0; loop < N; ++loop) {
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;
negative[e.to] = true;
}
// if (negative[e.from] == true) {
// negative[e.to] = true;
// }
}
}
return negative[N - 1];
}
//
/*
bool find_n_loop(){
//for(int i=0;i<N;i++) d[i] = 0;
for(int i=0;i<N;i++){
for(int j=0;j<M;j++){
edge e = es[j];
if(d[e.to]>d[e.from]+e.cost){
d[e.to] = d[e.from] + e.cost;
if(i==N-1) return true;
}
}
}
return false;
}
*/
| a.cc: In function 'int main()':
a.cc:38:12: error: 'largest_path' was not declared in this scope; did you mean 'est_path'?
38 | if(largest_path(0)){
| ^~~~~~~~~~~~
| est_path
a.cc: In function 'bool largest_path(int)':
a.cc:69:23: error: 'MAX_N' was not declared in this scope
69 | bool negative[MAX_N];
| ^~~~~
a.cc:71:17: error: 'negative' was not declared in this scope
71 | negative[i] = false;
| ^~~~~~~~
a.cc:78:33: error: 'negative' was not declared in this scope
78 | negative[e.to] = true;
| ^~~~~~~~
a.cc:85:12: error: 'negative' was not declared in this scope
85 | return negative[N - 1];
| ^~~~~~~~
|
s608978003 | p03722 | C++ | #include <cstdio>
#include <cstdlib>
#include <vector>
using namespace std;
struct edge {
int from;
int to;
long long cost;
};
edge es[2000];
long long d[1000];
int num[1000];
int N,M;
long long INF = 1LL << 50;
bool largest_path(int s);
//bool find_n_loop();
int main(){
scanf("%d %d",&N,&M);
for(int i=0;i<M;i++){
int a,b;
long long c;
scanf("%d %d %lld",&a,&b,&c);
struct edge e;
e.from = a-1;
e.to = b-1;
e.cost = -1*c;
es[i] = e;
}
if(largest_path(0)){
printf("inf\n");
}else{
//printf("%d\n",num[N-1]);
printf("%lld\n",-d[N-1]);
}
/*
for(int i=0;i<N;i++){
printf("%lld\n",d[i]);
}
*/
return 0;
}
//
bool largest_path(int s){
for(int i=0;i<N;i++) d[i] = INF;
d[s] = 0;
for(int j=0;j<N-1;j++){
//bool update = 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 = true;
}
}
//if(!update) break;
}
bool negative[MAX_N];
for (int i = 0; i < N; ++i) {
negative[i] = false;
}
for (int loop = 0; loop < N; ++loop) {
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;
negative[e.to] = true;
}
// if (negative[e.from] == true) {
// negative[e.to] = true;
// }
}
}
return negative[N - 1];
}
//
/*
bool find_n_loop(){
//for(int i=0;i<N;i++) d[i] = 0;
for(int i=0;i<N;i++){
for(int j=0;j<M;j++){
edge e = es[j];
if(d[e.to]>d[e.from]+e.cost){
d[e.to] = d[e.from] + e.cost;
if(i==N-1) return true;
}
}
}
return false;
}
*/
| a.cc: In function 'bool largest_path(int)':
a.cc:69:23: error: 'MAX_N' was not declared in this scope
69 | bool negative[MAX_N];
| ^~~~~
a.cc:71:17: error: 'negative' was not declared in this scope
71 | negative[i] = false;
| ^~~~~~~~
a.cc:78:33: error: 'negative' was not declared in this scope
78 | negative[e.to] = true;
| ^~~~~~~~
a.cc:85:12: error: 'negative' was not declared in this scope
85 | return negative[N - 1];
| ^~~~~~~~
|
s296291173 | p03722 | C++ | #include <cstdio>
#include <cstdlib>
#include <vector>
using namespace std;
struct edge {
int from;
int to;
long long cost;
};
edge es[2000];
long long d[1000];
int num[1000];
int N,M;
long long INF = 1LL << 50;
bool largest_path(int s);
//bool find_n_loop();
int main(){
scanf("%d %d",&N,&M);
for(int i=0;i<M;i++){
int a,b;
long long c;
scanf("%d %d %lld",&a,&b,&c);
struct edge e;
e.from = a-1;
e.to = b-1;
e.cost = -1*c;
es[i] = e;
}
largest_path(0);
if(find_n_loop()){
printf("inf\n");
}else{
//printf("%d\n",num[N-1]);
printf("%lld\n",-d[N-1]);
}
/*
for(int i=0;i<N;i++){
printf("%lld\n",d[i]);
}
*/
return 0;
}
//
bool largest_path(int s){
for(int i=0;i<N;i++) d[i] = INF;
d[s] = 0;
for(int j=0;j<N-1;j++){
//bool update = 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 = true;
}
}
//if(!update) break;
}
bool negative[MAX_N];
for (int i = 0; i < N; ++i) {
negative[i] = false;
}
for (int loop = 0; loop < N; ++loop) {
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;
negative[e.to] = true;
}
// if (negative[e.from] == true) {
// negative[e.to] = true;
// }
}
}
return negative[N - 1];
}
//
/*
bool find_n_loop(){
//for(int i=0;i<N;i++) d[i] = 0;
for(int i=0;i<N;i++){
for(int j=0;j<M;j++){
edge e = es[j];
if(d[e.to]>d[e.from]+e.cost){
d[e.to] = d[e.from] + e.cost;
if(i==N-1) return true;
}
}
}
return false;
}
*/
| a.cc: In function 'int main()':
a.cc:38:12: error: 'find_n_loop' was not declared in this scope
38 | if(find_n_loop()){
| ^~~~~~~~~~~
a.cc: In function 'bool largest_path(int)':
a.cc:69:23: error: 'MAX_N' was not declared in this scope
69 | bool negative[MAX_N];
| ^~~~~
a.cc:71:17: error: 'negative' was not declared in this scope
71 | negative[i] = false;
| ^~~~~~~~
a.cc:78:33: error: 'negative' was not declared in this scope
78 | negative[e.to] = true;
| ^~~~~~~~
a.cc:85:12: error: 'negative' was not declared in this scope
85 | return negative[N - 1];
| ^~~~~~~~
|
s858022486 | p03722 | C++ | #include <iostream>
#include <algorithm>
using namespace std;
using ll = long long;
const ll INF = -(1LL << 50);
int n, m;
int a[2000], b[2000];
ll c[2000];
ll d[1001];
int main() {
cin >> n >> m;
for (int i = 0; i < m; ++i) {
cin >> a[i] >> b[i] >> c[i];
}
fill(d, d + 1001, INF);
for (int i = 0; i < n; ++i) {
if (a[i] == 1) {
d[b[i]] = c[i];
}
}
for (int i = 0; i < m; ++i) {
for (int j = 0; j < m; ++i) {
if (d[a[j]] == INF) continue;
ll d1 = d[b[j]];
ll d2 = d[a[j]] + c[j];
if (d1 < d2 ) {
d[b[j]] = d2;
}
}
}
ll ans = d[n];
for (int j = 0; j < m; ++i) {
if (d[a[j]] == INF) continue;
ll d1 = d[b[j]];
ll d2 = d[a[j]] + c[j];
if (d1 < d2 ) {
d[b[j]] = d2;
}
}
if (ans < d[n]) {
cout << "inf" << endl;
}else {
cout << ans << endl;
}
} | a.cc: In function 'int main()':
a.cc:37:34: error: 'i' was not declared in this scope
37 | for (int j = 0; j < m; ++i) {
| ^
|
s353525050 | p03722 | C++ | #include <iostream>
using namespace std;
using ll = long long;
const int MAX_N = 1000;
const int MAX_M = 2000;
const ll WEIGHT_MAX = 1000000000;
// 頂点fromから頂点toへのコストcostの辺
struct edge {
int from, to;
ll cost;
};
edge es[MAX_M]; // 辺
ll d[MAX_N]; // 始点から各頂点への最大距離
int N, M;
// s番目の頂点から各頂点への最短距離を求める
bool shortest_path(int s) {
for (int i = 0; i < N; ++i) {
d[i] = LLONG_MAX / 2;
}
d[s] = 0;
for (int loop = 0; loop < N - 1; ++loop) {
for (int i = 0; i < M; ++i) {
edge e = es[i];
if ((d[e.from] != LLONG_MAX / 2 && d[e.to] > d[e.from] + e.cost)) {
d[e.to] = d[e.from] + e.cost;
}
}
}
bool negative[MAX_N];
for (int i = 0; i < N; ++i) {
negative[i] = false;
}
for (int loop = 0; loop < N; ++loop) {
for (int i = 0; i < M; ++i) {
edge e = es[i];
if ((d[e.from] != LLONG_MAX / 2 && d[e.to] > d[e.from] + e.cost)) {
d[e.to] = d[e.from] + e.cost;
negative[e.to] = true;
}
// if (negative[e.from] == true) {
// negative[e.to] = true;
// }
}
}
return negative[N - 1];
}
int main() {
cin >> N >> M;
for (int i = 0; i < M; ++i) {
int from, to;
ll cost;
cin >> from >> to >> cost;
es[i].from = from - 1;
es[i].to = to - 1;
es[i].cost = -cost;
}
if (shortest_path(0)) {
cout << "inf" << endl;
} else {
cout << -d[N - 1] << endl;
}
return 0;
} | a.cc: In function 'bool shortest_path(int)':
a.cc:24:16: error: 'LLONG_MAX' was not declared in this scope
24 | d[i] = LLONG_MAX / 2;
| ^~~~~~~~~
a.cc:2:1: note: 'LLONG_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
1 | #include <iostream>
+++ |+#include <climits>
2 |
a.cc:30:31: error: 'LLONG_MAX' was not declared in this scope
30 | if ((d[e.from] != LLONG_MAX / 2 && d[e.to] > d[e.from] + e.cost)) {
| ^~~~~~~~~
a.cc:30:31: note: 'LLONG_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
a.cc:42:31: error: 'LLONG_MAX' was not declared in this scope
42 | if ((d[e.from] != LLONG_MAX / 2 && d[e.to] > d[e.from] + e.cost)) {
| ^~~~~~~~~
a.cc:42:31: note: 'LLONG_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
|
s473459662 | p03722 | Java | import java.util.Scanner;
class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
int M = sc.nextInt();
int[] a = new int[M];
int[] b = new int[M];
int[] c = new int[M];
int[][] to = new int[N+1][M];
int[] cnt = new int[N+1];
for(int i=1; i<=N; i++){
cnt[i] = 0;
}
for(int i=0; i<M; i++){
a[i] = sc.nextInt();
b[i] = sc.nextInt();
c[i] = sc.nextInt();
to[a[i]][cnt[a[i]]++] = i;
}
long[] score = new long[N+1];
score[1] = 0;
for(int i=2; i<=N; i++){
score[i] = Long.MIN_VALUE;
}
boolean[] check = new boolean[N+1]
for(int i=2; i<=N; i++){
check[i] = false;
}
int now = 1;
int next;
int time = 0;
boolean inf = false;
while(true){
for(int j=0; j<cnt[now]; j++){
next = to[now][j];
Long x = score[b[next]];
Long y = score[now] + c[next];
if(x.compareTo(y)==-1){
score[b[next]] = score[now] + c[next];
if(cnt[b[next]]>0 && check[b[next]==false){
stock[stock_cnt++] = b[next];
check[b[next]] = true;
}
}
}
if(stock_cnt!=0){
now = stock[stock_cnt-1];
stock_cnt--;
check[now] = false;
}else{
break;
}
time++;
if(time>=M*M){
inf = true;
break;
}
}
if(inf==true){
System.out.print("inf");
}else{
System.out.print(score[N]);
}
}
}
| Main.java:33: error: ';' expected
boolean[] check = new boolean[N+1]
^
Main.java:49: error: ']' expected
if(cnt[b[next]]>0 && check[b[next]==false){
^
2 errors
|
s952660837 | p03722 | C++ | #include"bits/stdc++.h"
//#include<bits/stdc++.h>
using namespace std;
#define print(x) cout<<x<<endl;
#define rep(i,a,b) for(int i=a;i<b;i++)
typedef long long ll;
const ll mod = LLONG_MAX;
print("inf")
return 0; | a.cc:4:18: error: 'cout' does not name a type
4 | #define print(x) cout<<x<<endl;
| ^~~~
a.cc:9:1: note: in expansion of macro 'print'
9 | print("inf")
| ^~~~~
a.cc:10:1: error: expected unqualified-id before 'return'
10 | return 0;
| ^~~~~~
|
s282710600 | p03722 | C++ | // ConsoleApplication1.cpp : コンソール アプリケーションのエントリ ポイントを定義します。
//
#include "stdafx.h"
#include<cmath>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<iostream>
#include<queue>
typedef long long i64;
using namespace std;
int n;
int m;
int a[2000];
int b[2000];
i64 c[2000];
struct Edge {
int src, dst;
i64 cost;
public:
Edge(int src, int dst, i64 cost) {
this->src = src;
this->dst = dst;
this->cost = cost;
}
};
struct State {
int cur;
i64 cost;
public:State(int cur, i64 cost) {
this->cur = cur;
this->cost = cost;
}
};
int main() {
scanf("%d%d", &n, &m);
for (int i = 0; i < m; ++i) {
scanf("%d%d%lld", a + i, b + i, c + i);
--a[i];
--b[i];
c[i] *= -1;
}
vector<vector<Edge>> g;
vector<vector<int>> rev;
g.resize(n);
rev.resize(n);
for (int i = 0; i < m; ++i) {
Edge e = { a[i],b[i],c[i] };
g[a[i]].push_back(Edge(a[i], b[i], c[i]));
rev[b[i]].push_back(a[i]);
}
i64 d[1000];
for (int i = 0; i < n; ++i) {
d[i] = 1LL << 60;
}
d[0] = 0;
vector<queue<State>> pend;
pend.resize(n + 2);
pend[0].push(State(0, 0));
for (int i = 0; i < n; ++i) {
while (!pend[i].empty()) {
State s = pend[i].front();
pend[i].pop();
if (d[s.cur] < s.cost)
continue;
for (Edge e : g[s.cur]) {
if (d[e.dst] > d[s.cur] + e.cost) {
d[e.dst] = d[s.cur] + e.cost;
State ns = { e.dst, d[e.dst] };
pend[i + 1].push(ns);
}
}
}
}
bool reach[1000];
queue<int> q;
q.push(n - 1);
reach[n - 1] = true;
while (q.size() > 0) {
int v = q.front();
q.pop();
for (int dst : rev[v]) {
if (!reach[dst]) {
reach[dst] = true;
q.push(dst);
}
}
}
bool f = false;
while (!pend[n].empty()) {
State s = pend[n].front();
pend[n].pop();
f |= reach[s.cur];
}
if (!f) {
printf("%lld\n", -d[n - 1]);
}
else {
printf("inf\n");
}
return 0;
} | a.cc:4:10: fatal error: stdafx.h: No such file or directory
4 | #include "stdafx.h"
| ^~~~~~~~~~
compilation terminated.
|
s222276148 | p03722 | C++ | #include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<unordered_map> | /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
|
s958438803 | p03722 | C++ | // ConsoleApplication1.cpp : コンソール アプリケーションのエントリ ポイントを定義します。
//
#include "stdafx.h"
#include<cmath>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<iostream>
#include<queue>
typedef long long i64;
using namespace std;
int n;
int m;
int a[2000];
int b[2000];
i64 c[2000];
struct Edge {
int src, dst;
i64 cost;
public:
Edge(int src, int dst, i64 cost) {
this->src = src;
this->dst = dst;
this->cost = cost;
}
};
struct State {
int cur;
i64 cost;
public:State(int cur, i64 cost) {
this->cur = cur;
this->cost = cost;
}
};
int main() {
scanf("%d%d", &n, &m);
for (int i = 0; i < m; ++i) {
scanf("%d%d%lld", a + i, b + i, c + i);
--a[i];
--b[i];
c[i] *= -1;
}
vector<vector<Edge>> g;
vector<vector<int>> rev;
g.resize(n);
rev.resize(n);
for (int i = 0; i < m; ++i) {
Edge e = { a[i],b[i],c[i] };
g[a[i]].push_back(Edge(a[i], b[i], c[i]));
rev[b[i]].push_back(a[i]);
}
i64 d[1000];
for (int i = 0; i < n; ++i) {
d[i] = 1LL << 60;
}
d[0] = 0;
vector<queue<State>> pend;
pend.resize(n + 2);
pend[0].push(State(0, 0));
for (int i = 0; i < n; ++i) {
while (pend[i].size() > 0) {
//while (!pend[i].empty()) {
State s = pend[i].front();
pend[i].pop();
if (d[s.cur] < s.cost)
continue;
for (Edge e : g[s.cur]) {
if (d[e.dst] > d[s.cur] + e.cost) {
d[e.dst] = d[s.cur] + e.cost;
State ns = { e.dst, d[e.dst] };
pend[i + 1].push(ns);
}
}
}
}
bool reach[1000];
queue<int> q;
q.push(n - 1);
reach[n - 1] = true;
while (q.size() > 0) {
int v = q.front();
q.pop();
for (int dst : rev[v]) {
if (!reach[dst]) {
reach[dst] = true;
q.push(dst);
}
}
}
bool f = false;
while (pend[n].size() > 0) {
State s = pend[n].front();
pend[n].pop();
f |= reach[s.cur];
}
if (!f) {
printf("%lld\n", -d[n - 1]);
}
else {
printf("inf\n");
}
return 0;
} | a.cc:4:10: fatal error: stdafx.h: No such file or directory
4 | #include "stdafx.h"
| ^~~~~~~~~~
compilation terminated.
|
s897603749 | p03722 | C++ | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) FOR(i,0,b)
#define INF 1e18+1
using ll = long long;
const ll mod = LLONG_MAX;
struct edge{
int from,to,cost;
};
edge es[2010];
int d[1010];//最短距離 入力を負にしてヒックリカセス
int V,E;
void shrtest_path(int s){
rep(i,V)d[i]=INF;
d[s]=0;
rep(cnt,V+1){
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(cnt>=V){
cout<<"inf"<<endl;
}
}
}
if(!update)break;
}
}
bool find(){
rep(i,V)d[i]=0;
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;
}
signed main(){
cin>>V>>E;
rep(i,E){
int a,b,c;
cin>>a>>b>>c;
a--;b--;
es[i].from=a;
es[i].to=b;
//入力 負
es[i].cost=-c;
}
bool changed[1000000];
rep(i,N){
dist[i] = INF;
changed[2*i]=false;
changed[2*i+1]=false;
}
int xc=2*V;
rep(i,xc){
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( e.to== V-1 )
changed[i]=true;
}
}
}
if(changed[2*V-1]){
cout<<"inf"<<endl;
}else{
shrtest_path(0);
cout<<-d[V-1]<<endl;
}
return 0;
}
| a.cc: In function 'int main()':
a.cc:75:9: error: 'N' was not declared in this scope
75 | rep(i,N){
| ^
a.cc:4:34: note: in definition of macro 'FOR'
4 | #define FOR(i,a,b) for(int i=a;i<b;i++)
| ^
a.cc:75:3: note: in expansion of macro 'rep'
75 | rep(i,N){
| ^~~
a.cc:76:5: error: 'dist' was not declared in this scope
76 | dist[i] = INF;
| ^~~~
|
s379467165 | p03722 | C++ | // ConsoleApplication1.cpp : コンソール アプリケーションのエントリ ポイントを定義します。
//
#include "stdafx.h"
#include<cmath>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<iostream>
#include<queue>
typedef long long i64;
using namespace std;
int n;
int m;
int a[1000];
int b[1000];
i64 c[1000];
struct Edge {
int src, dst;
i64 cost;
public:
Edge(int src, int dst, i64 cost) {
this->src = src;
this->dst = dst;
this->cost = cost;
}
};
struct State {
int cur;
i64 cost;
public:State(int cur, i64 cost) {
this->cur = cur;
this->cost = cost;
}
};
int main() {
scanf("%d%d", &n, &m);
for (int i = 0; i < m; ++i) {
scanf("%d%d%lld", a + i, b + i, c + i);
--a[i];
--b[i];
c[i] *= -1;
}
vector<vector<Edge>> g;
vector<vector<int>> rev;
g.resize(n);
rev.resize(n);
for (int i = 0; i < m; ++i) {
Edge e = { a[i],b[i],c[i] };
g[a[i]].push_back(Edge(a[i], b[i], c[i]));
rev[b[i]].push_back(a[i]);
}
i64 d[1000];
for (int i = 0; i < n; ++i) {
d[i] = 1LL << 60;
}
d[0] = 0;
vector<queue<State>> pend;
pend.resize(n + 2);
pend[0].push(State(0, 0));
for (int i = 0; i < n; ++i) {
while (pend[i].size() > 0) {
//while (!pend[i].empty()) {
State s = pend[i].front();
pend[i].pop();
if (d[s.cur] < s.cost)
continue;
for (Edge e : g[s.cur]) {
if (d[e.dst] > d[s.cur] + e.cost) {
d[e.dst] = d[s.cur] + e.cost;
State ns = { e.dst, d[e.dst] };
pend[i + 1].push(ns);
}
}
}
}
bool reach[1000];
queue<int> q;
q.push(n - 1);
reach[n - 1] = true;
while (q.size() > 0) {
int v = q.front();
q.pop();
for (int dst : rev[v]) {
if (!reach[dst]) {
reach[dst] = true;
q.push(dst);
}
}
}
bool f = false;
while (pend[n].size() > 0) {
State s = pend[n].front();
pend[n].pop();
f = f || reach[s.cur];
}
if (!f) {
printf("%lld\n", -d[n - 1]);
}
else {
printf("inf\n");
}
return 0;
} | a.cc:4:10: fatal error: stdafx.h: No such file or directory
4 | #include "stdafx.h"
| ^~~~~~~~~~
compilation terminated.
|
s681262105 | p03722 | C++ | #include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
struct edge{
int from;
int to;
long long int score;
};
int main()
{
long long int N,M;
cin >> N >> M;
vector<struct edge>es(M);
for(int i=0; i < M; i++){
long long int a,b,c;
cin >> a >> b >> c;
a--;
b--;
es[i].from = a;
es[i].to = b;
es[i].score = c;
}
long long int inf = 10000000000;
vector<long long int>s(N);
for(int i=0; i < N; i++)
s[i] = -inf;
s[0] = 0;
bool inf = false;
for(int j=0; j < N-1; j++){
bool update = false;
for(int i=0; i < M; i++){
struct edge e = es[i];
if(s[e.from] != -inf && s[e.to] < s[e.from] + e.score){
s[e.to] = s[e.from] + e.score;
update = true;
}
}
if(!update)
break;
}
vector<bool>ne(N);
for(int i=0; i < N; i++)
ne[i] = false;
for(int i=0; i < N; i++){
for(int j=0; j < M; j++){
struct edge e = es[j];
if(s[e.from] != -inf && s[e.to] < s[e.from] + e.score){
s[e.to] = s[e.from] + e.score;
ne[e.to] = true;
ne[e.from] = true;
}
}
}
if(ne[N-1])
cout << "inf" << endl;
else
cout << s[N-1] << endl;
return 0;
}
| a.cc: In function 'int main()':
a.cc:36:8: error: conflicting declaration 'bool inf'
36 | bool inf = false;
| ^~~
a.cc:31:17: note: previous declaration as 'long long int inf'
31 | long long int inf = 10000000000;
| ^~~
|
s600881218 | p03722 | C++ | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) FOR(i,0,b)
#define INF 1e18+1
using ll = long long;
const ll mod = LLONG_MAX;
struct edge{
int from,to,cost;
};
edge es[2010];
int d[1010];//最短距離 入力を負にしてヒックリカセス
int V,E;
void shrtest_path(int s){
rep(i,V)d[i]=INF;
d[s]=0;
rep(cnt,V+1){
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(cnt>=V){
cout<<"inf"<<endl;
return ;
goto E;
}
}
}
if(!update)break;
}
}
bool find(){
rep(i,V)d[i]=0;
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;
}
signed main(){
cin>>V>>E;
rep(i,E){
int a,b,c;
scanf("%lld %lld %lld",&a,&b,&c);
a--;b--;
es[i].from=a;
es[i].to=b;
//入力 負
es[i].cost=-c;
}
if(find()){
cout<<"inf"<<endl;
}else{
shrtest_path(0);
cout<<-d[V-1]<<endl;
}
E:
return 0;
}
| a.cc: In function 'void shrtest_path(long long int)':
a.cc:35:16: error: label 'E' used but not defined
35 | goto E;
| ^
|
s532577781 | p03722 | C++ | #include<bits//stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
struct P{
ll from,to,cost;
};
vector<P>e;
ll a[10001];
const ll inf=-999999999999999999;
bool b[1001];
signed main(){
ll n,m;
cin>>n>>m;
for(ll i=0;i<m;i++){
ll a,b,c;
cin>>a>>b>>c;
e.push_back(P{a,b,c});
}
for(ll i=0;i<=n;i++){
a[i]=inf;
b[i]=false;
}
a[1]=0;
ll sum=0;
for(ll j=0;j<n;j++){
bool up=false;
for(ll i=0;i<m;i++){
P t=e[i];
if(a[t.from]!=inf&&a[t.to]<a[t.from]+t.cost){
a[t.to]=a[t.from]+t.cost;
up=true;
}
}
if(!up) break;
}
}
for(ll j=0;j<n;j++){
for(ll i=0;i<m;i++){
P t=e[i];
if(a[t.from]!=inf&&a[t.to]<a[t.from]+t.cost){
a[t.to]=a[t.from]+t.cost;
b[t.to]=true;
}
}
}
if(!b[n]){
cout<<a[n]<<endl;
}
else{
cout<<"inf"<<endl;
}
} | a.cc:38:9: error: expected unqualified-id before 'for'
38 | for(ll j=0;j<n;j++){
| ^~~
a.cc:38:20: error: 'j' does not name a type
38 | for(ll j=0;j<n;j++){
| ^
a.cc:38:24: error: 'j' does not name a type
38 | for(ll j=0;j<n;j++){
| ^
a.cc:47:9: error: expected unqualified-id before 'if'
47 | if(!b[n]){
| ^~
a.cc:50:9: error: expected unqualified-id before 'else'
50 | else{
| ^~~~
a.cc:53:1: error: expected declaration before '}' token
53 | }
| ^
|
s204623659 | p03722 | C++ | #include <iostream>
#include <iomanip>
#include <cmath>
#include <queue>
#include <map>
#include <cstdlib>
#include <algorithm>
#include <utility>
#include <queue>
#include <string>
#include <functional>
#define rep(i, a, b) for(int i=a;i<b;++i)
#define MOD 1000000007
#define RAND 1000
#define LLONG_MIN -9223372036854775808
using namespace std;
int a[100000], b[100000], n, m;
long long int c[100000];
long long int maxy = LLONG_MIN;
void g(int start, int i, long long int score)
{
//cout << score << endl;
if (start == n) {
if (score > maxy)
maxy = score;
return;
}
for (int j = i; j < m; ++j)
if (a[j] == start) {
score += c[j];
g(b[j], j, score);
score = 0;
}
}
int main(void)
{
cin >> n >> m;
for (int i = 0; i < m; ++i) {
cin >> a[i] >> b[i] >> c[i];
}
g(1, 0, 0);
if(maxy >= 100000000000000)
cout<<''inf''<<endl;
else
cout << maxy << endl;
//system("pause");
return 0;
} | a.cc:21:22: warning: integer constant is so large that it is unsigned
21 | long long int maxy = LLONG_MIN;
| ^~~~~~~~~
a.cc:48:22: error: empty character constant
48 | cout<<''inf''<<endl;
| ^~~~~
a.cc:48:27: error: empty character constant
48 | cout<<''inf''<<endl;
| ^~
a.cc: In function 'int main()':
a.cc:48:22: error: unable to find character literal operator 'operator""inf' with 'char' argument
48 | cout<<''inf''<<endl;
| ^~~~~
|
s002533193 | p03722 | C++ | #include "stdafx.h"
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<queue>
using namespace std;
#define REP(i, a, n) for(int i=a; i<n; i++)
#define ll long long
#define INF 1000000005
#define _INF -9000000000000000000
//#define _INF -1000000005
struct St {
int cur;
vector<bool> flag;
ll cost;
St(int _cur, vector<bool> _flag, ll _cost) {
cur = _cur;
flag = _flag;
cost = _cost;
}
};
int cost[1001][1001];
int main()
{
int N, M;
cin >> N >> M;
REP(i, 0, N) REP(j, 0, N) cost[i][j] = INF;
REP(i, 0, M) {
int a, b, c;
cin >> a >> b >> c;
cost[--a][--b] = c;
}
vector<bool> flag(N, false);
St state(0, flag, 0);
ll ans = _INF;
queue<St> q;
q.push(state);
while (!q.empty()) {
St now = q.front();
q.pop();
REP(i, 0, N) {
if (cost[now.cur][i] != INF) {
cout << now.cost << endl;
if (now.flag[i] == true) {
cout << "inf" << endl;
return 0;
}
else if (i == N - 1) {
ans = max(ans, now.cost + cost[now.cur][i]);
//continue;
}
now.flag[now.cur] = true;
St next(i, now.flag, now.cost + cost[now.cur][i]);
q.push(next);
}
}
}
cout << ans << endl;
return 0;
} | a.cc:1:10: fatal error: stdafx.h: No such file or directory
1 | #include "stdafx.h"
| ^~~~~~~~~~
compilation terminated.
|
s204108004 | p03722 | C++ | n, m = map(int, input().split())
dist = [-10**18] * n
edge = []
for i in range(m):
a, b, c = map(int, input().split())
edge.append((a - 1, b - 1, c))
dist[0] = 0
for i in range(n):
for i in edge:
a, b, c = i
if dist[a] + c > dist[b]:
dist[b] = dist[a] + c
updated = True
ans = dist[n - 1]
for i in range(n):
for i in edge:
a, b, c = i
if dist[a] + c > dist[b]:
dist[b] = dist[a] + c
updated = True
if ans == dist[n - 1]:
print(dist[n - 1])
else:
print("inf")
| a.cc:1:1: error: 'n' does not name a type
1 | n, m = map(int, input().split())
| ^
|
s453572429 | p03722 | C++ | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) FOR(i,0,b)
#define INF 1e18+1
using ll = long long;
const ll mod = LLONG_MAX;
struct edge{
int from,to,cost;
};
edge es[2010];
int d[1010];//最短距離 入力を負にしてヒックリカセス
int V,E;
void shrtest_path(int s){
rep(i,V)d[i]=INF;
d[s]=0;
rep(xs,100000){
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;
if(e.to==V-1 && xs>V){
cout<<"inf"<<endl;
}
update=true;
}
}
if(!update)break;
}
}
signed main(){
cin>>V>>E;
rep(i,E){
int a,b,c;
scanf("%lld %lld %lld",&a,&b,&c);
a--;b--;
es[i].from=a;
es[i].to=b;
//入力 負
es[i].cost=-c;
}
if(find()){
cout<<"inf"<<endl;
}else{
shrtest_path(0);
cout<<-d[V-1]<<endl;
}
return 0;
}
| a.cc: In function 'int main()':
a.cc:55:10: error: no matching function for call to 'find()'
55 | if(find()){
| ~~~~^~
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:1:
/usr/include/c++/14/bits/stl_algo.h:3842:5: note: candidate: 'template<class _IIter, class _Tp> _IIter std::find(_IIter, _IIter, const _Tp&)'
3842 | find(_InputIterator __first, _InputIterator __last,
| ^~~~
/usr/include/c++/14/bits/stl_algo.h:3842:5: note: candidate expects 3 arguments, 0 provided
In file included from /usr/include/c++/14/algorithm:86:
/usr/include/c++/14/pstl/glue_algorithm_defs.h:60:1: note: candidate: 'template<class _ExecutionPolicy, class _ForwardIterator, class _Tp> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator> std::find(_ExecutionPolicy&&, _ForwardIterator, _ForwardIterator, const _Tp&)'
60 | find(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __value);
| ^~~~
/usr/include/c++/14/pstl/glue_algorithm_defs.h:60:1: note: candidate expects 4 arguments, 0 provided
In file included from /usr/include/c++/14/iterator:66,
from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:54:
/usr/include/c++/14/bits/streambuf_iterator.h:435:5: note: candidate: 'template<class _CharT2> typename __gnu_cxx::__enable_if<std::__is_char<_CharT2>::__value, std::istreambuf_iterator<_CharT, std::char_traits<_CharT> > >::__type std::find(istreambuf_iterator<_CharT, char_traits<_CharT> >, istreambuf_iterator<_CharT, char_traits<_CharT> >, const _CharT2&)'
435 | find(istreambuf_iterator<_CharT> __first,
| ^~~~
/usr/include/c++/14/bits/streambuf_iterator.h:435:5: note: candidate expects 3 arguments, 0 provided
|
s435835097 | p03722 | C++ | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<typename T> using Graph = vector<vector<T>>;
#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) REP(i, 0, a)
#define EACH(i, a) for (auto i: a)
#define ITR(x, a) for (__typeof(a.begin()) x = a.begin(); x != a.end(); x++)
#define ALL(a) (a.begin()), (a.end())
#define HAS(a, x) (a.find(x) != a.end())
#define endl '\n'
const ll inf = (ll)1e15;
int N, M;
int a[1005], b[1005];
ll c[1005], G[1005][1005];
int main(void) {
cin.tie(0);
ios::sync_with_stdio(false);
cin >> N >> M;
rep(i, M) {
cin >> a[i] >> b[i] >> c[i];
a[i]--;
b[i]--;
}
rep(i, N) rep(j, N) G[i][j] = i == j ? 0:-inf;
rep(i, N) G[a[i]][b[i]] = c[i];
rep(k, N) rep(i, N) rep(j, N) G[i][j] = max(G[i][j], G[i][k] + G[k][j]);
ll val = G[0][N - 1]
rep(k, N) rep(i, N) rep(j, N) G[i][j] = max(G[i][j], G[i][k] + G[k][j]);
if (val == G[0][N - 1])
cout << G[0][N - 1] << endl;
else
cout << "inf" << endl;
return 0;
}
| a.cc: In function 'int main()':
a.cc:6:22: error: expected ',' or ';' before 'for'
6 | #define REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
| ^~~
a.cc:7:19: note: in expansion of macro 'REP'
7 | #define rep(i, a) REP(i, 0, a)
| ^~~
a.cc:37:3: note: in expansion of macro 'rep'
37 | rep(k, N) rep(i, N) rep(j, N) G[i][j] = max(G[i][j], G[i][k] + G[k][j]);
| ^~~
a.cc:37:7: error: 'k' was not declared in this scope
37 | rep(k, N) rep(i, N) rep(j, N) G[i][j] = max(G[i][j], G[i][k] + G[k][j]);
| ^
a.cc:6:45: note: in definition of macro 'REP'
6 | #define REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
| ^
a.cc:37:3: note: in expansion of macro 'rep'
37 | rep(k, N) rep(i, N) rep(j, N) G[i][j] = max(G[i][j], G[i][k] + G[k][j]);
| ^~~
a.cc:37:17: error: 'i' was not declared in this scope
37 | rep(k, N) rep(i, N) rep(j, N) G[i][j] = max(G[i][j], G[i][k] + G[k][j]);
| ^
a.cc:6:45: note: in definition of macro 'REP'
6 | #define REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
| ^
a.cc:37:13: note: in expansion of macro 'rep'
37 | rep(k, N) rep(i, N) rep(j, N) G[i][j] = max(G[i][j], G[i][k] + G[k][j]);
| ^~~
a.cc:37:27: error: 'j' was not declared in this scope; did you mean 'jn'?
37 | rep(k, N) rep(i, N) rep(j, N) G[i][j] = max(G[i][j], G[i][k] + G[k][j]);
| ^
a.cc:6:45: note: in definition of macro 'REP'
6 | #define REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
| ^
a.cc:37:23: note: in expansion of macro 'rep'
37 | rep(k, N) rep(i, N) rep(j, N) G[i][j] = max(G[i][j], G[i][k] + G[k][j]);
| ^~~
|
s052172928 | p03722 | C++ | #include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <limits.h>
#include <map>
#include <algorithm>
#include <functional>
using namespace std;
struct edge { int from, to, cost; };
int main() {
int N, M;
long long d[1001];
bool done[1001];
cin >> N;
cin >> M;
edge es[2000];
for ( int i = 0; i < M; i++ ) {
int a,b;
long long c;
cin >> a;
cin >> b;
cin >> c;
es[i].from = a;
es[i].to = b;
es[i].cost = c;
}
for ( int i = 0; i <= N; i++ ) {
d[i] = LLONG_MIN;
done[i] = false;
}
d[1] = 0;
for ( int i = 0; i < N; i++ ) {
for ( int j = 0; j < M; j++ ) {
edge e = es[j];
if ( done[from] || e.from == 1 ) {
if ( !done[e.to] ) {
done[e.to] = true;
d[e.to] = d[e.from] + e.cost;
}
else if ( d[e.to] < d[e.from] + e.cost ) {
d[e.to] = d[e.from] + e.cost;
if ( i == N-1 ) {
cout << "inf" << endl;
return 0;
}
}
}
}
}
cout << d[N] << endl;
return 0;
} | a.cc: In function 'int main()':
a.cc:53:23: error: 'from' was not declared in this scope; did you mean 'fromfp'?
53 | if ( done[from] || e.from == 1 ) {
| ^~~~
| fromfp
|
s976897908 | p03722 | C++ |
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include<math.h>
#define rep(i,a) for(int i=0;i<a;i++)
#define nrep(i,a,b) for(int i=a;i<b;i++)
#define mrep(i,a) for(int i=a;i>=0;i--)
#define ll long long
#define vl vector<ll>
#define vvl vector<vector<ll> >
#define vb vector<bool>
#define vvb vector<vector<bool> >
#define INF LLONG_MAX
using namespace std;
struct E{
ll from;
ll to;
ll cost;
};
ll ans,n,m;
vector<E> e;
vl dp;
bool bellman_ford(ll s){
dp[s] = 0;
rep(count, n) rep(i, m){
if (dp[e[i].from] + e[i].cost > dp[e[i].to]){
dp[e[i].to] = dp[e[i].from] + e[i].cost;
if (count == n - 1) return true;
}
}
return false;
}
int main(){
cin >> n >> m;
dp.resize(n, -INF);
e.resize(m);
rep(i, m){
ll a, b,c; cin >> a >> b >> c;
a--; b--;
e[i].from = a;
e[i].to = b;
e[i].cost = c;
}if (bellman_ford(0)) cout << "inf" << endl;
else cout << dp[n - 1] << endl;
return 0;
} | a.cc: In function 'int main()':
a.cc:15:13: error: 'LLONG_MAX' was not declared in this scope
15 | #define INF LLONG_MAX
| ^~~~~~~~~
a.cc:43:23: note: in expansion of macro 'INF'
43 | dp.resize(n, -INF);
| ^~~
a.cc:7:1: note: 'LLONG_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
6 | #include<math.h>
+++ |+#include <climits>
7 | #define rep(i,a) for(int i=0;i<a;i++)
|
s411417450 | p03722 | C++ | #include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <limits.h>
#include <map>
#include <algorithm>
#include <functional>
using namespace std;
struct edge { int from, to, cost; };
int main() {
int N, M;
long long d[1001];
bool done[1001];
cin >> N;
cin >> M;
edge es[2000];
for ( int i = 0; i < M; i++ ) {
int a,b;
long long c;
cin >> a;
cin >> b;
cin >> c;
es[i].from = a;
es[i].to = b;
es[i].cost = c;
}
for ( int i = 0; i <= N; i++ ) {
d[i] = LLONG_MIN;
done[i] = false;
}
d[1] = 0;
for ( int i = 0; i < N; i++ ) {
for ( int j = 0; j < M; j++ ) {
edge e = es[j];
if ( done[from] || e.forom == 1 ) {
if ( !done[e.to] ) {
done[e.to] = true;
d[e.to] = d[e.from] + e.cost;
}
else if ( d[e.to] < d[e.from] + e.cost ) {
d[e.to] = d[e.from] + e.cost;
if ( i == N-1 ) {
cout << "inf" << endl;
return 0;
}
}
}
}
}
cout << d[N] << endl;
return 0;
} | a.cc: In function 'int main()':
a.cc:53:23: error: 'from' was not declared in this scope; did you mean 'fromfp'?
53 | if ( done[from] || e.forom == 1 ) {
| ^~~~
| fromfp
a.cc:53:34: error: 'struct edge' has no member named 'forom'; did you mean 'from'?
53 | if ( done[from] || e.forom == 1 ) {
| ^~~~~
| from
|
s895956790 | p03722 | C++ |
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include<math.h>
#define rep(i,a) for(int i=0;i<a;i++)
#define nrep(i,a,b) for(int i=a;i<b;i++)
#define mrep(i,a) for(int i=a;i>=0;i--)
#define ll long long
#define vl vector<ll>
#define vvl vector<vector<ll> >
#define vb vector<bool>
#define vvb vector<vector<bool> >
#define INF LLONG_MAX
using namespace std;
struct E{
ll from;
ll to;
ll cost;
};
ll ans,n,m;
vector<E> e;
vl dp;
bool bellman_ford(ll s){
dp[s] = 0;
rep(count, n) rep(i, m){
if (dp[e[i].from] + e[i].cost > dp[e[i].to]){
dp[e[i].to] = dp[e[i].from] + e[i].cost;
if (count == n - 1) return true;
}
}
return false;
}
int main(){
cin >> n >> m;
dp.resize(n, -INF);
e.resize(m);
rep(i, m){
ll a, b,c; cin >> a >> b >> c;
a--; b--;
e[i].from = a;
e[i].to = b;
e[i].cost = c;
}if (bellman_ford(0)) cout << "inf" << endl;
else cout << dp[n - 1] << endl;
return 0;
} | a.cc: In function 'int main()':
a.cc:15:13: error: 'LLONG_MAX' was not declared in this scope
15 | #define INF LLONG_MAX
| ^~~~~~~~~
a.cc:43:23: note: in expansion of macro 'INF'
43 | dp.resize(n, -INF);
| ^~~
a.cc:7:1: note: 'LLONG_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
6 | #include<math.h>
+++ |+#include <climits>
7 | #define rep(i,a) for(int i=0;i<a;i++)
|
s482693280 | p03722 | C++ | #include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int n,m;
long long maxs[1010];
vector<pair<int,long long> > v[1010];
bool vis[1010],infs;
void DFS(int x,long long pnt){
if(pnt>2000000000000)return;
#include<algorithm>
#include<vector>
using namespace std;
int n,m;
long long maxs[1010];
vector<pair<int,long long> > v[1010];
bool vis[1010],infs;
void DFS(int x,long long pnt){
vis[x]=true;
for(int i=0;i<v[x].size();i++){
int f=v[x][i].first;
long long g=v[x][i].second;
if(maxs[f]<pnt+g){
maxs[f]=pnt+g;
DFS(f,maxs[f]);
}
}
vis[x]=false;
}
int main(){
cin>>n>>m;
for(int i=0;i<n;i++){
vis[i]=false;
maxs[i]=-2000000000000;
v[i].clear();
}
for(int i=0;i<m;i++){
int a,b;
long long c;
cin>>a>>b>>c;a--,b--;
v[a].push_back(make_pair(b,c));
}
infs=false;
DFS(0,0);
if(maxs[n-1]>2000000000000)cout<<"inf"<<endl;
else cout<<maxs[n-1]<<endl;
getchar();
getchar();
return 0;
}
vis[x]=true;
for(int i=0;i<v[x].size();i++){
int f=v[x][i].first;
long long g=v[x][i].second;
if(maxs[f]<pnt+g){
maxs[f]=pnt+g;
DFS(f,maxs[f]);
}
}
vis[x]=false;
}
int main(){
cin>>n>>m;
for(int i=0;i<n;i++){
vis[i]=false;
maxs[i]=-2000000000000;
v[i].clear();
}
for(int i=0;i<m;i++){
int a,b;
long long c;
cin>>a>>b>>c;a--,b--;
v[a].push_back(make_pair(b,c));
}
infs=false;
DFS(0,0);
if(maxs[n-1]>2000000000000)cout<<"inf"<<endl;
else cout<<maxs[n-1]<<endl;
return 0;
} | a.cc: In function 'void DFS(int, long long int)':
a.cc:22:30: error: a function-definition is not allowed here before '{' token
22 | void DFS(int x,long long pnt){
| ^
a.cc:36:9: warning: empty parentheses were disambiguated as a function declaration [-Wvexing-parse]
36 | int main(){
| ^~
a.cc:36:9: note: remove parentheses to default-initialize a variable
36 | int main(){
| ^~
| --
a.cc:36:9: note: or replace parentheses with braces to value-initialize a variable
a.cc:36:11: error: a function-definition is not allowed here before '{' token
36 | int main(){
| ^
|
s278539031 | p03722 | C++ | #include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int n,m;
long long maxs[1010];
vector<pair<int,long long> > v[1010];
bool vis[1010],infs;
void DFS(int x,long long pnt){
if(pnt>2000000000000)return;
#include<algorithm>
#include<vector>
using namespace std;
int n,m;
long long maxs[1010];
vector<pair<int,long long> > v[1010];
bool vis[1010],infs;
void DFS(int x,long long pnt){
vis[x]=true;
for(int i=0;i<v[x].size();i++){
int f=v[x][i].first;
long long g=v[x][i].second;
if(maxs[f]<pnt+g){
maxs[f]=pnt+g;
DFS(f,maxs[f]);
}
}
vis[x]=false;
}
int main(){
cin>>n>>m;
for(int i=0;i<n;i++){
vis[i]=false;
maxs[i]=-2000000000000;
v[i].clear();
}
for(int i=0;i<m;i++){
int a,b;
long long c;
cin>>a>>b>>c;a--,b--;
v[a].push_back(make_pair(b,c));
}
infs=false;
DFS(0,0);
if(maxs[n-1]>2000000000000)cout<<"inf"<<endl;
else cout<<maxs[n-1]<<endl;
getchar();
getchar();
return 0;
}
vis[x]=true;
for(int i=0;i<v[x].size();i++){
int f=v[x][i].first;
long long g=v[x][i].second;
if(maxs[f]<pnt+g){
maxs[f]=pnt+g;
DFS(f,maxs[f]);
}
}
vis[x]=false;
}
int main(){
cin>>n>>m;
for(int i=0;i<n;i++){
vis[i]=false;
maxs[i]=-2000000000000;
v[i].clear();
}
for(int i=0;i<m;i++){
int a,b;
long long c;
cin>>a>>b>>c;a--,b--;
v[a].push_back(make_pair(b,c));
}
infs=false;
DFS(0,0);
if(maxs[n-1]>2000000000000)cout<<"inf"<<endl;
else cout<<maxs[n-1]<<endl;
getchar();
getchar();
return 0;
} | a.cc: In function 'void DFS(int, long long int)':
a.cc:22:30: error: a function-definition is not allowed here before '{' token
22 | void DFS(int x,long long pnt){
| ^
a.cc:36:9: warning: empty parentheses were disambiguated as a function declaration [-Wvexing-parse]
36 | int main(){
| ^~
a.cc:36:9: note: remove parentheses to default-initialize a variable
36 | int main(){
| ^~
| --
a.cc:36:9: note: or replace parentheses with braces to value-initialize a variable
a.cc:36:11: error: a function-definition is not allowed here before '{' token
36 | int main(){
| ^
|
s586731296 | p03722 | C++ | #include <iostream>
#include <string>
#define REP(i,k,n) for(int(i)=(k);(i)<(n);++(i))
using namespace std;
const int N_MAX = 1050;
// minus infinity
const long MINF = -int(1e9)-50;
int N,M;
long A[N_MAX][N_MAX] = {};
// i: 今居る頂点
// s: iまでのスコア・コスト
long dfs(int i, long s)
{
if (i == N-1) return s;
/*
A[i]
;
REP(0,j,N) {
if (A[i])
*/
//
// 最高スコア
long m = MINF;
// どこも辿れる所がないかもしれない
REP(0,j,N) {
// 0 だと辿れない。探索打ち切り
if (A[i][j] != 0) {
int x = dfs(j, s + A[i][j]);
// update max
if (x > m) m = x;
}
}
return m;
}
int main()
{
cin >> N >> M;
REP(i,0,M) {
int a,b;
long c;
cin >> a >> b >> c;
--a; --b;
// 有向グラフ
A[i][j] = c;
}
long res = dfs(0,0);
cout << res << endl;
return 0;
}
| a.cc: In function 'long int dfs(int, long int)':
a.cc:27:9: error: 'j' was not declared in this scope
27 | REP(0,j,N) {
| ^
a.cc:3:32: note: in definition of macro 'REP'
3 | #define REP(i,k,n) for(int(i)=(k);(i)<(n);++(i))
| ^
a.cc:27:7: error: lvalue required as increment operand
27 | REP(0,j,N) {
| ^
a.cc:3:46: note: in definition of macro 'REP'
3 | #define REP(i,k,n) for(int(i)=(k);(i)<(n);++(i))
| ^
a.cc: In function 'int main()':
a.cc:48:10: error: 'j' was not declared in this scope
48 | A[i][j] = c;
| ^
|
s441895337 | p03722 | C++ | #include <iostream>
#include <iomanip>
#include <cmath>
#include <queue>
#include <map>
#include <cstdlib>
#include <algorithm>
#include <utility>
#include <queue>
#include <string>
#include <functional>
#define rep(i, a, b) for(int i=a;i<b;++i)
#define MOD 1000000007
#define RAND 1000
using namespace std;
int a[100000], b[100000], n, m;
long long int c[100000];
long long int maxy = LLONG_MIN;
void g(int start, int i, long long int score)
{
//cout << score << endl;
if (start == n) {
if (score > maxy)
maxy = score;
return;
}
for (int j = i; j < m; ++j)
if (a[j] == start) {
score += c[j];
g(b[j], j, score);
score = 0;
}
}
int main(void)
{
cin >> n >> m;
for (int i = 0; i < m; ++i) {
cin >> a[i] >> b[i] >> c[i];
}
g(1, 0, 0);
cout << maxy << endl;
//system("pause");
return 0;
} | a.cc:20:22: error: 'LLONG_MIN' was not declared in this scope
20 | long long int maxy = LLONG_MIN;
| ^~~~~~~~~
a.cc:12:1: note: 'LLONG_MIN' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
11 | #include <functional>
+++ |+#include <climits>
12 | #define rep(i, a, b) for(int i=a;i<b;++i)
|
s027380259 | p03722 | C++ | #include <iostream>
#include <vector>
using namespace std;
// 隣接リストで使う辺を表す型
struct Edge {
long long to, cost; // 辺の接続先頂点, 辺の重み
Edge(long long to, long long cost) : to(to), cost(cost) {} // コンストラクタ
};
typedef vector<vector<Edge> > AdjList; // 隣接リストの型
AdjList graph; // グラフの辺を格納した構造体
// graph[v][i]は頂点vから出るi番目の辺Edge
const long long INF = 2147483646000000;
vector<long long> dist; // 最短距離
// 戻り値がtrueなら負の閉路を含む
bool bellman_ford(long long n, long long s) { // nは頂点数、sは開始頂点
dist = vector<long long>(n, INF);
dist[s] = 0; // 開始点の距離は0
for (long long i = 0; i < n; i++) {
for (long long v = 0; v < n; v++) {
for (long long 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) return true; // n回目にも更新があるなら負の閉路が存在
cout << e.cost << endl;
}
}
}
}
return false;
}
int main() {
long long n, m;
cin >> n >> m;
graph = AdjList(n);
for (long long i = 0; i < m; i++) {
long long from, to, cost;
cin >> from >> to >> cost;
graph[from-1].push_back(Edge(to-1, -cost));
}
bool tf = bellman_ford(n, 0);
if (tf) {
cout << "inf" << endl;
}else{
-dist[n-1] << endl;
}
return 0;
}
| a.cc: In function 'int main()':
a.cc:54:16: error: invalid operands of types '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} and '<unresolved overloaded function type>' to binary 'operator<<'
54 | -dist[n-1] << endl;
| ~~~~~~~~~~~^~~~~~~
|
s186543236 | p03722 | C++ | #include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 3010, inf = 1e17;
int n, m, a, b, c, u, v, w, flag = 0, cnt;
vector <int> top;
vector < pair <int, int> > g[N];
int was[N], dp[N];
void dfs(int v) {
if (was[v]) return;
was[v] = 1;
for (auto i : g[v])
dfs(i.first);
top.push_back(v);
}
main() {
cin >> n >> m;
for (int i = 0; i < m; ++i) {
cin >> a >> b >> c;
g[b].push_back({a, c});
}
g[1].push_back({0, 0});
g[n + 1].push_back({n, 0});
for (int i = 0; i < n + 2; ++i) dfs(i);
fill(dp, dp + n + 3, -inf);
dp[0] = 0;
for (auto v : top) {
//cerr << v << ' ';
for (auto i : g[v]) {
u = i.first;
w = i.second;
dp[v] = max(dp[v], dp[u] + w);
}
}
for (int j = 0; j < 10500; ++j) {
flag = 0;
for (auto v : top) {
for (auto i : g[v]) {
u = i.first, w = i.second;
if (dp[u] + w > dp[v])
flag = 1;
dp[v] = max(dp[v], dp[u] + w);
}
}
reverse(top.begin(), top.end());
if (flag == 0) cnt++;
else cnt = 0
if (cnt > 100) break;
}
if (flag) cout << "inf\n";
else cout << dp[n + 1] << '\n';
return 0;
}
| a.cc:19:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
19 | main() {
| ^~~~
a.cc: In function 'int main()':
a.cc:51:17: error: expected ';' before 'if'
51 | else cnt = 0
| ^
| ;
52 | if (cnt > 100) break;
| ~~
|
s441135133 | p03722 | C++ | #include <iostream>
#include <algorithm>
#include <vector>
#include <memory>
using namespace std;
#define reps(i,s,n) for(int (i) = (s); (i) < (n); ++(i))
#define rep(i,n) reps(i,0,n)
using ll = long long;
struct edge{ll from,to,cost;};
edge es[1001],m_es[1001];
#define MAX_V 1001
ll d[MAX_V];
ll V,E;
#define INF 1930000000000000
#define MINF -1930000000000000
void longest_path(int s){
rep(i,V){
d[i] = MINF;
//d[i] = 0;
}
d[s] = 0;
while(true){
bool update = false;
rep(i,E){
edge e = es[i];
cout << d[e.to] << "|" << d[e.from] + e.cost << endl;
if(d[e.to] < d[e.from] + e.cost){//今考えている辺を経由した方が点数は高いか?
d[e.to] = d[e.from] + e.cost;
update = true;
}
}
if(!update) break;
}
}
//d[目的地]を出力
bool find_negative(){
memset(d,0,sizeof(d));
rep(i,V){
rep(j,E){
edge e = m_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;
ll a,b,c;
rep(i,E){//辺は0オリジン
cin >> a >> b >> c;
es[i].from = a;
es[i].to = b;
es[i].cost = c;
m_es[i].from = a;
m_es[i].to = b;
m_es[i].cost = -1*c;
}
if(find_negative()==true){
cout << "inf" << endl;
return 0;
}
longest_path(1);
cout << d[V] << endl;
return 0;
} | a.cc: In function 'bool find_negative()':
a.cc:40:5: error: 'memset' was not declared in this scope
40 | memset(d,0,sizeof(d));
| ^~~~~~
a.cc:5:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
4 | #include <memory>
+++ |+#include <cstring>
5 |
|
s264865623 | p03722 | C++ | #include <iostream>
#include <vector>
using namespace std;
// 隣接リストで使う辺を表す型
struct Edge {
long long int to, cost; // 辺の接続先頂点, 辺の重み
Edge(long long int to, long long int cost) : to(to), cost(cost) {} // コンストラクタ
};
typedef vector<vector<Edge> > AdjList; // 隣接リストの型
AdjList graph; // グラフの辺を格納した構造体
// graph[v][i]は頂点vから出るi番目の辺Edge
const long long int INF = 1000000000000000000;
vector<long long int> dist; // 最短距離
// 戻り値がtrueなら負の閉路を含む
bool bellman_ford(long long int n, long long int s) { // nは頂点数、sは開始頂点
dist = vector<long long int>(n, INF);
dist[s] = 0; // 開始点の距離は0
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) return true; // n回目にも更新があるなら負の閉路が存在
}
}
}
}
return false;
}
int main() {
long long int n, m;
cin >> n >> m;
graph = AdjList(n);
for (int i = 0; i < m; i++) {
long long int from, to, cost;
cin >> from >> to >> cost;
graph[from-1].push_back(Edge(to-1, -cost));
}
bellman_ford(n, 0);
long long int ans=INF;
for (int i = 1; i < n; i++) {
if (dist[i] != INF)
{if(ans>-dist[i])ans=-dist[i];
//cout << "0から" << i << "へのコスト: " << -dist[i] << endl;}
}
cout << "" << "" << ans << endl;
return 0;
}
| a.cc: In function 'int main()':
a.cc:59:2: error: expected '}' at end of input
59 | }
| ^
a.cc:37:12: note: to match this '{'
37 | int main() {
| ^
|
s274187525 | p03722 | C++ | #include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
#define reps(i,s,n) for(int (i) = (s); (i) < (n); ++(i))
#define rep(i,n) reps(i,0,n)
using ll = long long;
struct edge{int from,to,cost;};
edge es[1001],m_es[1001];
#define MAX_V 1001
int d[MAX_V];
int V,E;
#define INF 1930000000
#define MINF -1930000000
void longest_path(int s){
rep(i,V){
d[i] = MINF;
//d[i] = 0;
}
d[s] = 0;
while(true){
bool update = false;
rep(i,E){
edge e = es[i];
if(d[e.to] < d[e.from] + e.cost){//今考えている辺を経由した方が点数は高いか?
d[e.to] = d[e.from] + e.cost;
update = true;
}
}
if(!update) break;
}
}
//d[目的地]を出力
bool find_negative(){
memset(d,0,sizeof(d));
rep(i,V){
rep(j,E){
edge e = m_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;
int a,b,c;
rep(i,E){//辺は0オリジン
cin >> a >> b >> c;
es[i].from = a;
es[i].to = b;
es[i].cost = c;
m_es[i].from = a;
m_es[i].to = b;
m_es[i].cost = -1*c;
}
int score;
if(find_negative()==true){
cout << "inf" << endl;
return 0;
}
longest_path(1);
cout << d[V] << endl;
return 0;
} | a.cc: In function 'bool find_negative()':
a.cc:38:5: error: 'memset' was not declared in this scope
38 | memset(d,0,sizeof(d));
| ^~~~~~
a.cc:4:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
3 | #include <vector>
+++ |+#include <cstring>
4 |
|
s329405077 | p03722 | C++ | #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
using ll = long long int;
struct edge { ll from, to, cost;
edge(ll a,ll b,ll c) : from(a) , to(b) , cost(c){
}
};
edge es[2010];
ll d[1010];
ll V, E;
ll INF = 9223372036854775807;
bool bellman_ford(int s) {
for (int i = 0; i < V; i++) d[i] = INF;
d[s] = 0;
for (int i = 0; i <= V*V; i++) {
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) return false;
}
return true;
}
int main() {
cin >> V >> E;
for (ll i = 0; i < E; i++) {
ll a, b, c;
cin >> a >> b >> c;
a--; b--;
es[i] = edge(a,b,c);
}
if (bellman_ford(0)) {
cout << "inf" << endl;
}
else {
cout << -1LL*d[V - 1] << endl;
}
}
| a.cc:17:13: error: no matching function for call to 'edge::edge()'
17 | edge es[2010];
| ^
a.cc:12:1: note: candidate: 'edge::edge(ll, ll, ll)'
12 | edge(ll a,ll b,ll c) : from(a) , to(b) , cost(c){
| ^~~~
a.cc:12:1: note: candidate expects 3 arguments, 0 provided
a.cc:11:8: note: candidate: 'constexpr edge::edge(const edge&)'
11 | struct edge { ll from, to, cost;
| ^~~~
a.cc:11:8: note: candidate expects 1 argument, 0 provided
a.cc:11:8: note: candidate: 'constexpr edge::edge(edge&&)'
a.cc:11:8: note: candidate expects 1 argument, 0 provided
|
s633635679 | p03722 | Java | import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
int M = sc.nextInt();
long[] d = new long[N];
boolean flg = false;
long ans = 0;
ArrayList<Edge> edge = new ArrayList<Edge>();
for(int i = 0; i < M; i++) {
int a = sc.nextInt() - 1;
int b = sc.nextInt() - 1;
long s = (-1) * sc.nextLong();
edge.add(new Edge(a, b, s));
}
// ベルマンフォード
for(int i = 0; i < N; i++) {
for(int j = 0; j < edge.size(); j++) {
Edge e = edge.get(j);
if(d[e.to] > d[e.from] + e.score) {
d[e.to] = d[e.from] + e.score;
if(i == N - 1) flg = true;
}
}
}
if(flg) {
System.out.println("inf");
} else {
// ベルマンフォード
for(int i = 0; i < N; i++) {
d[i] = (long)Math.pow(10, 15);
}
d[0] = 0;
while(true) {
boolean update = false;
for(int i = 0; i < edge.size(); i++) {
Edge e = edge.get(i);
if(d[e.from] != (long)Math.pow(10, 15) && d[e.to] > d[e.from] + e.score) {
d[e.to] = d[e.from] + e.score;
update = true;
}
}
if(!update) break;
}
System.out.println("inf");
}
}
} | Main.java:11: error: cannot find symbol
ArrayList<Edge> edge = new ArrayList<Edge>();
^
symbol: class Edge
location: class Main
Main.java:11: error: cannot find symbol
ArrayList<Edge> edge = new ArrayList<Edge>();
^
symbol: class Edge
location: class Main
Main.java:16: error: cannot find symbol
edge.add(new Edge(a, b, s));
^
symbol: class Edge
location: class Main
Main.java:21: error: cannot find symbol
Edge e = edge.get(j);
^
symbol: class Edge
location: class Main
Main.java:39: error: cannot find symbol
Edge e = edge.get(i);
^
symbol: class Edge
location: class Main
5 errors
|
s353761020 | p03722 | C++ | #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;
#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = (1LL << 31) - 1;
const ll MOD = 1e9 + 7;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1
#define MAX_N 2010
int n, m;
struct edge {
int to;
ll cost;
};
vector<edge> G[100100];
ll d[100100];
ll cnt[100100];
ll cost[1010][1010];
bool f[1010];
void check(int s, int now) {
if (f[now])return;
f[now] = true;
REP(i, G[now].size()) {
int to = G[now][i].to;
cost[s][to] = max(cost[s][now] + G[now][i].cost, cost[s][to]);
check(s, to);
}
}
void solve(int now,ll cost) {
d[now] = cost;
REP(i, G[now].size()) {
int to = G[now][i].to;
ll ncost = d[now] + G[now][i].cost;
if (d[to] < ncost)solve(to, ncost);
}
}
int main() {
fill(d, d + 100100, LLONG_MIN);
cin >> n >> m;
REP(i, m) {
int a, b, c;
cin >> a >> b >> c;
a--; b--;
G[a].push_back({ b,c });
}
REP(i, n)REP(j, n)cost[i][j] = -1;
REP(i, n) {
fill(f, f + 1010, false);
cost[i][i] = 0;
check(i, i);
}
bool ok = true;
REP(i, n) {
FOR(j, i + 1, n) {
if (cost[i][j] != -1 && cost[j][i] != -1) {
if (cost[i][j] + cost[j][i] > 0)ok = false;
}
}
}
if (!ok)cout << "inf" << endl;
else {
solve(0, 0);
cout << d[n - 1] << endl;
}
} | a.cc: In function 'int main()':
a.cc:79:29: error: 'LLONG_MIN' was not declared in this scope
79 | fill(d, d + 100100, LLONG_MIN);
| ^~~~~~~~~
a.cc:18:1: note: 'LLONG_MIN' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
17 | #include <bitset>
+++ |+#include <climits>
18 | #include <time.h>
|
s459422577 | p03722 | C++ | # include <iostream>
# include <sstream>
# include <cstdio>
# include <cstdlib>
# include <algorithm>
# include <string>
# include <cstring>
# include <cmath>
# include <stack>
# include <queue>
# include <vector>
# include <list>
# include <map>
# include <set>
# include <deque>
# include <iterator>
# include <functional>
# include <bitset>
# include <climits>
# include <ctime>
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define odd(x) (x&1)
typedef long long ll;
typedef long double ld;
const ll oo = /*2 * 1000 * 1000 * 1000*/0x3f3f3f3f;
const int _cnt = 1000 * 1000;
const int _p = 1000 * 1000 * 1000 + 7;
ll o(ll x) { return x%_p; }
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
//ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
int lcm(int a, int b) { return a / gcd(a, b)*b; }
using namespace std;
void file_put() {
freopen("filename.in", "r", stdin);
freopen("filename.out", "w", stdout);
}
const int N = 80;
class BigNumber {
private:
int x[N], sgn = 0;
public:
void shrink();
BigNumber();
BigNumber(const int &sgn, const int len);
BigNumber(const int &t);
BigNumber(const BigNumber & B);
BigNumber(const string & s);
void print(int num = 0) const;
void swap(BigNumber &B);
int size() const;
BigNumber &operator=(const BigNumber &B);
BigNumber &operator=(const int &A);
BigNumber &operator=(const string & A);
friend ostream &operator<<(ostream & output, BigNumber & B);
friend istream &operator >> (istream & input, BigNumber & B);
BigNumber operator+() const;
BigNumber operator-() const;
friend int compare(const BigNumber & A, const BigNumber & B);
friend bool operator>(const BigNumber &A, const BigNumber &B);
friend bool operator>=(const BigNumber &A, const BigNumber &B);
friend bool operator<(const BigNumber &A, const BigNumber &B);
friend bool operator<=(const BigNumber &A, const BigNumber &B);
friend bool operator==(const BigNumber &A, const BigNumber &B);
friend bool operator!=(const BigNumber &A, const BigNumber &B);
friend bool operator>(const BigNumber &A, const int &B);
friend bool operator>=(const BigNumber &A, const int &B);
friend bool operator<(const BigNumber &A, const int &B);
friend bool operator<=(const BigNumber &A, const int &B);
friend bool operator==(const BigNumber &A, const int &B);
friend bool operator!=(const BigNumber &A, const int &B);
friend bool operator>(const int &A, const BigNumber &B);
friend bool operator>=(const int &A, const BigNumber &B);
friend bool operator<(const int &A, const BigNumber &B);
friend bool operator<=(const int &A, const BigNumber &B);
friend bool operator==(const int &A, const BigNumber &B);
friend bool operator!=(const int &A, const BigNumber &B);
bool operator!() const;
friend BigNumber abs(const BigNumber &B);
friend BigNumber operator + (const BigNumber &A, const BigNumber &B);
friend BigNumber operator - (const BigNumber &A, const BigNumber &B);
friend BigNumber operator * (const BigNumber &A, const BigNumber &B);
friend BigNumber operator + (const BigNumber &A, const int &B);
friend BigNumber operator - (const BigNumber &A, const int &B);
friend BigNumber operator * (const BigNumber &A, const int &B);
friend BigNumber operator + (const int &A, const BigNumber &B);
friend BigNumber operator - (const int &A, const BigNumber &B);
friend BigNumber operator * (const int &A, const BigNumber &B);
BigNumber& operator +=(const BigNumber &A);
BigNumber& operator -=(const BigNumber &A);
BigNumber& operator *=(const BigNumber &A);
BigNumber& operator +=(const int &A);
BigNumber& operator -=(const int &A);
BigNumber& operator *=(const int &A);
BigNumber& operator ++();
BigNumber operator ++(int);
BigNumber& operator --();
BigNumber operator --(int);
};
void BigNumber::shrink() {
while (x[0] && !x[x[0]]) x[0]--;
if (!x[0]) {
this->x[0] = 1;
this->sgn = 0;
}
}
BigNumber::BigNumber() {
sgn = 0;
memset(x, 0, sizeof(x));
x[0] = 1;
}
BigNumber::BigNumber(const int &sgn, const int len) {
this->sgn = sgn;
memset(x, 0, sizeof(x));
x[0] = len;
}
BigNumber::BigNumber(const int &t) {
int n = t;
if (n > 0) sgn = 1; else
if (n < 0) sgn = -1; else
sgn = 0;
n = abs(n);
memset(x, 0, sizeof(x));
if (!n) {
this->x[0] = 1;
return;
}
while (n) {
x[++x[0]] = n % 10;
n /= 10;
}
this->shrink();
}
BigNumber::BigNumber(const BigNumber & B) {
this->sgn = B.sgn;
memset(this->x, 0, sizeof(this->x));
for (int i = 0; i <= B.x[0]; i++) this->x[i] = B.x[i];
this->shrink();
}
BigNumber::BigNumber(const string & s) {
string st = s;
if (st[0] == '-') {
this->sgn = -1;
st.erase(st.begin());
}
else
this->sgn = 1;
memset(this->x, 0, sizeof(this->x));
for (int i = st.length() - 1; i >= 0; i--) this->x[++x[0]] = st[i] - '0';
if (this->x[0] == 1 && this->x[1] == 0) this->sgn = 0;
//this->shrink();
}
void BigNumber::print(int num) const {
if (this->sgn == -1 && this->x[x[0]] != 0) printf("-");
if (num && this->sgn == 1 && this->x[x[0]] != 0) printf("+");
BigNumber B = *this;
B.shrink();
for (int i = B.x[0]; i >= 1; i--) printf("%d", B.x[i]);
}
void BigNumber::swap(BigNumber &B) {
std::swap(*this, B);
}
int BigNumber::size() const { return this->x[0]; }
BigNumber & BigNumber ::operator=(const BigNumber &B) {
this->sgn = B.sgn;
memset(this->x, 0, sizeof(this->x));
for (int i = 0; i <= B.x[0]; i++) this->x[i] = B.x[i];
return *this;
}
BigNumber & BigNumber ::operator=(const int &A) {
BigNumber B = A;
this->sgn = B.sgn;
memset(this->x, 0, sizeof(this->x));
for (int i = 0; i <= B.x[0]; i++) this->x[i] = B.x[i];
return *this;
}
BigNumber & BigNumber ::operator=(const string &A) {
BigNumber B = A;
this->sgn = B.sgn;
memset(this->x, 0, sizeof(this->x));
for (int i = 0; i <= B.x[0]; i++) this->x[i] = B.x[i];
return *this;
}
ostream &operator<<(ostream & output, BigNumber & B) {
B.shrink();
if (B.sgn == -1) output << '-';
for (int i = B.x[0]; i >= 1; i--) output << B.x[i];
return output;
}
istream &operator >> (istream & input, BigNumber & B) {
string st;
input >> st;
B = BigNumber(st);
return input;
}
BigNumber BigNumber ::operator+() const {
return *this;
}
BigNumber BigNumber ::operator-() const {
BigNumber t = *this;
t.sgn = -t.sgn;
return t;
}
int compare(const BigNumber & A, const BigNumber & B) {
if (A.sgn > B.sgn) return 1;
if (A.sgn < B.sgn) return -1;
if (A.x[0] > B.x[0]) return A.sgn;
if (A.x[0] < B.x[0]) return -A.sgn;
for (int i = A.x[0]; i >= 1; i--) {
if (A.x[i] > B.x[i]) return A.sgn;
if (A.x[i] < B.x[i]) return -A.sgn;
}
return 0;
}
bool operator>(const BigNumber &A, const BigNumber &B) {
return compare(A, B) == 1;
}
bool operator>=(const BigNumber &A, const BigNumber &B) {
return compare(A, B) != -1;
}
bool operator<(const BigNumber &A, const BigNumber &B) {
return compare(A, B) == -1;
}
bool operator<=(const BigNumber &A, const BigNumber &B) {
return compare(A, B) != 1;
}
bool operator==(const BigNumber &A, const BigNumber &B) {
return compare(A, B) == 0;
}
bool operator!=(const BigNumber &A, const BigNumber &B) {
return compare(A, B) != 0;
}
bool operator>(const BigNumber &A, const int &B) {
return compare(A, B) == 1;
}
bool operator>=(const BigNumber &A, const int &B) {
return compare(A, B) != -1;
}
bool operator<(const BigNumber &A, const int &B) {
return compare(A, B) == -1;
}
bool operator<=(const BigNumber &A, const int &B) {
return compare(A, B) != 1;
}
bool operator==(const BigNumber &A, const int &B) {
return compare(A, B) == 0;
}
bool operator!=(const BigNumber &A, const int &B) {
return compare(A, B) != 0;
}
bool operator>(const int &A, const BigNumber &B) {
return compare(A, B) == 1;
}
bool operator>=(const int &A, const BigNumber &B) {
return compare(A, B) != -1;
}
bool operator<(const int &A, const BigNumber &B) {
return compare(A, B) == -1;
}
bool operator<=(const int &A, const BigNumber &B) {
return compare(A, B) != 1;
}
bool operator==(const int &A, const BigNumber &B) {
return compare(A, B) == 0;
}
bool operator!=(const int &A, const BigNumber &B) {
return compare(A, B) != 0;
}
bool BigNumber ::operator!() const { return *this == 0; }
BigNumber abs(const BigNumber &B) { return (B >= 0) ? (+B) : (-B); }
BigNumber operator + (const BigNumber &A, const BigNumber &B) {
if (!A) return B;
if (!B) return A;
if (A.sgn == B.sgn) {
BigNumber C(A.sgn, max(A.x[0], B.x[0]));
for (int i = 1; i <= C.x[0]; i++) C.x[i] = A.x[i] + B.x[i];
for (int i = 1; i <= C.x[0]; i++) C.x[i + 1] += C.x[i] / 10, C.x[i] %= 10;
C.x[0] += (C.x[C.x[0] + 1] > 0);
return C;
}
if (A < 0) return B - (-A); else return A - (-B);
}
BigNumber operator - (const BigNumber &A, const BigNumber &B) {
if (!A) return -B;
if (!B) return A;
if (A < 0) return -(-A + B);
if (B < 0) return A + (-B);
if (A < B) return -(B - A);
BigNumber C(1, A.x[0]);
for (int i = 1; i <= C.x[0]; i++) C.x[i] = A.x[i] - B.x[i];
for (int i = 1; i <= C.x[0]; i++) {
C.x[i + 1] -= (C.x[i] < 0);
C.x[i] += (C.x[i] < 0) * 10;
}
while (C.x[0] > 1 && !C.x[C.x[0]]) C.x[0]--;
C.sgn = !(C.x[0] == 1 && !C.x[1]);
return C;
}
BigNumber operator * (const BigNumber &A, const BigNumber &B) {
if (!A || !B) return 0;
BigNumber C(A.sgn*B.sgn, A.x[0] + B.x[0] - 1);
for (int i = 1; i <= A.x[0]; i++)
for (int j = 1; j <= B.x[0]; j++)
C.x[i + j - 1] += A.x[i] * B.x[j];
for (int i = 1; i <= C.x[0]; i++) C.x[i + 1] += C.x[i] / 10, C.x[i] %= 10;
while (C.x[C.x[0] + 1]) {
C.x[0]++;
C.x[C.x[0] + 1] += C.x[C.x[0]] / 10;
C.x[C.x[0]] %= 10;
}
return C;
}
BigNumber operator + (const BigNumber &A, const int &B) { return A + BigNumber(B); }
BigNumber operator - (const BigNumber &A, const int &B) { return A - BigNumber(B); }
BigNumber operator * (const BigNumber &A, const int &B) { return A * BigNumber(B); }
BigNumber operator + (const int &A, const BigNumber &B) { return BigNumber(A) + B; }
BigNumber operator - (const int &A, const BigNumber &B) { return BigNumber(A) - B; }
BigNumber operator * (const int &A, const BigNumber &B) { return BigNumber(A) * B; }
BigNumber& BigNumber ::operator +=(const BigNumber &A) { return *this = *this + A; }
BigNumber& BigNumber ::operator -=(const BigNumber &A) { return *this = *this - A; }
BigNumber& BigNumber ::operator *=(const BigNumber &A) { return *this = *this * A; }
BigNumber& BigNumber ::operator +=(const int &A) { return *this = *this + A; }
BigNumber& BigNumber ::operator -=(const int &A) { return *this = *this - A; }
BigNumber& BigNumber ::operator *=(const int &A) { return *this = *this * A; }
BigNumber& BigNumber ::operator ++() { return *this += 1; }
BigNumber BigNumber ::operator ++(int) { return *this += 1; }
BigNumber& BigNumber ::operator --() { return *this -= 1; }
BigNumber BigNumber ::operator --(int) { return *this -= 1; }
const int MAXN = 200005;
const ll INF = 9223372036854775807;
struct Edge {
int v;
int cost;
Edge(int _v = 0, int _cost = 0) :v(_v), cost(_cost) {}
};
vector<Edge>E[MAXN];
void addedge(int u, int v, int w) {
E[u].push_back(Edge(v, w));
}
bool vis[MAXN];
int cnt[MAXN];
BigNumber dist[MAXN];
bool SPFA(int start, int n) {
memset(vis, false, sizeof(vis));
for (int i = 1; i <= n; i++)dist[i] = "92233720368547758079225807";
vis[start] = true;
dist[start] = 0;
queue<int>que;
while (!que.empty())que.pop();
que.push(start);
memset(cnt, 0, sizeof(cnt));
cnt[start] = 1;
while (!que.empty()) {
int u = que.front();
que.pop();
vis[u] = false;
for (int i = 0; i<E[u].size(); i++) {
int v = E[u][i].v;
if (dist[v]>dist[u] + E[u][i].cost) {
dist[v] = dist[u] + E[u][i].cost;
if (!vis[v]) {
vis[v] = true;
que.push(v);
if (++cnt[v]>n)return false;
}
}
}
}
return true;
}
int n, m, a, b, c;
int main() {
//file_put();
scanf("%d%d", &n, &m);
for (int i = 1; i <= m; i++) {
scanf("%d%d%d", &a, &b, &c);
addedge(a, b, -c);
}
if (!SPFA(1, n)) printf("inf\n"); else cout << (-dist[n]);
return 0;
}
| a.cc: In function 'int main()':
a.cc:504:53: error: no match for 'operator<<' (operand types are 'std::ostream' {aka 'std::basic_ostream<char>'} and 'BigNumber')
504 | if (!SPFA(1, n)) printf("inf\n"); else cout << (-dist[n]);
| ~~~~ ^~ ~~~~~~~~~~
| | |
| | BigNumber
| std::ostream {aka std::basic_ostream<char>}
a.cc:260:10: note: candidate: 'std::ostream& operator<<(std::ostream&, BigNumber&)' (near match)
260 | ostream &operator<<(ostream & output, BigNumber & B) {
| ^~~~~~~~
a.cc:260:10: note: conversion of argument 2 would be ill-formed:
a.cc:504:57: error: cannot bind non-const lvalue reference of type 'BigNumber&' to an rvalue of type 'BigNumber'
504 | if (!SPFA(1, n)) printf("inf\n"); else cout << (-dist[n]);
| ~^~~~~~~~~
In file included from /usr/include/c++/14/iostream:41,
from a.cc:1:
/usr/include/c++/14/ostream:116:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(__ostream_type& (*)(__ostream_type&)) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
116 | operator<<(__ostream_type& (*__pf)(__ostream_type&))
| ^~~~~~~~
/usr/include/c++/14/ostream:116:36: note: no known conversion for argument 1 from 'BigNumber' to 'std::basic_ostream<char>::__ostream_type& (*)(std::basic_ostream<char>::__ostream_type&)' {aka 'std::basic_ostream<char>& (*)(std::basic_ostream<char>&)'}
116 | operator<<(__ostream_type& (*__pf)(__ostream_type&))
| ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/ostream:125:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(__ios_type& (*)(__ios_type&)) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>; __ios_type = std::basic_ios<char>]'
125 | operator<<(__ios_type& (*__pf)(__ios_type&))
| ^~~~~~~~
/usr/include/c++/14/ostream:125:32: note: no known conversion for argument 1 from 'BigNumber' to 'std::basic_ostream<char>::__ios_type& (*)(std::basic_ostream<char>::__ios_type&)' {aka 'std::basic_ios<char>& (*)(std::basic_ios<char>&)'}
125 | operator<<(__ios_type& (*__pf)(__ios_type&))
| ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
/usr/include/c++/14/ostream:135:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(std::ios_base& (*)(std::ios_base&)) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
135 | operator<<(ios_base& (*__pf) (ios_base&))
| ^~~~~~~~
/usr/include/c++/14/ostream:135:30: note: no known conversion for argument 1 from 'BigNumber' to 'std::ios_base& (*)(std::ios_base&)'
135 | operator<<(ios_base& (*__pf) (ios_base&))
| ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
/usr/include/c++/14/ostream:174:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long int) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
174 | operator<<(long __n)
| ^~~~~~~~
/usr/include/c++/14/ostream:174:23: note: no known conversion for argument 1 from 'BigNumber' to 'long int'
174 | operator<<(long __n)
| ~~~~~^~~
/usr/include/c++/14/ostream:178:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long unsigned int) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
178 | operator<<(unsigned long __n)
| ^~~~~~~~
/usr/include/c++/14/ostream:178:32: note: no known conversion for argument 1 from 'BigNumber' to 'long unsigned int'
178 | operator<<(unsigned long __n)
| ~~~~~~~~~~~~~~^~~
/usr/include/c++/14/ostream:182:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(bool) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
182 | operator<<(bool __n)
| ^~~~~~~~
/usr/include/c++/14/ostream:182:23: note: no known conversion for argument 1 from 'BigNumber' to 'bool'
182 | operator<<(bool __n)
| ~~~~~^~~
In file included from /usr/include/c++/14/ostream:1022:
/usr/include/c++/14/bits/ostream.tcc:96:5: note: candidate: 'std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(short int) [with _CharT = char; _Traits = std::char_traits<char>]'
96 | basic_ostream<_CharT, _Traits>::
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/ostream.tcc:97:22: note: no known conversion for argument 1 from 'BigNumber' to 'short int'
97 | operator<<(short __n)
| ~~~~~~^~~
/usr/include/c++/14/ostream:189:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(short unsigned int) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
189 | operator<<(unsigned short __n)
| ^~~~~~~~
/usr/include/c++/14/ostream:189:33: note: no known conversion for argument 1 from 'BigNumber' to 'short unsigned int'
189 | operator<<(unsigned short __n)
| ~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/ostream.tcc:110:5: note: candidate: 'std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(int) [with _CharT = char; _Traits = std::char_traits<char>]'
110 | basic_ostream<_CharT, _Traits>::
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/ostream.tcc:111:20: note: no known conversion for argument 1 from 'BigNumber' to 'int'
111 | operator<<(int __n)
| ~~~~^~~
/usr/include/c++/14/ostream:200:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(unsigned int) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
200 | operator<<(unsigned int __n)
| ^~~~~~~~
/usr/include/c++/14/ostream:200:31: note: no known conversion for argument 1 from 'BigNumber' to 'unsigned int'
200 | operator<<(unsigned int __n)
| ~~~~~~~~~~~~~^~~
/usr/include/c++/14/ostream:211:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long long int) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
211 | operator<<(long long __n)
| ^~~~~~~~
/usr/include/c++/14/ostream:211:28: note: no known conversion for argument 1 from 'BigNumber' to 'long long int'
211 | operator<<(long long __n)
| ~~~~~~~~~~^~~
/usr/include/c++/14/ostream:215:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long long unsigned int) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
215 | operator<<(unsigned long long __n)
| ^~~~~~~~
/usr/include/c++/14/ostream:215:37: note: no known conversion for argument 1 from 'BigNumber' to 'long long unsigned int'
215 | operator<<(unsigned long long __n)
| ~~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/ostream:231:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(double) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
231 | operator<<(double __f)
| ^~~~~~~~
/usr/include/c++/14/ostream:231:25: note: no known conversion for argument 1 from 'BigNumber' to 'double'
231 | operator<<(double __f)
| ~~~~~~~^~~
/usr/include/c++/14/ostream:235:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(float) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
235 | operator<<(float __f)
| ^~~~~~~~
/usr/include/c++/14/ostream:235:24: note: no known conversion for argument 1 from 'BigNumber' to 'float'
235 | operator<<(float __f)
| ~~~~~~^~~
/usr/include/c++/14/ostream:243:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long double) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
243 | operator<<(long double __f)
| ^~~~~~~~
/usr/include/c++/14/ostream:243:30: note: no known conversion for argument 1 from 'BigNumber' to 'long double'
243 | operator<<(long double __f)
| ~~~~~~~~~~~~^~~
/usr/include/c++/14/ostream:301:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(const void*) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
301 | operator<<(const void* __p)
| ^~~~~~~~
/usr/include/c++/14/ostream:301:30: note: no known conversion for argument 1 from 'BigNumber' to 'const void*'
301 | operator<<(const void* __p)
| ~~~~~~~~~~~~^~~
/usr/include/c++/14/ostream:306:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(std::nullptr_t |
s874584138 | p03722 | C++ | # include <iostream>
# include <sstream>
# include <cstdio>
# include <cstdlib>
# include <algorithm>
# include <string>
# include <cstring>
# include <cmath>
# include <stack>
# include <queue>
# include <vector>
# include <list>
# include <map>
# include <set>
# include <deque>
# include <iterator>
# include <functional>
# include <bitset>
# include <climits>
# include <ctime>
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define odd(x) (x&1)
typedef long long ll;
typedef long double ld;
const ll oo = /*2 * 1000 * 1000 * 1000*/0x3f3f3f3f;
const int _cnt = 1000 * 1000;
const int _p = 1000 * 1000 * 1000 + 7;
ll o(ll x) { return x%_p; }
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
//ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
int lcm(int a, int b) { return a / gcd(a, b)*b; }
using namespace std;
void file_put() {
freopen("filename.in", "r", stdin);
freopen("filename.out", "w", stdout);
}
const int N = 80;
class BigNumber {
private:
int x[N], sgn = 0;
public:
void shrink();
BigNumber();
BigNumber(const int &sgn, const int len);
BigNumber(const int &t);
BigNumber(const BigNumber & B);
BigNumber(const string & s);
void print(int num = 0) const;
void swap(BigNumber &B);
int size() const;
BigNumber &operator=(const BigNumber &B);
BigNumber &operator=(const int &A);
BigNumber &operator=(const string & A);
friend ostream &operator<<(ostream & output, BigNumber & B);
friend istream &operator >> (istream & input, BigNumber & B);
BigNumber operator+() const;
BigNumber operator-() const;
friend int compare(const BigNumber & A, const BigNumber & B);
friend bool operator>(const BigNumber &A, const BigNumber &B);
friend bool operator>=(const BigNumber &A, const BigNumber &B);
friend bool operator<(const BigNumber &A, const BigNumber &B);
friend bool operator<=(const BigNumber &A, const BigNumber &B);
friend bool operator==(const BigNumber &A, const BigNumber &B);
friend bool operator!=(const BigNumber &A, const BigNumber &B);
friend bool operator>(const BigNumber &A, const int &B);
friend bool operator>=(const BigNumber &A, const int &B);
friend bool operator<(const BigNumber &A, const int &B);
friend bool operator<=(const BigNumber &A, const int &B);
friend bool operator==(const BigNumber &A, const int &B);
friend bool operator!=(const BigNumber &A, const int &B);
friend bool operator>(const int &A, const BigNumber &B);
friend bool operator>=(const int &A, const BigNumber &B);
friend bool operator<(const int &A, const BigNumber &B);
friend bool operator<=(const int &A, const BigNumber &B);
friend bool operator==(const int &A, const BigNumber &B);
friend bool operator!=(const int &A, const BigNumber &B);
bool operator!() const;
friend BigNumber abs(const BigNumber &B);
friend BigNumber operator + (const BigNumber &A, const BigNumber &B);
friend BigNumber operator - (const BigNumber &A, const BigNumber &B);
friend BigNumber operator * (const BigNumber &A, const BigNumber &B);
friend BigNumber operator + (const BigNumber &A, const int &B);
friend BigNumber operator - (const BigNumber &A, const int &B);
friend BigNumber operator * (const BigNumber &A, const int &B);
friend BigNumber operator + (const int &A, const BigNumber &B);
friend BigNumber operator - (const int &A, const BigNumber &B);
friend BigNumber operator * (const int &A, const BigNumber &B);
BigNumber& operator +=(const BigNumber &A);
BigNumber& operator -=(const BigNumber &A);
BigNumber& operator *=(const BigNumber &A);
BigNumber& operator +=(const int &A);
BigNumber& operator -=(const int &A);
BigNumber& operator *=(const int &A);
BigNumber& operator ++();
BigNumber operator ++(int);
BigNumber& operator --();
BigNumber operator --(int);
};
void BigNumber::shrink() {
while (x[0] && !x[x[0]]) x[0]--;
if (!x[0]) {
this->x[0] = 1;
this->sgn = 0;
}
}
BigNumber::BigNumber() {
sgn = 0;
memset(x, 0, sizeof(x));
x[0] = 1;
}
BigNumber::BigNumber(const int &sgn, const int len) {
this->sgn = sgn;
memset(x, 0, sizeof(x));
x[0] = len;
}
BigNumber::BigNumber(const int &t) {
int n = t;
if (n > 0) sgn = 1; else
if (n < 0) sgn = -1; else
sgn = 0;
n = abs(n);
memset(x, 0, sizeof(x));
if (!n) {
this->x[0] = 1;
return;
}
while (n) {
x[++x[0]] = n % 10;
n /= 10;
}
this->shrink();
}
BigNumber::BigNumber(const BigNumber & B) {
this->sgn = B.sgn;
memset(this->x, 0, sizeof(this->x));
for (int i = 0; i <= B.x[0]; i++) this->x[i] = B.x[i];
this->shrink();
}
BigNumber::BigNumber(const string & s) {
string st = s;
if (st[0] == '-') {
this->sgn = -1;
st.erase(st.begin());
}
else
this->sgn = 1;
memset(this->x, 0, sizeof(this->x));
for (int i = st.length() - 1; i >= 0; i--) this->x[++x[0]] = st[i] - '0';
if (this->x[0] == 1 && this->x[1] == 0) this->sgn = 0;
//this->shrink();
}
void BigNumber::print(int num) const {
if (this->sgn == -1 && this->x[x[0]] != 0) printf("-");
if (num && this->sgn == 1 && this->x[x[0]] != 0) printf("+");
BigNumber B = *this;
B.shrink();
for (int i = B.x[0]; i >= 1; i--) printf("%d", B.x[i]);
}
void BigNumber::swap(BigNumber &B) {
std::swap(*this, B);
}
int BigNumber::size() const { return this->x[0]; }
BigNumber & BigNumber ::operator=(const BigNumber &B) {
this->sgn = B.sgn;
memset(this->x, 0, sizeof(this->x));
for (int i = 0; i <= B.x[0]; i++) this->x[i] = B.x[i];
return *this;
}
BigNumber & BigNumber ::operator=(const int &A) {
BigNumber B = A;
this->sgn = B.sgn;
memset(this->x, 0, sizeof(this->x));
for (int i = 0; i <= B.x[0]; i++) this->x[i] = B.x[i];
return *this;
}
BigNumber & BigNumber ::operator=(const string &A) {
BigNumber B = A;
this->sgn = B.sgn;
memset(this->x, 0, sizeof(this->x));
for (int i = 0; i <= B.x[0]; i++) this->x[i] = B.x[i];
return *this;
}
ostream &operator<<(ostream & output, BigNumber & B) {
B.shrink();
if (B.sgn == -1) output << '-';
for (int i = B.x[0]; i >= 1; i--) output << B.x[i];
return output;
}
istream &operator >> (istream & input, BigNumber & B) {
string st;
input >> st;
B = BigNumber(st);
return input;
}
BigNumber BigNumber ::operator+() const {
return *this;
}
BigNumber BigNumber ::operator-() const {
BigNumber t = *this;
t.sgn = -t.sgn;
return t;
}
int compare(const BigNumber & A, const BigNumber & B) {
if (A.sgn > B.sgn) return 1;
if (A.sgn < B.sgn) return -1;
if (A.x[0] > B.x[0]) return A.sgn;
if (A.x[0] < B.x[0]) return -A.sgn;
for (int i = A.x[0]; i >= 1; i--) {
if (A.x[i] > B.x[i]) return A.sgn;
if (A.x[i] < B.x[i]) return -A.sgn;
}
return 0;
}
bool operator>(const BigNumber &A, const BigNumber &B) {
return compare(A, B) == 1;
}
bool operator>=(const BigNumber &A, const BigNumber &B) {
return compare(A, B) != -1;
}
bool operator<(const BigNumber &A, const BigNumber &B) {
return compare(A, B) == -1;
}
bool operator<=(const BigNumber &A, const BigNumber &B) {
return compare(A, B) != 1;
}
bool operator==(const BigNumber &A, const BigNumber &B) {
return compare(A, B) == 0;
}
bool operator!=(const BigNumber &A, const BigNumber &B) {
return compare(A, B) != 0;
}
bool operator>(const BigNumber &A, const int &B) {
return compare(A, B) == 1;
}
bool operator>=(const BigNumber &A, const int &B) {
return compare(A, B) != -1;
}
bool operator<(const BigNumber &A, const int &B) {
return compare(A, B) == -1;
}
bool operator<=(const BigNumber &A, const int &B) {
return compare(A, B) != 1;
}
bool operator==(const BigNumber &A, const int &B) {
return compare(A, B) == 0;
}
bool operator!=(const BigNumber &A, const int &B) {
return compare(A, B) != 0;
}
bool operator>(const int &A, const BigNumber &B) {
return compare(A, B) == 1;
}
bool operator>=(const int &A, const BigNumber &B) {
return compare(A, B) != -1;
}
bool operator<(const int &A, const BigNumber &B) {
return compare(A, B) == -1;
}
bool operator<=(const int &A, const BigNumber &B) {
return compare(A, B) != 1;
}
bool operator==(const int &A, const BigNumber &B) {
return compare(A, B) == 0;
}
bool operator!=(const int &A, const BigNumber &B) {
return compare(A, B) != 0;
}
bool BigNumber ::operator!() const { return *this == 0; }
BigNumber abs(const BigNumber &B) { return (B >= 0) ? (+B) : (-B); }
BigNumber operator + (const BigNumber &A, const BigNumber &B) {
if (!A) return B;
if (!B) return A;
if (A.sgn == B.sgn) {
BigNumber C(A.sgn, max(A.x[0], B.x[0]));
for (int i = 1; i <= C.x[0]; i++) C.x[i] = A.x[i] + B.x[i];
for (int i = 1; i <= C.x[0]; i++) C.x[i + 1] += C.x[i] / 10, C.x[i] %= 10;
C.x[0] += (C.x[C.x[0] + 1] > 0);
return C;
}
if (A < 0) return B - (-A); else return A - (-B);
}
BigNumber operator - (const BigNumber &A, const BigNumber &B) {
if (!A) return -B;
if (!B) return A;
if (A < 0) return -(-A + B);
if (B < 0) return A + (-B);
if (A < B) return -(B - A);
BigNumber C(1, A.x[0]);
for (int i = 1; i <= C.x[0]; i++) C.x[i] = A.x[i] - B.x[i];
for (int i = 1; i <= C.x[0]; i++) {
C.x[i + 1] -= (C.x[i] < 0);
C.x[i] += (C.x[i] < 0) * 10;
}
while (C.x[0] > 1 && !C.x[C.x[0]]) C.x[0]--;
C.sgn = !(C.x[0] == 1 && !C.x[1]);
return C;
}
BigNumber operator * (const BigNumber &A, const BigNumber &B) {
if (!A || !B) return 0;
BigNumber C(A.sgn*B.sgn, A.x[0] + B.x[0] - 1);
for (int i = 1; i <= A.x[0]; i++)
for (int j = 1; j <= B.x[0]; j++)
C.x[i + j - 1] += A.x[i] * B.x[j];
for (int i = 1; i <= C.x[0]; i++) C.x[i + 1] += C.x[i] / 10, C.x[i] %= 10;
while (C.x[C.x[0] + 1]) {
C.x[0]++;
C.x[C.x[0] + 1] += C.x[C.x[0]] / 10;
C.x[C.x[0]] %= 10;
}
return C;
}
BigNumber operator + (const BigNumber &A, const int &B) { return A + BigNumber(B); }
BigNumber operator - (const BigNumber &A, const int &B) { return A - BigNumber(B); }
BigNumber operator * (const BigNumber &A, const int &B) { return A * BigNumber(B); }
BigNumber operator + (const int &A, const BigNumber &B) { return BigNumber(A) + B; }
BigNumber operator - (const int &A, const BigNumber &B) { return BigNumber(A) - B; }
BigNumber operator * (const int &A, const BigNumber &B) { return BigNumber(A) * B; }
BigNumber& BigNumber ::operator +=(const BigNumber &A) { return *this = *this + A; }
BigNumber& BigNumber ::operator -=(const BigNumber &A) { return *this = *this - A; }
BigNumber& BigNumber ::operator *=(const BigNumber &A) { return *this = *this * A; }
BigNumber& BigNumber ::operator +=(const int &A) { return *this = *this + A; }
BigNumber& BigNumber ::operator -=(const int &A) { return *this = *this - A; }
BigNumber& BigNumber ::operator *=(const int &A) { return *this = *this * A; }
BigNumber& BigNumber ::operator ++() { return *this += 1; }
BigNumber BigNumber ::operator ++(int) { return *this += 1; }
BigNumber& BigNumber ::operator --() { return *this -= 1; }
BigNumber BigNumber ::operator --(int) { return *this -= 1; }
const int MAXN = 200005;
const ll INF = 9223372036854775807;
struct Edge {
int v;
int cost;
Edge(int _v = 0, int _cost = 0) :v(_v), cost(_cost) {}
};
vector<Edge>E[MAXN];
void addedge(int u, int v, int w) {
E[u].push_back(Edge(v, w));
}
bool vis[MAXN];
int cnt[MAXN];
BigNumber dist[MAXN];
bool SPFA(int start, int n) {
memset(vis, false, sizeof(vis));
for (int i = 1; i <= n; i++)dist[i] = "92233720368547758079225807";
vis[start] = true;
dist[start] = 0;
queue<int>que;
while (!que.empty())que.pop();
que.push(start);
memset(cnt, 0, sizeof(cnt));
cnt[start] = 1;
while (!que.empty()) {
int u = que.front();
que.pop();
vis[u] = false;
for (int i = 0; i<E[u].size(); i++) {
int v = E[u][i].v;
if (dist[v]>dist[u] + E[u][i].cost) {
dist[v] = dist[u] + E[u][i].cost;
if (!vis[v]) {
vis[v] = true;
que.push(v);
if (++cnt[v]>n)return false;
}
}
}
}
return true;
}
int n, m, a, b, c;
int main() {
//file_put();
scanf("%d%d", &n, &m);
for (int i = 1; i <= m; i++) {
scanf("%d%d%d", &a, &b, &c);
addedge(a, b, -c);
}
if (!SPFA(1, n)) printf("inf\n"); else cout << -dist[n] << endl;
return 0;
}
| a.cc: In function 'int main()':
a.cc:504:53: error: no match for 'operator<<' (operand types are 'std::ostream' {aka 'std::basic_ostream<char>'} and 'BigNumber')
504 | if (!SPFA(1, n)) printf("inf\n"); else cout << -dist[n] << endl;
| ~~~~ ^~ ~~~~~~~~
| | |
| | BigNumber
| std::ostream {aka std::basic_ostream<char>}
a.cc:260:10: note: candidate: 'std::ostream& operator<<(std::ostream&, BigNumber&)' (near match)
260 | ostream &operator<<(ostream & output, BigNumber & B) {
| ^~~~~~~~
a.cc:260:10: note: conversion of argument 2 would be ill-formed:
a.cc:504:56: error: cannot bind non-const lvalue reference of type 'BigNumber&' to an rvalue of type 'BigNumber'
504 | if (!SPFA(1, n)) printf("inf\n"); else cout << -dist[n] << endl;
| ^~~~~~~~
In file included from /usr/include/c++/14/iostream:41,
from a.cc:1:
/usr/include/c++/14/ostream:116:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(__ostream_type& (*)(__ostream_type&)) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
116 | operator<<(__ostream_type& (*__pf)(__ostream_type&))
| ^~~~~~~~
/usr/include/c++/14/ostream:116:36: note: no known conversion for argument 1 from 'BigNumber' to 'std::basic_ostream<char>::__ostream_type& (*)(std::basic_ostream<char>::__ostream_type&)' {aka 'std::basic_ostream<char>& (*)(std::basic_ostream<char>&)'}
116 | operator<<(__ostream_type& (*__pf)(__ostream_type&))
| ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/ostream:125:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(__ios_type& (*)(__ios_type&)) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>; __ios_type = std::basic_ios<char>]'
125 | operator<<(__ios_type& (*__pf)(__ios_type&))
| ^~~~~~~~
/usr/include/c++/14/ostream:125:32: note: no known conversion for argument 1 from 'BigNumber' to 'std::basic_ostream<char>::__ios_type& (*)(std::basic_ostream<char>::__ios_type&)' {aka 'std::basic_ios<char>& (*)(std::basic_ios<char>&)'}
125 | operator<<(__ios_type& (*__pf)(__ios_type&))
| ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
/usr/include/c++/14/ostream:135:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(std::ios_base& (*)(std::ios_base&)) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
135 | operator<<(ios_base& (*__pf) (ios_base&))
| ^~~~~~~~
/usr/include/c++/14/ostream:135:30: note: no known conversion for argument 1 from 'BigNumber' to 'std::ios_base& (*)(std::ios_base&)'
135 | operator<<(ios_base& (*__pf) (ios_base&))
| ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
/usr/include/c++/14/ostream:174:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long int) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
174 | operator<<(long __n)
| ^~~~~~~~
/usr/include/c++/14/ostream:174:23: note: no known conversion for argument 1 from 'BigNumber' to 'long int'
174 | operator<<(long __n)
| ~~~~~^~~
/usr/include/c++/14/ostream:178:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long unsigned int) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
178 | operator<<(unsigned long __n)
| ^~~~~~~~
/usr/include/c++/14/ostream:178:32: note: no known conversion for argument 1 from 'BigNumber' to 'long unsigned int'
178 | operator<<(unsigned long __n)
| ~~~~~~~~~~~~~~^~~
/usr/include/c++/14/ostream:182:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(bool) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
182 | operator<<(bool __n)
| ^~~~~~~~
/usr/include/c++/14/ostream:182:23: note: no known conversion for argument 1 from 'BigNumber' to 'bool'
182 | operator<<(bool __n)
| ~~~~~^~~
In file included from /usr/include/c++/14/ostream:1022:
/usr/include/c++/14/bits/ostream.tcc:96:5: note: candidate: 'std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(short int) [with _CharT = char; _Traits = std::char_traits<char>]'
96 | basic_ostream<_CharT, _Traits>::
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/ostream.tcc:97:22: note: no known conversion for argument 1 from 'BigNumber' to 'short int'
97 | operator<<(short __n)
| ~~~~~~^~~
/usr/include/c++/14/ostream:189:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(short unsigned int) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
189 | operator<<(unsigned short __n)
| ^~~~~~~~
/usr/include/c++/14/ostream:189:33: note: no known conversion for argument 1 from 'BigNumber' to 'short unsigned int'
189 | operator<<(unsigned short __n)
| ~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/ostream.tcc:110:5: note: candidate: 'std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(int) [with _CharT = char; _Traits = std::char_traits<char>]'
110 | basic_ostream<_CharT, _Traits>::
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/ostream.tcc:111:20: note: no known conversion for argument 1 from 'BigNumber' to 'int'
111 | operator<<(int __n)
| ~~~~^~~
/usr/include/c++/14/ostream:200:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(unsigned int) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
200 | operator<<(unsigned int __n)
| ^~~~~~~~
/usr/include/c++/14/ostream:200:31: note: no known conversion for argument 1 from 'BigNumber' to 'unsigned int'
200 | operator<<(unsigned int __n)
| ~~~~~~~~~~~~~^~~
/usr/include/c++/14/ostream:211:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long long int) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
211 | operator<<(long long __n)
| ^~~~~~~~
/usr/include/c++/14/ostream:211:28: note: no known conversion for argument 1 from 'BigNumber' to 'long long int'
211 | operator<<(long long __n)
| ~~~~~~~~~~^~~
/usr/include/c++/14/ostream:215:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long long unsigned int) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
215 | operator<<(unsigned long long __n)
| ^~~~~~~~
/usr/include/c++/14/ostream:215:37: note: no known conversion for argument 1 from 'BigNumber' to 'long long unsigned int'
215 | operator<<(unsigned long long __n)
| ~~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/ostream:231:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(double) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
231 | operator<<(double __f)
| ^~~~~~~~
/usr/include/c++/14/ostream:231:25: note: no known conversion for argument 1 from 'BigNumber' to 'double'
231 | operator<<(double __f)
| ~~~~~~~^~~
/usr/include/c++/14/ostream:235:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(float) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
235 | operator<<(float __f)
| ^~~~~~~~
/usr/include/c++/14/ostream:235:24: note: no known conversion for argument 1 from 'BigNumber' to 'float'
235 | operator<<(float __f)
| ~~~~~~^~~
/usr/include/c++/14/ostream:243:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long double) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
243 | operator<<(long double __f)
| ^~~~~~~~
/usr/include/c++/14/ostream:243:30: note: no known conversion for argument 1 from 'BigNumber' to 'long double'
243 | operator<<(long double __f)
| ~~~~~~~~~~~~^~~
/usr/include/c++/14/ostream:301:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(const void*) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]'
301 | operator<<(const void* __p)
| ^~~~~~~~
/usr/include/c++/14/ostream:301:30: note: no known conversion for argument 1 from 'BigNumber' to 'const void*'
301 | operator<<(const void* __p)
| ~~~~~~~~~~~~^~~
/usr/include/c++/14/ostream:306:7: note: candidate: 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(std::nul |
s116778892 | p03722 | C++ | #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
struct Edge{ //边类型定义
ll u,v; //起点和终点
ll l; //边长-----------------------------******(可能是浮点型)
};
ll n,m; //n是点数,m是边数
const ll N=1005,M=2006; //问题中给出的可能的最大点数和最大边数(无向边算两条边)-----------------*******(根据实际问题修改)
const ll MAXL = 1e15; //边的无限长
Edge edge[M+10]; //边集
ll pre[N+10]; //从源点到该点的路径上该点的前驱(以源点为根的路径树,根结点的值为-1)
ll dist[N+10]; //从源点到该点的最短距离
//松弛操作
bool relax( Edge e ){
if( dist[e.v] > dist[e.u]+e.l ){
dist[e.v] = dist[e.u]+e.l;
pre[e.v] = e.u;
return true; //进行更新的话返回真值
}
return false;
}
bool relaxX(Edge e){
if( dist[e.v] > dist[e.u]+e.l ){
dist[e.v] = dist[e.u]+e.l;
pre[e.v] = e.u;
if((e.u)==(n-1)||(e.v==(n-1))return true; //进行更新的话返回真值
}
return false;
}
bool bellman(int s){
//初始化dist[] 和 pre[]
for(ll i=0 ; i<n ; i++){
dist[i] = MAXL;
pre[i] = -1;
}
dist[s] = 0;
bool change = false; //使用标记优化,提高效率
for(ll i=1 ; i<n ; i++){
change = false;
for(ll j=0 ; j<m ; j++){
if( relax(edge[j]) )
change = relax;
}
if( !change ) //如果对所有边进行的一次relax()操作没有更新说明已经找到了到所有点的最短路
break;
}
for(ll i=0 ; i<m ; i++){
if( relaxX(edge[i]) )
return false; //再对所有边进行一次relax()操作,如果有更新dist[]则说明存在负权回路
}
return true;
}
int main(){
scanf("%lld%lld",&n,&m);
ll a,b,c;
for(int i=0;i<m;i++){
scanf("%lld%lld%lld",&a,&b,&c);
edge[i].u=a-1;
edge[i].v=b-1;
edge[i].l=-c;
}
if(bellman(0)){
printf("%lld",-dist[n-1]);
}else printf("inf");
return 0;
} | a.cc: In function 'bool relaxX(Edge)':
a.cc:31:46: error: expected ';' before 'return'
31 | if((e.u)==(n-1)||(e.v==(n-1))return true; //进行更新的话返回真值
| ^~~~~~
| ;
a.cc:32:9: error: expected primary-expression before '}' token
32 | }
| ^
a.cc:31:58: error: expected ')' before '}' token
31 | if((e.u)==(n-1)||(e.v==(n-1))return true; //进行更新的话返回真值
| ~ ^
| )
32 | }
| ~
a.cc:32:9: error: expected primary-expression before '}' token
32 | }
| ^
|
s344185626 | p03722 | C++ | #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
struct Edge{ //边类型定义
ll u,v; //起点和终点
ll l; //边长-----------------------------******(可能是浮点型)
};
ll n,m; //n是点数,m是边数
const ll N=1005,M=2006; //问题中给出的可能的最大点数和最大边数(无向边算两条边)-----------------*******(根据实际问题修改)
const ll MAXL = 1e15; //边的无限长
Edge edge[M+10]; //边集
ll pre[N+10]; //从源点到该点的路径上该点的前驱(以源点为根的路径树,根结点的值为-1)
ll dist[N+10]; //从源点到该点的最短距离
//松弛操作
bool relax( Edge e ){
if( dist[e.v] > dist[e.u]+e.l ){
dist[e.v] = dist[e.u]+e.l;
pre[e.v] = e.u;
return true; //进行更新的话返回真值
}
return false;
}
bool relaxX(Edge e){
if( dist[e.v] > dist[e.u]+e.l ){
dist[e.v] = dist[e.u]+e.l;
pre[e.v] = e.u;
if((e.u)==(n-1)||(e.v==(n-1)return true; //进行更新的话返回真值
}
return false;
}
bool bellman(int s){
//初始化dist[] 和 pre[]
for(ll i=0 ; i<n ; i++){
dist[i] = MAXL;
pre[i] = -1;
}
dist[s] = 0;
bool change = false; //使用标记优化,提高效率
for(ll i=1 ; i<n ; i++){
change = false;
for(ll j=0 ; j<m ; j++){
if( relax(edge[j]) )
change = relax;
}
if( !change ) //如果对所有边进行的一次relax()操作没有更新说明已经找到了到所有点的最短路
break;
}
for(ll i=0 ; i<m ; i++){
if( relaxX(edge[i]) )
return false; //再对所有边进行一次relax()操作,如果有更新dist[]则说明存在负权回路
}
return true;
}
int main(){
scanf("%lld%lld",&n,&m);
ll a,b,c;
for(int i=0;i<m;i++){
scanf("%lld%lld%lld",&a,&b,&c);
edge[i].u=a-1;
edge[i].v=b-1;
edge[i].l=-c;
}
if(bellman(0)){
printf("%lld",-dist[n-1]);
}else printf("inf");
return 0;
} | a.cc: In function 'bool relaxX(Edge)':
a.cc:31:45: error: expected ')' before 'return'
31 | if((e.u)==(n-1)||(e.v==(n-1)return true; //进行更新的话返回真值
| ~ ^~~~~~
| )
a.cc:31:56: error: expected ')' before ';' token
31 | if((e.u)==(n-1)||(e.v==(n-1)return true; //进行更新的话返回真值
| ~ ^
| )
|
s812161897 | p03722 | C++ | #include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <functional>
#include <iostream>
#define INF 10000000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,ll> P;
int n,m;
ll f[2001],t[2001],c[2001];
ll res[1001];
void solve(){
for(int i=0;i<n;i++){
res[i]=INF;
}
res[0]=0;
int cnt=0;
while(true){
bool upd=false;
bool upd2=false;
for(int i=0;i<m;i++){
if(res[f[i]]!=INF && res[f[i]]-c[i]<res[t[i]]){
upd=true;
res[t[i]]=res[f[i]]-c[i];
if(t[i]==n-1)upd2=true;
}
}
if(!upd)break;
if(cnt>3*n && upd2){
printf("inf\n");
return;
}
if(cnt==4*n)break;
cnt++;
}
printf("%lld\n",-res[n-1]);
}
int main(void){
scanf("%d%d",&n,&m);
for(int i=0;i<m;i++){
scanf("%lld%lld%lld",&f[i],&t[i],&c[i]);
f[i]--;
t[i]--;
}
solve();
return 0;
} | a.cc:17:1: error: extended character is not valid in an identifier
17 |
| ^
a.cc:21:1: error: extended character is not valid in an identifier
21 |
| ^
a.cc:48:1: error: extended character is not valid in an identifier
48 |
| ^
a.cc:17:1: error: '\U000000a0' does not name a type
17 |
| ^
a.cc:21:1: error: '\U000000a0' does not name a type
21 |
| ^
a.cc:48:1: error: '\U000000a0' does not name a type
48 |
| ^
|
s681523632 | p03722 | C++ | #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
using ll = long long int;
struct edge { ll from, to, cost;
edge(ll a,ll b,ll c) : from(a) , to(b) , cost(c){
}
};
vector<edge> es[1010];
vector<ll> d;
ll V, E;
ll INF = 9223372036854775807;
// 戻り値がtrueなら負の閉路を含む
bool bellman_ford(int n, int s) { // nは頂点数、sは開始頂点
d = vector<ll>(n,INF);
d[s] = 0; // 開始点の距離は0
for (ll i = 0; i < n; i++) {
for (ll v = 0; v < n; v++) {
for (ll k = 0; k < es[v].size(); k++) {
edge e = es[v][k];
if (d[v] != INF && d[e.to] > d[v] + e.cost) {
d[e.to] = d[v] + e.cost;
if (i == n - 1) return true; // n回目にも更新があるなら負の閉路が存在
}
}
}
}
return false;
}
int main() {
cin >> V >> E;
for (ll i = 0; i < E; i++) {
ll a, b, c;
cin >> a >> b >> c;
a--; b--;
es[a].push_back(edge(a, b, c*-1));
}
if (bellman_ford(V, 0)) {
cout << "inf" << endl;
}
else {
cout << -1LL*d[V - 1] << endl;
}
| a.cc: In function 'int main()':
a.cc:59:10: error: expected '}' at end of input
59 | }
| ^
a.cc:43:12: note: to match this '{'
43 | int main() {
| ^
|
s624675924 | p03722 | C++ | #include<iostream>
#include<vector>
#include<stack>
#include<algorithm>
using namespace std;
struct Node {
long long max_score;
bool visited;
std::vector<pair<int ,int>> connect;
};
int main()
{
long long N, M;
cin >> N >> M;
std::vector<Node> nodes(N + 1);
for (int i = 1; i <= N; i++) {
nodes[i].max_score = LLONG_MIN;
}
for (int i = 0; i < M; i++) {
int a, b, c;
cin >> a >> b >> c;
nodes[a].connect.push_back(make_pair(b, c));
}
nodes[1].max_score = 0;
for (int i = 1; i <= N; i++) {
for (unsigned int j = 0; j < nodes[i].connect.size(); j++) {
//自分自身のスコア + 移動で得るスコア
long long score = nodes[i].max_score + nodes[i].connect[j].second;
//すでに調査済のノードの最大スコアを更新できたらinf
if (nodes[nodes[i].connect[j].first].max_score < score && nodes[nodes[i].connect[j].first].visited == true) {
printf("inf\n");
return 0;
}
nodes[nodes[i].connect[j].first].max_score = max(nodes[nodes[i].connect[j].first].max_score, score);
}
//ノードの調査済フラグを立てる
nodes[i].visited = true;
}
cout << nodes[N].max_score << endl;
} | a.cc: In function 'int main()':
a.cc:21:38: error: 'LLONG_MIN' was not declared in this scope
21 | nodes[i].max_score = LLONG_MIN;
| ^~~~~~~~~
a.cc:5:1: note: 'LLONG_MIN' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
4 | #include<algorithm>
+++ |+#include <climits>
5 | using namespace std;
|
s090284349 | p03722 | C++ | #include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
long long n,m;
bool infs;
bool vis[1010];
long long maxs[1010];
vector<long long> v[1010];
vector<long long>score[1010];
void DFS(long long key,long long pnt){
if(vis[key]){infs=true;return;}
maxs[key]=pnt;
vis[key]=true;
for(long long i=0;i<v[key].size();i++){
long long qq=pnt+score[key][i];
if(qq>maxs[v[key][i]]){
DFS(v[key][i],qq);
}
}
vis[key]=false;
}
long long main(){
cin>>n>>m;
for(long long i=0;i<m;i++){
long long a,b;
long long c;
cin>>a>>b>>c;a--,b--;
v[a].push_back(b);
score[a].push_back(c);
}
infs=false;
for(long long i=0;i<n;i++)vis[i]=false,maxs[i]=-5000000000000;
DFS(0,0);
if(infs)cout<<"inf"<<endl;
else cout<<maxs[n-1]<<endl;
return 0;
} | cc1plus: error: '::main' must return 'int'
|
s580976312 | p03722 | C++ | #include <set>
#include <map>
#include <list>
#include <stack>
#include <queue>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
#define int long long
typedef pair<int,int> P;
const int INF = LLONG_MAX;
vector<int> d;
int n,m;
struct edge{int from, to, cost;};
vector<edge> es;
signed main(void){
cin >> n >> m;
for(int i = 0; i < m; i++){
edge buf;
cin >> buf.from >> buf.to >> buf.cost;
buf.from--;
buf.to--;
buf.cost = -buf.cost;
es.push_back(buf);
}
for(int i = 0; i < n; i++) d.push_back(INF);
d[0] = 0;
bool b_inf = false;
for(int j = 0; j < n; j++){
bool update = 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=true;
}
}
if(j==n-1)b_inf=true;
if(!update) break;
}
if(b_inf)cout<<"inf\r\n";
else cout<<-d[n-1]<< "\r\n";
return 0;
}
| a.cc:30:17: error: 'LLONG_MAX' was not declared in this scope
30 | const int INF = LLONG_MAX;
| ^~~~~~~~~
a.cc:25:1: note: 'LLONG_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
24 | #include <algorithm>
+++ |+#include <climits>
25 | using namespace std;
|
s428548319 | p03722 | C++ | #include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
using namespace std;
void SPFA();
queue<int> q;
int dis[1005],a[1005][1005],n,m,st,en,time[1005];
bool flag;
int main()
{
while(scanf("%d%d",&n,&m)!=EOF)
{
flag=1;
memset(a,0,sizeof(a));
memset(dis,0,sizeof(dis));
memset(time, 0, sizeof(time));
for(int j=0; j<m; ++j)
{
int a1,a2,a3;
scanf("%d%d%d",&a1,&a2,&a3);
if(a3 > a[a1][a2])
{
a[a1][a2]=a3;
}
}
st = 1;
SPFA();
if(!flag)
cout<<"inf"<<endl;
else
{
cout << dis[n] << endl;
}
}
return 0;
}
void SPFA()
{
dis[st]=0;
q.push(st);
while(!q.empty())
{
int i=q.front();
q.pop();
for(int i1=1; i1<=n; ++i1)
{
if(dis[i1]<dis[i]+a[i][i1] && a[i][i1])
{
dis[i1]=dis[i]+a[i][i1];
q.push(i1);
time[i1]++;
}
if(time[i1]>n)
{
flag=0;
while(!q.empty())
q.pop();
break;
}
}
}
}
| a.cc:10:48: error: 'int time [1005]' redeclared as different kind of entity
10 | int dis[1005],a[1005][1005],n,m,st,en,time[1005];
| ^
In file included from /usr/include/pthread.h:23,
from /usr/include/x86_64-linux-gnu/c++/14/bits/gthr-default.h:35,
from /usr/include/x86_64-linux-gnu/c++/14/bits/gthr.h:157,
from /usr/include/c++/14/ext/atomicity.h:35,
from /usr/include/c++/14/bits/ios_base.h:39,
from /usr/include/c++/14/ios:44,
from /usr/include/c++/14/ostream:40,
from /usr/include/c++/14/iostream:41,
from a.cc:2:
/usr/include/time.h:76:15: note: previous declaration 'time_t time(time_t*)'
76 | extern time_t time (time_t *__timer) __THROW;
| ^~~~
a.cc: In function 'int main()':
a.cc:19:32: error: ISO C++ forbids applying 'sizeof' to an expression of function type [-fpermissive]
19 | memset(time, 0, sizeof(time));
| ~^~~~~
a.cc:19:16: error: invalid conversion from 'time_t (*)(time_t*) noexcept' {aka 'long int (*)(long int*) noexcept'} to 'void*' [-fpermissive]
19 | memset(time, 0, sizeof(time));
| ^~~~
| |
| time_t (*)(time_t*) noexcept {aka long int (*)(long int*) noexcept}
In file included from /usr/include/c++/14/cstring:43,
from a.cc:3:
/usr/include/string.h:61:28: note: initializing argument 1 of 'void* memset(void*, int, size_t)'
61 | extern void *memset (void *__s, int __c, size_t __n) __THROW __nonnull ((1));
| ~~~~~~^~~
a.cc: In function 'void SPFA()':
a.cc:56:24: warning: pointer to a function used in arithmetic [-Wpointer-arith]
56 | time[i1]++;
| ^
a.cc:56:24: warning: ISO C++ forbids incrementing a pointer of type 'time_t (*)(time_t*) noexcept' {aka 'long int (*)(long int*) noexcept'} [-Wpointer-arith]
56 | time[i1]++;
| ~~~~~~~^
a.cc:56:24: error: lvalue required as increment operand
56 | time[i1]++;
| ^
a.cc:58:23: warning: pointer to a function used in arithmetic [-Wpointer-arith]
58 | if(time[i1]>n)
| ^
a.cc:58:24: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
58 | if(time[i1]>n)
| ~~~~~~~~^~
|
s224512682 | p03722 | C++ | #include <iostream>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <map>
#define eps 0.0000000001
#define maxn 30009
#define inf 0x3f3f3f3f
#define mod 1000000009
#define ll long long
using namespace std;
int n,m;
struct ee
{
int to;
ll v;
};
vector<ee> g[maxn];
ll d[maxn];
int in[maxn];
bool v[maxn],vv[maxn];
int main()
{
//freopen("d:\\in.txt","r",stdin);
scanf("%d%d",&n,&m);
for(int i=1;i<=m;i++)
{
ee p;
int a;
scanf("%d%d%lld",&a,&p.to,&p.v);
g[a].push_back(p);
}
memset(in,0,sizeof(in));
queue<int> q;
bool ff=false;
for(int i=1;i<=maxn-5;i++)
d[i]=-10000000000000000;
q.push(1);
d[1]=0;
ll ans;
while(!q.empty())
{
int u=q.front();
q.pop();
v[u]=false;
for(int i=0;i<g[u].size();i++)
{
ee r=g[u][i];
if(d[r.to]<d[u]+r.v)
{
in[r.to]++;
if(in[r.to]>4000)
{
ann=d[u];
}
if(in[r.to]>5000)
{
if(ann<d[u])
{
ff=true;
break;
}
}
d[r.to]=d[u]+r.v;
if(v[r.to]==false)
{
q.push(r.to),v[r.to]=true;
in[r.to]++;
}
}
}
if(ff)
break;
}
if(ff)
printf("inf\n");
else
printf("%lld\n",d[n]);
return 0;
}
| a.cc: In function 'int main()':
a.cc:57:21: error: 'ann' was not declared in this scope; did you mean 'ans'?
57 | ann=d[u];
| ^~~
| ans
a.cc:61:24: error: 'ann' was not declared in this scope; did you mean 'ans'?
61 | if(ann<d[u])
| ^~~
| ans
|
s804829391 | p03722 | C++ | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,ll> P;
const ll INF=9000000000000000000LL;
int N,M;
ll score[1234];
bool X[1234][1234];
vector<P> e[2345];
void dfs(int s){
if(s==N) return;
for(int i=0; i<e[s].size(); i++){
score[e[s][i].first]=max(score[e[s][i].first],score[s]+e[s][i].second);
dfs(e[s][i].first);
}
return;
}
int main(){
cin>>N>>M;
for(int i=0; i<M; i++){
int a,b; ll c;
scanf("%d %d %lld",&a,&b,&c);
X[a][b]=1;
e[a].push_back(P(b,c));
}
for(int i=1; i<=N; i++){
for(int j=1; j<=N; j++){
if(X[i][j]==1&&X[j][i]==1){
cout<<"inf"<<endl; return 0;
}
}
}
for(int i=1; i<=N; i++) score[i]=-INF;
score[1]=0LL;
dfs(1);
cout<<score[N]<<endl;
return 0;
} | a.cc:34:1: error: extended character is not valid in an identifier
34 | for(int j=1; j<=N; j++){
| ^
a.cc:34:1: error: extended character is not valid in an identifier
a.cc:38:1: error: extended character is not valid in an identifier
38 | }
| ^
a.cc:38:1: error: extended character is not valid in an identifier
a.cc: In function 'int main()':
a.cc:34:9: error: expected primary-expression before 'int'
34 | for(int j=1; j<=N; j++){
| ^~~
a.cc:34:18: error: 'j' was not declared in this scope
34 | for(int j=1; j<=N; j++){
| ^
|
s090303981 | p03722 | C++ | #include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>
using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define FIND(s, e) ((s).find(e) != (s).end())
#define EB emplace_back
template<typename T> inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}
const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;
// O(|V||E|)
struct edge {int from, to, cost;};
bool Bellman_Ford(int V, int E, int s, edge es[], LL dist[]) {
fill(dist, dist + V, LLINF);
dist[s] = 0;
int cnt = 0;
while (true) {
bool update = false;
VI v;
for (int i = 0; i < E; ++i) {
bool f = (dist[es[i].from] != LLINF && chmin(dist[es[i].to], dist[es[i].from] + es[i].cost));
if (f) v.EB(es[i].to);
update |= f;
}
if (!update) break;
if (cnt == V - 1) {
FORE(e, v) if (e = v - 1) return true;
break;
}
++cnt;
}
return false;
}
const int MAX_N = 1010;
const int MAX_M = 2020;
int N, M;
edge e[MAX_M];
int main(void) {
scanf("%d%d", &N, &M);
REP(i, M) {
int a, b, c;
scanf("%d%d%d", &a, &b, &c);
e[i] = {a - 1, b - 1, -c};
}
vector<LL> dist(N);
if (Bellman_Ford(N, M, 0, e, dist.data())) {
cout << "inf" << endl;
DEBUG(-dist[N - 1])
} else cout << -dist[N - 1] << endl;
}
| a.cc: In function 'bool Bellman_Ford(int, int, int, edge*, LL*)':
a.cc:79:34: error: no match for 'operator-' (operand types are 'VI' {aka 'std::vector<int>'} and 'int')
79 | FORE(e, v) if (e = v - 1) return true;
| ~ ^ ~
| | |
| | int
| VI {aka std::vector<int>}
In file included from /usr/include/c++/14/string:48,
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_iterator.h:618:5: note: candidate: 'template<class _IteratorL, class _IteratorR> constexpr decltype ((__y.base() - __x.base())) std::operator-(const reverse_iterator<_Iterator>&, const reverse_iterator<_IteratorR>&)'
618 | operator-(const reverse_iterator<_IteratorL>& __x,
| ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:618:5: note: template argument deduction/substitution failed:
a.cc:79:36: note: 'VI' {aka 'std::vector<int>'} is not derived from 'const std::reverse_iterator<_Iterator>'
79 | FORE(e, v) if (e = v - 1) return true;
| ^
/usr/include/c++/14/bits/stl_iterator.h:1790:5: note: candidate: 'template<class _IteratorL, class _IteratorR> constexpr decltype ((__x.base() - __y.base())) std::operator-(const move_iterator<_IteratorL>&, const move_iterator<_IteratorR>&)'
1790 | operator-(const move_iterator<_IteratorL>& __x,
| ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1790:5: note: template argument deduction/substitution failed:
a.cc:79:36: note: 'VI' {aka 'std::vector<int>'} is not derived from 'const std::move_iterator<_IteratorL>'
79 | FORE(e, v) if (e = v - 1) return true;
| ^
In file included from a.cc:8:
/usr/include/c++/14/complex:370:5: note: candidate: 'template<class _Tp> std::complex<_Tp> std::operator-(const complex<_Tp>&, const complex<_Tp>&)'
370 | operator-(const complex<_Tp>& __x, const complex<_Tp>& __y)
| ^~~~~~~~
/usr/include/c++/14/complex:370:5: note: template argument deduction/substitution failed:
a.cc:79:36: note: 'VI' {aka 'std::vector<int>'} is not derived from 'const std::complex<_Tp>'
79 | FORE(e, v) if (e = v - 1) return true;
| ^
/usr/include/c++/14/complex:379:5: note: candidate: 'template<class _Tp> std::complex<_Tp> std::operator-(const complex<_Tp>&, const _Tp&)'
379 | operator-(const complex<_Tp>& __x, const _Tp& __y)
| ^~~~~~~~
/usr/include/c++/14/complex:379:5: note: template argument deduction/substitution failed:
a.cc:79:36: note: 'VI' {aka 'std::vector<int>'} is not derived from 'const std::complex<_Tp>'
79 | FORE(e, v) if (e = v - 1) return true;
| ^
/usr/include/c++/14/complex:388:5: note: candidate: 'template<class _Tp> std::complex<_Tp> std::operator-(const _Tp&, const complex<_Tp>&)'
388 | operator-(const _Tp& __x, const complex<_Tp>& __y)
| ^~~~~~~~
/usr/include/c++/14/complex:388:5: note: template argument deduction/substitution failed:
a.cc:79:36: note: mismatched types 'const std::complex<_Tp>' and 'int'
79 | FORE(e, v) if (e = v - 1) return true;
| ^
/usr/include/c++/14/complex:465:5: note: candidate: 'template<class _Tp> std::complex<_Tp> std::operator-(const complex<_Tp>&)'
465 | operator-(const complex<_Tp>& __x)
| ^~~~~~~~
/usr/include/c++/14/complex:465:5: note: candidate expects 1 argument, 2 provided
|
s236184508 | p03722 | C++ | #include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <functional>
#include <cmath>
#include <complex>
#include <cctype>
#include <cassert>
#include <sstream>
#include <ctime>
#include <cstdlib>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> P;
const ll INF = 1ll<<60;
const ll MOD = 1000000007;
const double EPS = 1e-10;
int n, m;
int cnt[112345];
ll d[112345];
vector<pll> g[112345];
int main() {
cin >> n >> m;
REP(i, m) {
ll a, b, c;
scanf("%lld %lld %lld", &a, &b, &c);
g[a - 1].push_back(pll(b - 1, c));
}
fill(d, d + n, -INF);
priority_queue<pll> pq;
pq.push(pll(0, 0));
int cnt = 0;
bool ng = false;
while (!pq.empty()) {
pll now = pq.top();
pq.pop();
ll pos = now.second;
ll cost = now.first;
if (chmax(d[pos], cost)) {
cnt[pos]++;
if (cnt[n - 1] >= 20) {
ng = true;
break;
}
}
else continue;
if (cnt >= 10000000) break;
REP(i, g[pos].size()) {
ll next = g[pos][i].first;
ll nextc = g[pos][i].second + cost;
if (d[next] >= nextc) continue;
pq.push(pll(nextc, next));
}
}
if (ng) puts("inf");
else cout << d[n - 1] << endl;
return 0;
} | a.cc: In function 'int main()':
a.cc:67:28: error: invalid types 'int[ll {aka long long int}]' for array subscript
67 | cnt[pos]++;
| ^
a.cc:68:32: error: invalid types 'int[int]' for array subscript
68 | if (cnt[n - 1] >= 20) {
| ^
|
s177929961 | p03722 | C++ |
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
auto& in = std::cin;
auto& out = std::cout;
const int MAX_E = 2000;
const int MAX_V = 1000;
const int64_t INF = 10000000000000000;
// 頂点fromから頂点toへのコストcostの辺
struct edge { int from, to; int64_t cost; };
edge es[MAX_E]; // 辺
int64_t d[MAX_V]; // 最短距離
int V, E; // Vは頂点数、Eは辺数
// s番目の頂点から各頂点への最短距離を求める
void shortest_path(int 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() {
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;
}
int main()
{
using std::endl;
in.sync_with_stdio(false);
out.sync_with_stdio(false);
in >> V>>E;
for (int32_t i = 0; i < E; ++i)
{
int a, b, c;
in >> a >> b >> c; --a; --b; c = -c;
es[i] = edge{ a,b,c };
}
if (find_negative_loop()) {
std::cout << "inf\n"; return 0;
}
shortest_path(0);
std::cout << -d[V - 1] << std::endl;
return 0;
}
#endif
| a.cc: In function 'bool find_negative_loop()':
a.cc:54:9: error: 'memset' was not declared in this scope
54 | memset(d, 0, sizeof(d));
| ^~~~~~
a.cc:23:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
22 | #include <assert.h>
+++ |+#include <cstring>
23 |
|
s409821099 | p03723 | Java | a,b,c=map(int,input().split())
cnt=0
if a==b==c and a%2==0:
print(-1)
else:
while a%2==0 and b%2==0 and c%2==0:
a,b,c=(b+c)//2,(a+c)//2,(a+b)//2
cnt+=1
print(cnt)
| Main.java:1: error: class, interface, enum, or record expected
a,b,c=map(int,input().split())
^
1 error
|
s720152678 | p03723 | C++ | #include <bits/stdc++.h>
#define LL long long
#define PII pair
#define MP(x, y) make_pair((x),(y))
#define fi first
#define se second
#define PB(x) push_back((x))
#define MMG(x) memset((x), -1,sizeof(x))
#define MMF(x) memset((x),0,sizeof(x))
#define MMI(x) memset((x), INF, sizeof(x))
using namespace std;
const int INF = 0x3f3f3f3f;
const int N = 1e5+20;
const double eps = 1e-8;
char mp[1000][1000];
int dir[4][2] = {1, 0, -1, 0, 0, 1, 0, -1};
int vis[1000][1000];
int n, m, k;
int bfs(int sx, int sy)
{
MMF(vis);
int ans = INF;
queueq;
q.push(MP(sx, sy));
while(!q.empty())
{
PII nw = q.front();
q.pop();
int sp = min(min(nw.fi - 1, nw.se - 1), min(n - nw.fi , m - nw.se));
ans = min(sp / k + ((sp%k)?1:0), ans);
for(int i = 0; i < 4; i++)
{
int nx = nw.fi + dir[i][0];
int ny = nw.se + dir[i][1];
if(nx > 0 && ny > 0 && nx <= n && ny <= m && mp[nx][ny] == '.')
{
if(!vis[nx][ny] && abs(nx - sx) + abs(ny - sy) <= k)
vis[nx][ny] = 1, q.push(MP(nx, ny));
}
}
}
return ans;
}
int main()
{
while(cin >> n >> m >> k)
{
getchar();
int sx = -1, sy = -1;
for(int i = 1; i <= n; i++)
{
for(int j = 1; j <= m; j++)
{
scanf("%c",&mp[i][j]);
if(mp[i][j] == 'S')
sx = i, sy = j;
}
getchar();
}
int ans = bfs(sx, sy);
printf("%d\n", ans + 1);
}
return 0;
} | a.cc: In function 'int bfs(int, int)':
a.cc:25:5: error: 'queueq' was not declared in this scope
25 | queueq;
| ^~~~~~
a.cc:26:5: error: 'q' was not declared in this scope
26 | q.push(MP(sx, sy));
| ^
|
s395445140 | p03723 | C++ | #include <bits/stdc++.h>
#include <atcoder/segtree>
using namespace atcoder;
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
//#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
using dou =long double;
string yes="yes";
string Yes="Yes";
string YES="YES";
string no="no";
string No="No";
string NO="NO";
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
const ll mod = 1000000007;
//const ll mod = 10000000000ll;
//const ll mod = 10000;
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;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define brep(n) for(int bit=0;bit<(1<<n);bit++)
#define bbrep(n) for(int bbit=0;bbit<(1<<n);bbit++)
#define erep(i,container) for (auto &i : container)
#define itrep(i,container) for (auto i : container)
#define irep(i, n) for(ll i = n-1; i >= (ll)0ll; i--)
#define rrep(i,m,n) for(ll i = m; i < (ll)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define repreprep(i,j,k,h,w,n) rep(i,h)rep(j,w)rep(k,n)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define query int qq;std::cin >> qq;rep(qqq,qq)
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define itn int
#define mp make_pair
//#define sum(a) accumulate(all(a),0ll)
#define keta fixed<<setprecision
#define vout(a) erep(qxqxqx,a)std::cout << qxqxqx << ' ';std::cout << std::endl;
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
//#define vvector(name,typ,m,n)vector<vector<typ> > name(m,vector<typ> (n))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
#define case std::cout <<"Case #" <<qqq+1<<":"
#define RES(a,i,j) a.resize(i);rep(ii,i)a[ii].resize(j);
#define RESRES(a,i,j,k) a.resize(i);rep(ii,i)a[ii].resize(j);reprep(ii,jj,i,j){dp[ii][jj].resize(k)};
#define res resize
#define as assign
#define ffor for(;;)
#define ppri(a,b) std::cout << a<<" "<<b << std::endl
#define pppri(a,b,c) std::cout << a<<" "<<b <<" "<< c<<std::endl
#define ppppri(a,b,c,d) std::cout << a<<" "<<b <<" "<< c<<' '<<d<<std::endl
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define SUM(a) accumulate(all(a),0ll)
#define stirng string
#define gin(a,b) int a,b;std::cin >> a>>b;a--;b--;
#define popcount __builtin_popcount
#define permu(a) next_permutation(all(a))
//#define grid_input(a,type) int h,w;std::cin >> h>>w;vvector(a,type,h,w,0);reprep(i,j,h,w)std::cin >> a[i][j];
//typedef long long T;
ll ceil(ll a,ll b){
return ((a+b-1)/b);
}
const int INF = 2000000000;
const ll INF64 =3223372036854775807ll;
//const ll INF64 = 9223372036854775807ll;
//const ll INF64 = 243'000'000'000'000'000'0;
//const ll MOD = 100'000'000'7ll;
const ll MOD = 1000000007ll;
//const ll MOD = 1000003ll;
const ll OD = 1000000000000007ll;
const dou pi=3.141592653589793;
long long modpow(long long a, long long n) { //累乗の余剰
long long res = 1;
while (n > 0) {
if (n & 1) res = res * a % MOD;
a = a * a % MOD;
n >>= 1;
}
return res;
}
//メモ
//ゲーム(Grundy数とか)の復習をする
//群論の勉強をする?
//講演の録画をする(金曜日まで)←スーツが無難!
//周期性の実験をする
//リスニング力をどうにかする
//モノイドをやる!!!!
//特に理由がなければllを使おうキャンペーン
//Fenwick Treeのコンストラクタでvectorは使えないので注意
//ランチパスポートを使う
//using mint =modint998244353;
int main(){
ll a,b,c;
std::cin >> a>>b>>c;
if(a==b&&c==b){
std::cout << -1 << std::endl;
exit(0);
}
else{
int ans=0;
while(a%2==0&&b%2==0&&c%2==0){
a=(b+c)/2;
b=(a+c)/2;
c=(b+a)/2;
ans++;
}
std::cout << ans << std::endl;
}
} | a.cc:2:10: fatal error: atcoder/segtree: No such file or directory
2 | #include <atcoder/segtree>
| ^~~~~~~~~~~~~~~~~
compilation terminated.
|
s026212007 | p03723 | C++ | #include <bits/stdc++.h>
#define rep(i, n) for(long long i = 0; i < n; i++)
using ll = long long;
using ld = long double;
using namespace std;
int main() {
int A, B, C, a, b, c, N = 0;
cin >> A >> B >> C;
bool b = true;
a = A;
b = B;
c = C;
while(true) {
A = B / 2 + C / 2;
B = A / 2 + C / 2;
C = A / 2 + B / 2;
N++;
if (A % 2 == 1 || B % 2 == 1 || C % 2 == 1) {break;}
if (A == a && B == b && C == c) {
b = false;
break;
}
}
if (b) {cout << N << endl;}
else {cout << -1 << endl;}
} | a.cc: In function 'int main()':
a.cc:9:8: error: conflicting declaration 'bool b'
9 | bool b = true;
| ^
a.cc:7:19: note: previous declaration as 'int b'
7 | int A, B, C, a, b, c, N = 0;
| ^
|
s109169039 | p03723 | C++ | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = 1; i < (int)(n+1); i++)
int main() {
int A,B,C;
cin>>A>>B>>C;
int ans=true;
rep(i,100000000){
if(A==B&&B==C)
{
if(i==0){
if(A%2==1||B%2==1||C%2==1){
cout<<0<<endl;
break:}
}
cout<<-1<<endl;
break;
}
int D=A;
int E=B;
int F=C;
A=(E+F)/2;
B=(D+F)/2;
C=(D+E)/2;
if(A%2==1||B%2==1||C%2==1){
cout<<i+1<<endl;
break;
}
}
}
| a.cc: In function 'int main()':
a.cc:17:20: error: expected ';' before ':' token
17 | break:}
| ^
| ;
a.cc:17:20: error: expected primary-expression before ':' token
|
s405876539 | p03723 | C++ | int main(){
int a_ini,b_ini,c_ini; //A,B,Cの初期値
cin>>a_ini>>b_ini>>c_ini;
int a=a_ini;
int b=b_ini;
int c=c_ini;
int count=0;
int a_temp,b_temp,c_temp;
while(a%2==0 && b%2==0 && c%2==0){
a_temp=a;
b_temp=b;
c_temp=c;
a=b_temp/2+c_temp/2;
b=c_temp/2+a_temp/2;
c=a_temp/2+b_temp/2;
count++;
if(a==a_ini && b==b_ini && c==c_ini){
count=-1;
break;
}
}
cout<<count<<endl;
} | a.cc: In function 'int main()':
a.cc:3:5: error: 'cin' was not declared in this scope; did you mean 'c_ini'?
3 | cin>>a_ini>>b_ini>>c_ini;
| ^~~
| c_ini
a.cc:27:5: error: 'cout' was not declared in this scope; did you mean 'count'?
27 | cout<<count<<endl;
| ^~~~
| count
a.cc:27:18: error: 'endl' was not declared in this scope
27 | cout<<count<<endl;
| ^~~~
|
s502599616 | p03723 | Java | public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();
int c = sc.nextInt();
sc.close();
int ans = 0;
int a2, b2, c2;
while (a % 2 == 0 && b % 2 == 0 && c % 2 == 0) {
if (a == b && b == c) {
ans = -1;
break;
}
a2 = b / 2 + c / 2;
b2 = a / 2 + c / 2;
c2 = a / 2 + b / 2;
a = a2;
b = b2;
c = c2;
ans++;
}
System.out.println(ans);
}
} | Main.java:4: error: cannot find symbol
Scanner sc = new Scanner(System.in);
^
symbol: class Scanner
location: class Main
Main.java:4: error: cannot find symbol
Scanner sc = new Scanner(System.in);
^
symbol: class Scanner
location: class Main
2 errors
|
s944587447 | p03723 | C++ | #include <bits/stdc++.h>
using namespace std;
int main() {
int a,b,c;
int x,y,z,count;
count = 0;
cin >> a >> b >> c;
while(){
if(a%2==1 || b%2==1 || c%2==1){
cout << count << endl;
break;
}
else if(a==b && b==c && c==a){
cout << -1 << endl;
break;
}
x = b/2 + c/2;
y = a/2 + c/2;
z = a/2 + b/2;
count++;
if(x%2==1 || y%2==1 || z%2==1){
cout << count << endl;
break;
}
else{
a = y/2 + z/2;
b = x/2 + z/2;
c = x/2 + y/2;
count++;
}
}
} | a.cc: In function 'int main()':
a.cc:9:9: error: expected primary-expression before ')' token
9 | while(){
| ^
|
s633568084 | p03723 | C | #include <stdio.h>
int main(void){
int a, b, c;
scanf("%d %d %d", &a, &b, &c);
if(a==b && b==c && c==a %% a%2==0 %% b%2==0 && c%2==0){
printf("-1\n");
return 0;
}
int ans=0;
while(a%2==0 && b%2==0 && c%2==0){
int _a=a, _b=b, _c=c;
a=_b/2+_c/2;
b=_a/2+_c/2;
c=_a/2+_b/2;
ans++;
}
printf("%d\n", ans);
return 0;
}
| main.c: In function 'main':
main.c:5:30: error: expected expression before '%' token
5 | if(a==b && b==c && c==a %% a%2==0 %% b%2==0 && c%2==0){
| ^
|
s760610113 | p03723 | C++ | #include <bits/stdc++.h>
using namespace std;
#define inf 1072114514
#define llinf 4154118101919364364
#define mod 1000000007
#define pi 3.1415926535897932384
int round(int a,int b){if((a%b)*2 >= b){return (a/b)+1;}return a/b;}
int gcd(int a,int b){int c;while(b!=0){c=a%b;a=b;b=c;}return a;} //最大公約数
int lcm(int a,int b){int c=gcd(a,b);a/=c;return a*b;} //最小公倍数
int nCr(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;} //コンビネーション
int nHr(int a,int b){return nCr(a+b-1,b);} // 重複組み合わせ
int fact(int a){int i,r=1;for(i=1;i<=a;i++){r*=i;}return r;} //階乗
int pow(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;} // a~bまでの階乗
int dsum(int x){int r=0;while(x){r+=(x%10);x/=10;}return r;} //数字の各位の和
int dsumb(int x,int b){int r=0;while(x){r+=(x%b);x/=b;}return r;} // b進数の各位の和?
int sankaku(int x){return ((1+x)*x)/2;} //三角数 xまでの和
//以下long long ver
long long llmax(long long a,long long b){if(a>b){return a;}return b;}
long long llmin(long long a,long long b){if(a<b){return a;}return b;}
long long llzt(long long a,long long b){return llmax(a,b)-llmin(a,b);}
long long llround(long long a,long long b){if((a%b)*2 >= b){return (a/b)+1;}return a/b;}
long long llceil(long long a,long long b){if(a%b==0){return a/b;}return (a/b)+1;}
long long llgcd(long long a,long long b){long long c;while(b!=0){c=a%b;a=b;b=c;}return a;}
long long lllcm(long long a,long long b){long long c=llgcd(a,b);a/=c;return a*b;}
long long llnCr(long long a,long long b){long long i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
long long llnHr(long long a,long long b){return llnCr(a+b-1,b);}
long long llfact(long long a){long long i,r=1;for(i=1;i<=a;i++){r*=i;}return r;}
long long llpow(long long a,long long b){long long i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}
long long lldsum(long long x){long long r=0;while(x){r+=(x%10);x/=10;}return r;}
long long lldsumb(long long x,long long b){long long r=0;while(x){r+=(x%b);x/=b;}return r;}
long long llsankaku(long long x){return ((1+x)*x)/2;}
//double
double dbmax(double a,double b){if(a>b){return a;}return b;}
double dbmin(double a,double b){if(a<b){return a;}return b;}
double dbzt(double a,double b){return dbmax(a,b)-dbmin(a,b);}
typedef pair<int, int> ii;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
#define forr(i,a,b) ; for(int i=(a); i<(b); i++)
#define clean(arr,val) memset(arr,val,sizeof(arr))
#define forn(i,n) forr(i,0,n)
#define PB push_back
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<pll> vpll;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
/*CODE START HERE*/
int main() {
int64_t a,b,c;
cin >> a >> b >> c;
int count = 0;
forn (i,40){
if (a%2 == 1 || b%2 == 1 || c%2 == 1){
cout << count << endl;
return 0;
}
int na = (b+c)/2;
int nb = (a+c)/2;
int nc = (a+b)/2;
count ++ ;
a = na;
b = nb;
x = nc;
}
cout << -1 << endl;
} | a.cc: In function 'int main()':
a.cc:75:5: error: 'x' was not declared in this scope
75 | x = nc;
| ^
|
s660033500 | p03723 | C++ | #include <bits/stdc++.h>
using namespace std;
int main() {
int l = ;
vector <int> a(l);
vector <int> b(l);
vector <int> c(l);
cin >> a.at(0) >> b.at(0) >> c.at(0);
int ans =0 ;
for ( int i=0 ; ; i++){
if ( a.at(i)%2==1 || b.at(i)%2==1 || c.at(i)%2==1){
cout << ans << endl ;
return 0 ;
}
if ( a.at(i)%4==0 && b.at(i)%4==0 && c.at(i)%4==0){
cout << -1 << endl;
return 0 ;
}
if ( a.at(i)%4==2 && b.at(i)%4==2 && c.at(i)%4==2){
cout << -1 << endl;
return 0 ;
}
a.at(i+1) = (b.at(i)+c.at(i))/2 ;
b.at(i+1) = (c.at(i)+c.at(i))/2 ;
c.at(i+1) = (b.at(i)+a.at(i))/2 ;
ans ++ ;
}
} | a.cc: In function 'int main()':
a.cc:5:11: error: expected primary-expression before ';' token
5 | int l = ;
| ^
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.