Submission #1035896

#TimeUsernameProblemLanguageResultExecution timeMemory
1035896whyalwaysmezzzRobot (JOI21_ho_t4)C++14
100 / 100
300 ms122260 KiB
//********************** // //********************** #include <bits/stdc++.h> #define int long long #define fi first #define se second #define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; i++) #define FORD(i, b, a) for (int i = (b), _a = (a); i >= _a; i--) #define add(a,b) a=(a+b)%MOD #define BIT(mask,i) ((mask >> i) & 1ll ) #define OFF(mask,i) (mask & (~(1ll << i))) #define ON(mask,i) (mask | (1ll << i)) #define endl '\n' #define DAO(mask,i) (mask ^ (1ll << i)) #define add(a,b) a=(a+b)%MOD #define m_p make_pair #define m_t make_tuple #define built(mask) __builtin_popcountll(mask) #define all(x) x.begin(),x.end() #define XD cout << '\n' #define ii pair <int,int> #define iii pair<int,pair<int, int> > #define TASK "robot1" using namespace std; const long long oo = 1e18; const int N = 6e5+5; const int MOD = 1e9+7; vector< ii > a[N]; map<int , int> mp[N]; vector< iii> g[N]; int dist[N]; int sum[N]; bool vis[N]; void dij(int x) { FOR(i,1,N) dist[i] = oo; priority_queue< pair < int,int > , vector < pair < int ,int > > , greater < pair < int , int > > > q; dist[x] = 0; q.push(m_p(0, x)); while (!q.empty()) { auto p1 = q.top(); int W = p1.fi; int x = p1.se; q.pop(); if (vis[x]) continue; vis[x] = 1; for (auto p2 : a[x]) { int y = p2.fi; int w = p2.se; if (vis[y] || dist[y] < W + w) continue; dist[y] = W + w; q.push({W + w, y}); } } } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); // freopen(TASK".inp","r",stdin); // freopen(TASK".out","w",stdout); int n,m,x,y,c,p; cin >> n >> m; FOR(i,1,m) { cin >> x >> y >> c >> p; g[x].push_back({c, {y, p}}); g[y].push_back({c, {x, p}}); a[x].push_back({y, p}); a[y].push_back({x, p}); } int cur = n; FOR(i,1,n) { sort(g[i].begin(), g[i].end()); for (auto x : g[i]) sum[x.fi] += x.se.se; for (auto x : g[i]) { if (!vis[x.fi]) { ++cur; a[i].push_back(m_p(cur,0)); } vis[x.fi] = 1; a[cur].push_back(m_p(x.se.fi, sum[x.fi] - x.se.se)); a[x.se.fi].push_back(m_p(cur, 0)); } for (auto x : g[i]) { sum[x.fi] = 0; vis[x.fi] = 0; } } dij(1); if (dist[n] == oo) cout << "-1"; else cout << dist[n]; return 0; }

Compilation message (stderr)

Main.cpp: In function 'void dij(long long int)':
Main.cpp:37:21: warning: iteration 600004 invokes undefined behavior [-Waggressive-loop-optimizations]
   37 |  FOR(i,1,N) dist[i] = oo;
      |             ~~~~~~~~^~~~
Main.cpp:8:52: note: within this loop
    8 | #define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; i++)
      |                                                    ^
Main.cpp:37:2: note: in expansion of macro 'FOR'
   37 |  FOR(i,1,N) dist[i] = oo;
      |  ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...