제출 #1334667

#제출 시각아이디문제언어결과실행 시간메모리
1334667retardeRobot (JOI21_ho_t4)C++20
0 / 100
195 ms28624 KiB
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define int long long
#define all(x) (x).begin(), (x).end()

typedef long double ld;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<vector<bool>> vvb;
typedef vector<vector<ll>> vvll;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef map<int, int> mii;
typedef unordered_map<int, int> umii;

const int mod = 1e9 + 7;
const int inf = INTMAX_MAX;
const bool tc = false;

struct edge {
    int to, col, p;
};

int n, m;
const int mxn = 1e5 + 5;
vector<edge> adj[mxn];
vector<pii> dadj[mxn];

inline void solve() {
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        int u, v;
        cin >> u >> v;
        u--; v--;
        int c, p; cin >> c >> p;
        adj[u].pb({v, c, p});
        adj[v].pb({u, c, p});
    }

    // for (int i = 0; i < n; i++) {
    //     for (auto &x : adj[i]) {
    //         cout << i + 1 << " to " << x.to + 1 << '\n';
    //     }
    // }
    // cout << '\n';

    for (int i = 0; i < n; i++) {
        // i -> current node
        mii mpp; for (auto &e : adj[i]) {
            mpp[e.col] += e.p;
        }
        for (auto &e : adj[i]) {
            bool ok = (mpp[e.col] == e.p);
            dadj[i].pb({e.to, (ok ? 0 : min(e.p, mpp[e.col]-e.p))});
        }
    }

    // for (int i = 0; i < n; i++) {
    //     for (auto &x : dadj[i]) {
    //         cout << i + 1 << " to " << x.fi + 1 << " costs " << x.se << '\n';
    //     }
    // }

    vi d(n, 1e18); set<pii> djk; djk.insert({0, 0});
    d[0] = 0;
    
    while (djk.size()) {
        auto cur = *djk.begin();
        djk.erase(djk.begin());
        int node = cur.se; int dist = cur.fi; // this is fine
        for (auto &neighbour : dadj[node]) {
            if (d[node] + neighbour.se >= d[neighbour.fi]) continue;
            djk.erase({d[neighbour.fi], neighbour.fi});
            d[neighbour.fi] = d[node] + neighbour.se;
            djk.insert({d[neighbour.fi], neighbour.fi});
        } 
    }

    // for (int i = 0; i < n; i++) cout << d[i] << " ";
    // cout << '\n';

    cout << (d[n - 1] == 1e18 ? -1 : d[n - 1]) << '\n';
}

void setIO(string s) {
    freopen((s + ".in").c_str(), "r", stdin);
    freopen((s + ".out").c_str(), "w", stdout);
}

signed main() {
    ios::sync_with_stdio(false);
    cout.tie(0);
    cin.tie(0);
    //setIO();

    int t = 1;
    if (tc) {
        cin >> t;
    }

    while (t--) {
        solve();
    }
}

컴파일 시 표준 에러 (stderr) 메시지

Main.cpp: In function 'void setIO(std::string)':
Main.cpp:99:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   99 |     freopen((s + ".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:100:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  100 |     freopen((s + ".out").c_str(), "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...