Submission #1166257

#TimeUsernameProblemLanguageResultExecution timeMemory
1166257hainam2k9Robot (JOI21_ho_t4)C++20
100 / 100
131 ms15852 KiB
#include <bits/stdc++.h>
#define tt cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(0)
#define fo freopen((NAME+".INP").c_str(), "r", stdin), freopen((NAME+".OUT").c_str(), "w", stdout)
#define ll long long
#define ull unsigned long long
#define i128 __int128
#define db long double
#define sz(a) ((int)(a).size())
#define pb emplace_back
#define pf emplace_front
#define pob pop_back
#define pof pop_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define ins emplace
#define mp make_pair
using namespace std;
const int MOD = 1e9+7, MAXN = 1e5+5;
const string NAME = "";
struct Edge{
    int to,color,cost;
    Edge(int a, int b, int c){
        to=a, color=b, cost=c;
    }
};
int n,m,cnt[MAXN<<1];
ll dp[MAXN],sum[MAXN<<1],MIN[MAXN<<1];
vector<Edge> adj[MAXN];
priority_queue<pair<ll,int>, vector<pair<ll,int>>, greater<pair<ll,int>>> pq;
int main()
{
    tt;
    if(fopen((NAME + ".INP").c_str(), "r")) fo;
    cin >> n >> m;
    for(int i = 1; i<=m; ++i){
        int a,b,color,cost;
        cin >> a >> b >> color >> cost;
        adj[a].pb(Edge(b,color,cost)), adj[b].pb(Edge(a,color,cost));
    }
    memset(dp,0x3f,sizeof(dp));
    memset(MIN,0x3f,sizeof(MIN));
    dp[1]=0;
    pq.ins(0,1);
    while(!pq.empty()){
        pair<ll,int> top = pq.top();
        pq.pop();
        if(top.fi>dp[top.se]) continue;
        for(Edge& e : adj[top.se]) ++cnt[e.color], sum[e.color]+=e.cost, MIN[e.color]=min(MIN[e.color],dp[e.to]);
        for(Edge& e : adj[top.se]){
            ll cost = cnt[e.color]<2 ? top.fi : min(top.fi+e.cost,sum[e.color]-e.cost+min(top.fi,MIN[e.color]));
            if(dp[e.to]>cost) dp[e.to]=cost, pq.ins(dp[e.to],e.to);
        }
        for(Edge& e: adj[top.se]) sum[e.color]=cnt[e.color]=0, MIN[e.color]=1e18;
    }
    if(dp[n]>1e18) dp[n]=-1;
    cout << dp[n];
}

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:3:19: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    3 | #define fo freopen((NAME+".INP").c_str(), "r", stdin), freopen((NAME+".OUT").c_str(), "w", stdout)
      |            ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:35:45: note: in expansion of macro 'fo'
   35 |     if(fopen((NAME + ".INP").c_str(), "r")) fo;
      |                                             ^~
Main.cpp:3:63: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    3 | #define fo freopen((NAME+".INP").c_str(), "r", stdin), freopen((NAME+".OUT").c_str(), "w", stdout)
      |                                                        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:35:45: note: in expansion of macro 'fo'
   35 |     if(fopen((NAME + ".INP").c_str(), "r")) fo;
      |                                             ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...